Skip to content

Commit 2eea1f8

Browse files
committed
Added MongoDB default access scanner
1 parent be0c423 commit 2eea1f8

File tree

1 file changed

+65
-5
lines changed

1 file changed

+65
-5
lines changed

nosqlmap.py

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
#Set a list so we can track whether options are set or not to avoid resetting them in subsequent cals to the options menu.
3030
global optionSet
3131
optionSet = [False,False,False,False,False,False]
32+
global victim
33+
global webPort
34+
global uri
35+
global httpMethod
36+
global myIP
37+
global myPort
3238

3339

3440
def mainMenu():
@@ -39,10 +45,11 @@ def mainMenu():
3945
print "NoSQLMap-v0.15b"
4046
4147
print "\n"
42-
print "1-Set options (do this first)"
48+
print "1-Set options"
4349
print "2-NoSQL DB Access Attacks"
4450
print "3-NoSQL Web App attacks"
45-
print "4-Exit"
51+
print "4-Scan for Anonymous MongoDB Access"
52+
print "5-Exit"
4653

4754
select = raw_input("Select an option: ")
4855

@@ -67,8 +74,11 @@ def mainMenu():
6774
else:
6875
raw_input("Options not set! Check Host and URI path. Press enter to continue...")
6976
mainMenu()
70-
77+
7178
elif select == "4":
79+
massMongo()
80+
81+
elif select == "5":
7282
sys.exit()
7383

7484
else:
@@ -83,7 +93,6 @@ def options():
8393
global httpMethod
8494
global myIP
8595
global myPort
86-
8796
#Set default value if needed
8897
if optionSet[0] == False:
8998
victim = "Not Set"
@@ -829,6 +838,57 @@ def stealDBs(myDB):
829838

830839
except:
831840
raw_input ("Something went wrong. Are you sure your MongoDB is running and options are set? Press enter to return...")
832-
mainMenu()
841+
mainMenu()
842+
843+
def massMongo():
844+
global victim
845+
success = []
846+
print "\n"
847+
print "Massmongo-Scan for default access to MongoDB servers"
848+
print "===================================================="
849+
loadPath = raw_input("Enter file name with IP list to scan: ")
850+
851+
with open (loadPath) as f:
852+
ipList = f.readlines()
853+
854+
855+
for target in ipList:
856+
try:
857+
conn = pymongo.MongoClient(target,27017)
858+
print " Connected to " + target[:-1]
859+
dbList = conn.database_names()
860+
861+
print "Successful admin access to " + target[:-1]
862+
target = target[:-1]
863+
success.append(target)
864+
conn.disconnect()
865+
866+
except:
867+
print "Failed to connect to " + target + " or credentials required."
868+
869+
print "\n\n"
870+
print "Discovered MongoDB Servers:"
871+
872+
menuItem = 1
873+
print "List of servers:"
874+
for server in success:
875+
print str(menuItem) + "-" + server
876+
menuItem += 1
877+
878+
select = True
879+
while select:
880+
select = raw_input("Select a NoSQLMap target or press x to exit: ")
881+
882+
if select == "x" or select == "X":
883+
mainMenu()
884+
885+
elif select.isdigit() == True:
886+
victim = success[int(select) - 1]
887+
optionSet[0] = True
888+
raw_input("New target set! Press enter to return to the main menu.")
889+
mainMenu()
890+
891+
else:
892+
raw_input("Invalid selection.")
833893

834894
mainMenu()

0 commit comments

Comments
 (0)