Skip to content

Commit cde8458

Browse files
committed
Added subnet scanning to access scanner
1 parent 3f7f608 commit cde8458

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

nosqlmap.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import subprocess
2626
import json
2727
import gridfs
28+
import ipcalc
2829
from hashlib import md5
2930

3031
#Set a list so we can track whether options are set or not to avoid resetting them in subsequent cals to the options menu.
@@ -879,37 +880,62 @@ def stealDBs(myDB):
879880

880881
def massMongo():
881882
global victim
883+
optCheck = True
882884
loadCheck = False
883885
success = []
886+
ipList = []
884887
print "\n"
885888
print "MongoDB Default Access Scanner"
886889
print "=============================="
890+
print "1-Scan a subnet for default MongoDB access"
891+
print "2-Loads IPs to scan from a file"
887892

888-
while loadCheck == False:
889-
loadPath = raw_input("Enter file name with IP list to scan: ")
893+
while optCheck:
894+
loadOpt = raw_input("Select a scan method: ")
895+
896+
897+
if loadOpt == "1":
898+
subnet = raw_input("Enter subnet to scan: ")
899+
900+
try:
901+
for ip in ipcalc.Network(subnet):
902+
ipList.append(str(ip))
903+
optCheck = False
904+
except:
905+
raw_input("Not a valid subnet. Press enter to return to main menu.")
906+
mainMenu()
907+
908+
909+
print "Debug:"
910+
print ipList
911+
912+
if loadOpt == "2":
913+
while loadCheck == False:
914+
loadPath = raw_input("Enter file name with IP list to scan: ")
890915

891-
try:
892-
with open (loadPath) as f:
893-
ipList = f.readlines()
894-
loadCheck = True
895-
except:
896-
print "Couldn't open file."
916+
try:
917+
with open (loadPath) as f:
918+
ipList = f.readlines()
919+
loadCheck = True
920+
optCheck = False
921+
except:
922+
print "Couldn't open file."
897923

898924

899925
print "\n"
900926
for target in ipList:
901927
try:
902928
conn = pymongo.MongoClient(target,27017)
903-
print "Connected to " + target[:-1] + "!"
929+
print "Connected to " + target
904930
dbList = conn.database_names()
905931

906-
print "Successful admin access on " + target[:-1] + ".\n"
932+
print "Successful default access on " + target
907933
target = target[:-1]
908934
success.append(target)
909935
conn.disconnect()
910936

911937
except:
912-
print "Failed to connect to " + target[:-1] + " or credentials required."
938+
print "Failed to connect to or need credentials for " + target
913939

914940
print "\n\n"
915941
print "Discovered MongoDB Servers:"

0 commit comments

Comments
 (0)