19
19
ssl ._create_default_https_context = ssl ._create_unverified_context
20
20
21
21
22
- def getApps (webPort ,victim ,uri ,https ,verb ,requestHeaders ):
22
+ def args ():
23
+ return [
24
+ ["--injectSize" , "Size of payload" ],
25
+ ["--injectFormat" , "1-Alphanumeric, 2-Letters only, 3-Numbers only, 4-Email address" ],
26
+ ["--params" , "Enter parameters to inject in a comma separated list" ],
27
+ ["--doTimeAttack" , "Start timing based tests (y/n)" ]]
28
+
29
+ def getApps (webPort ,victim ,uri ,https ,verb ,requestHeaders , args = None ):
23
30
print "Web App Attacks (GET)"
24
31
print "==============="
25
32
paramName = []
@@ -81,25 +88,32 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
81
88
82
89
if appUp == True :
83
90
84
- sizeSelect = True
91
+ if args == None :
92
+ sizeSelect = not injectSize .isdigit ()
85
93
86
- while sizeSelect :
87
- injectSize = raw_input ("Baseline test-Enter random string size: " )
88
- if injectSize .isdigit ():
89
- sizeSelect = False
90
- else :
91
- print "Invalid! The size should be an integer."
94
+ while sizeSelect :
95
+ injectSize = raw_input ("Baseline test-Enter random string size: " )
96
+ sizeSelect = not injectSize .isdigit ()
97
+ if sizeSelect :
98
+ print "Invalid! The size should be an integer."
99
+
100
+ format = randInjString (int (injectSize ))
101
+ else :
102
+ injectSize = int (args .injectSize )
103
+ format = args .injectFormat
104
+
105
+ injectString = build_random_string (format , injectSize )
92
106
93
- injectString = randInjString (int (injectSize ))
94
107
print "Using " + injectString + " for injection testing.\n "
95
108
96
109
# Build a random string and insert; if the app handles input correctly, a random string and injected code should be treated the same.
97
110
if "?" not in appURL :
98
111
print "No URI parameters provided for GET request...Check your options.\n "
99
- raw_input ("Press enter to continue..." )
112
+ if args == None :
113
+ raw_input ("Press enter to continue..." )
100
114
return ()
101
115
102
- randomUri = buildUri (appURL ,injectString )
116
+ randomUri = buildUri (appURL ,injectString , args )
103
117
print "URI : " + randomUri
104
118
req = urllib2 .Request (randomUri , None , requestHeaders )
105
119
@@ -260,8 +274,10 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
260
274
checkResult (randLength ,injLen ,testNum ,verb ,None )
261
275
testNum += 1
262
276
263
-
264
- doTimeAttack = raw_input ("Start timing based tests (y/n)? " )
277
+ if args == None :
278
+ doTimeAttack = raw_input ("Start timing based tests (y/n)? " )
279
+ else :
280
+ doTimeAttack = args .doTimeAttack
265
281
266
282
if doTimeAttack .lower () == "y" :
267
283
print "Starting Javascript string escape time based injection..."
@@ -323,7 +339,10 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
323
339
else :
324
340
print "Integer attack-Unsuccessful"
325
341
326
- fileOut = raw_input ("Save results to file (y/n)? " )
342
+ if args == None :
343
+ fileOut = raw_input ("Save results to file (y/n)? " )
344
+ else :
345
+ fileOut = "n"
327
346
328
347
if fileOut .lower () == "y" :
329
348
savePath = raw_input ("Enter output file name: " )
@@ -349,7 +368,8 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
349
368
fo .write ("\n " )
350
369
fo .close ()
351
370
352
- raw_input ("Press enter to continue..." )
371
+ if args == None :
372
+ raw_input ("Press enter to continue..." )
353
373
return ()
354
374
355
375
@@ -430,20 +450,25 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders):
430
450
menuItem += 1
431
451
432
452
try :
433
- injIndex = raw_input ("Which parameter should we inject? " )
453
+ injIndex = 1
454
+ if args == None :
455
+ injIndex = raw_input ("Which parameter should we inject? " )
456
+
434
457
injOpt = str (postData .keys ()[int (injIndex )- 1 ])
435
458
print "Injecting the " + injOpt + " parameter..."
436
459
except :
437
- raw_input ("Something went wrong. Press enter to return to the main menu..." )
460
+ if args == None :
461
+ raw_input ("Something went wrong. Press enter to return to the main menu..." )
438
462
return
439
463
440
- sizeSelect = True
464
+
465
+ sizeSelect = (args == None )
466
+ injectSize = 1000
441
467
442
468
while sizeSelect :
443
469
injectSize = raw_input ("Baseline test-Enter random string size: " )
444
- if injectSize .isdigit ():
445
- sizeSelect = False
446
- else :
470
+ sizeSelect = not injectSize .isdigit ()
471
+ if sizeSelect :
447
472
print "Invalid! The size should be an integer."
448
473
449
474
injectString = randInjString (int (injectSize ))
@@ -454,7 +479,6 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders):
454
479
postData .update ({injOpt :injectString })
455
480
if verb == "ON" :
456
481
print "Checking random injected parameter HTTP response size sending " + str (postData ) + "...\n "
457
-
458
482
else :
459
483
print "Sending random parameter value..."
460
484
@@ -641,7 +665,9 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders):
641
665
testNum += 1
642
666
print "\n "
643
667
644
- doTimeAttack = raw_input ("Start timing based tests (y/n)? " )
668
+ doTimeAttack = "N"
669
+ if args == None :
670
+ doTimeAttack = raw_input ("Start timing based tests (y/n)? " )
645
671
646
672
if doTimeAttack == "y" or doTimeAttack == "Y" :
647
673
print "Starting Javascript string escape time based injection..."
@@ -849,28 +875,29 @@ def randInjString(size):
849
875
850
876
while format :
851
877
format = raw_input ("Select an option: " )
878
+ if format not in ["1" , "2" , "3" , "4" ]:
879
+ format = True
880
+ print "Invalid selection."
881
+ return format
852
882
853
- if format == "1" :
854
- chars = string .ascii_letters + string .digits
855
- return '' .join (random .choice (chars ) for x in range (size ))
856
-
857
- elif format == "2" :
858
- chars = string .ascii_letters
859
- return '' .join (random .choice (chars ) for x in range (size ))
883
+ def build_random_string (format , size ):
884
+ if format == "1" :
885
+ chars = string .ascii_letters + string .digits
886
+ return '' .join (random .choice (chars ) for x in range (size ))
860
887
861
- elif format == "3 " :
862
- chars = string .digits
863
- return '' .join (random .choice (chars ) for x in range (size ))
888
+ elif format == "2 " :
889
+ chars = string .ascii_letters
890
+ return '' .join (random .choice (chars ) for x in range (size ))
864
891
865
- elif format == "4" :
866
- chars = string .ascii_letters + string .digits
867
- return '' .join (random .choice (chars ) for x in range (size )) + '@' + '' .join (random .choice (chars ) for x in range (size )) + '.com'
868
- else :
869
- format = True
870
- print "Invalid selection."
892
+ elif format == "3" :
893
+ chars = string .digits
894
+ return '' .join (random .choice (chars ) for x in range (size ))
871
895
896
+ else : # format == "4":
897
+ chars = string .ascii_letters + string .digits
898
+ return '' .join (random .choice (chars ) for x in range (size )) + '@' + '' .join (random .choice (chars ) for x in range (size )) + '.com'
872
899
873
- def buildUri (origUri , randValue ):
900
+ def buildUri (origUri , randValue , args = None ):
874
901
paramName = []
875
902
paramValue = []
876
903
global uriArray
@@ -898,7 +925,10 @@ def buildUri(origUri, randValue):
898
925
menuItem += 1
899
926
900
927
try :
901
- injIndex = raw_input ("Enter parameters to inject in a comma separated list: " )
928
+ if args == None :
929
+ injIndex = raw_input ("Enter parameters to inject in a comma separated list: " )
930
+ else :
931
+ injIndex = args .params
902
932
903
933
for params in injIndex .split ("," ):
904
934
injOpt .append (paramName [int (params )- 1 ])
0 commit comments