1919 ssl ._create_default_https_context = ssl ._create_unverified_context
2020
2121
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 ):
2330 print "Web App Attacks (GET)"
2431 print "==============="
2532 paramName = []
@@ -81,25 +88,32 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
8188
8289 if appUp == True :
8390
84- sizeSelect = True
91+ if args == None :
92+ sizeSelect = not injectSize .isdigit ()
8593
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 )
92106
93- injectString = randInjString (int (injectSize ))
94107 print "Using " + injectString + " for injection testing.\n "
95108
96109 # Build a random string and insert; if the app handles input correctly, a random string and injected code should be treated the same.
97110 if "?" not in appURL :
98111 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..." )
100114 return ()
101115
102- randomUri = buildUri (appURL ,injectString )
116+ randomUri = buildUri (appURL ,injectString , args )
103117 print "URI : " + randomUri
104118 req = urllib2 .Request (randomUri , None , requestHeaders )
105119
@@ -260,8 +274,10 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
260274 checkResult (randLength ,injLen ,testNum ,verb ,None )
261275 testNum += 1
262276
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
265281
266282 if doTimeAttack .lower () == "y" :
267283 print "Starting Javascript string escape time based injection..."
@@ -323,7 +339,10 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
323339 else :
324340 print "Integer attack-Unsuccessful"
325341
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"
327346
328347 if fileOut .lower () == "y" :
329348 savePath = raw_input ("Enter output file name: " )
@@ -349,7 +368,8 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
349368 fo .write ("\n " )
350369 fo .close ()
351370
352- raw_input ("Press enter to continue..." )
371+ if args == None :
372+ raw_input ("Press enter to continue..." )
353373 return ()
354374
355375
@@ -430,20 +450,25 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders):
430450 menuItem += 1
431451
432452 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+
434457 injOpt = str (postData .keys ()[int (injIndex )- 1 ])
435458 print "Injecting the " + injOpt + " parameter..."
436459 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..." )
438462 return
439463
440- sizeSelect = True
464+
465+ sizeSelect = (args == None )
466+ injectSize = 1000
441467
442468 while sizeSelect :
443469 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 :
447472 print "Invalid! The size should be an integer."
448473
449474 injectString = randInjString (int (injectSize ))
@@ -454,7 +479,6 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders):
454479 postData .update ({injOpt :injectString })
455480 if verb == "ON" :
456481 print "Checking random injected parameter HTTP response size sending " + str (postData ) + "...\n "
457-
458482 else :
459483 print "Sending random parameter value..."
460484
@@ -641,7 +665,9 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders):
641665 testNum += 1
642666 print "\n "
643667
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)? " )
645671
646672 if doTimeAttack == "y" or doTimeAttack == "Y" :
647673 print "Starting Javascript string escape time based injection..."
@@ -849,28 +875,29 @@ def randInjString(size):
849875
850876 while format :
851877 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
852882
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 ))
860887
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 ))
864891
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 ))
871895
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'
872899
873- def buildUri (origUri , randValue ):
900+ def buildUri (origUri , randValue , args = None ):
874901 paramName = []
875902 paramValue = []
876903 global uriArray
@@ -898,7 +925,10 @@ def buildUri(origUri, randValue):
898925 menuItem += 1
899926
900927 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
902932
903933 for params in injIndex .split ("," ):
904934 injOpt .append (paramName [int (params )- 1 ])
0 commit comments