3
3
import os
4
4
import sys
5
5
import json
6
- import base64
7
6
import binascii
8
7
import mimetypes
9
8
import xml .etree .ElementTree as et
9
+ from base64 import b64decode
10
10
11
11
# Import burp export and return a list of decoded data
12
12
def get_burp_list (filename ):
13
13
if not os .path .exists (filename ):
14
14
return []
15
15
16
- with open (filename ) as f :
16
+ with open (filename , 'r' ) as f :
17
17
filecontents = f .read ()
18
18
19
19
tree = et .fromstring (filecontents )
@@ -23,19 +23,15 @@ def get_burp_list(filename):
23
23
for dict_el in tree .iterfind ('item' ):
24
24
tmpDict = {}
25
25
for item in dict_el :
26
- if item .tag == "request" :
27
- tmpDict ['request' ] = base64 .b64decode (item .text )
28
- if item .tag == "response" :
29
- tmpDict ['response' ] = base64 .b64decode (item .text )
30
- if item .tag == "url" :
31
- tmpDict ['url' ] = item .text
26
+ if item .tag in ["request" , "response" , "url" ]:
27
+ tmpDict [item .tag ] = b64decode (item .text )
32
28
requestList .append (tmpDict )
33
29
34
30
return requestList
35
31
36
32
# Return hex encoded string output of binary input
37
33
def payload_encode_file (input_file ):
38
- with open (input_file ) as f :
34
+ with open (input_file , 'r' ) as f :
39
35
filecontents = f .read ()
40
36
hue = binascii .hexlify (filecontents )
41
37
filecontents = '\\ x' + '\\ x' .join (hue [i :i + 2 ] for i in xrange (0 , len (hue ), 2 )) # Stackoverflow, because pythonistic
@@ -404,78 +400,87 @@ def xss_gen(requestList, settingsDict):
404
400
-n Turn off payload optimization
405
401
406
402
"""
407
- if len (sys .argv ) < 2 :
408
- print logo
409
- print helpmenu
410
- else :
411
- # settingsDict will contain code generation settings, such as waiting for each request to complete, etc.
412
- settingsDict = {}
413
- settingsDict ['opt' ] = True
414
-
415
- showlogo = True
416
-
417
- for option in sys .argv [1 :]:
418
- if option == "-h" :
419
- print logo
420
- print helpmenu
421
- sys .exit ()
422
- if option == "-s" :
423
- showlogo = False
424
- if "-m=" in option :
425
- metafile = option .replace ("-m=" , "" )
426
- if os .path .isfile (metafile ):
427
- tmpList = open (metafile ).readlines ()
428
- for key ,value in enumerate (tmpList ):
429
- tmpList [key ] = value .replace ("\n " , "" )
430
- if len (tmpList ):
431
- settingsDict ['metaList' ] = tmpList
432
- else :
433
- print "Error, meta list not found!"
434
- if "-p=" in option :
435
- parsefile = option .replace ("-p=" , "" )
436
- if os .path .isfile (parsefile ):
437
- tmpList = open (parsefile ).readlines ()
438
- for key ,value in enumerate (tmpList ):
439
- tmpList [key ] = value .replace ("\n " , "" )
440
- if len (tmpList ):
441
- settingsDict ['parseList' ] = tmpList
442
- else :
443
- print "Error, parse list not found!"
444
- if "-n" in option :
445
- settingsDict ['opt' ] = False
446
- if "-f=" in option :
447
- fileuploadlist = option .replace ("-f=" , "" )
448
- if os .path .isfile (fileuploadlist ):
449
- tmpDict = {}
450
- fileuploadlinesList = open (fileuploadlist ).readlines ()
451
- for key , value in enumerate (fileuploadlinesList ):
452
- rowparts = value .replace ("\n " , "" ).split ("," , 1 )
453
- if len (rowparts ) == 2 :
454
- if os .path .isfile (rowparts [1 ]):
455
- tmpDict [rowparts [0 ]] = rowparts [1 ]
456
- else :
457
- print "File '" + rowparts [1 ] + "' not found!"
458
- sys .exit ()
459
- else :
460
- print "Error while parsing file " + fileuploadlist + " on line #" + str (key )
461
- print " ->'" + value .replace ("\n " , "" ) + "'"
462
- sys .exit ()
463
- if tmpDict :
464
- settingsDict ['fileDict' ] = tmpDict
465
- else :
466
- print "Input filelist not found!"
467
- sys .exit ()
468
-
469
- if os .path .exists (sys .argv [- 1 ]):
470
- inputfile = sys .argv [- 1 ]
403
+ if __name__ == '__main__' :
404
+ if len (sys .argv ) < 2 :
405
+ print logo
406
+ print helpmenu
471
407
else :
472
- inputfile = ""
408
+ # settingsDict will contain code generation settings, such as waiting for each request to complete, etc.
409
+ settingsDict = {}
410
+ settingsDict ['opt' ] = True
473
411
474
- if showlogo :
475
- print logo
412
+ showlogo = False if "-s" in sys .argv [1 :] else True # quick check for this first incase they hate logos
476
413
477
- if inputfile :
478
- requestList = get_burp_list (inputfile )
479
- print xss_gen (requestList , settingsDict )
480
- else :
481
- print "Error while processing Burp export, please ensure the file exists!"
414
+ for option in sys .argv [1 :]:
415
+ if option == "-s" :
416
+ pass
417
+ if option == "-h" :
418
+ if showlogo :
419
+ print logo
420
+ print helpmenu
421
+ sys .exit (0 )
422
+ if "-m=" in option :
423
+ metafile = option .replace ("-m=" , "" )
424
+ if os .path .isfile (metafile ):
425
+ tmpList = open (metafile ).readlines ()
426
+ for key ,value in enumerate (tmpList ):
427
+ tmpList [key ] = value .replace ("\n " , "" )
428
+ if len (tmpList ):
429
+ settingsDict ['metaList' ] = tmpList
430
+ else :
431
+ print "Error, meta list not found!"
432
+ if "-p=" in option :
433
+ parsefile = option .replace ("-p=" , "" )
434
+ if os .path .isfile (parsefile ):
435
+ tmpList = open (parsefile ).readlines ()
436
+ for key ,value in enumerate (tmpList ):
437
+ tmpList [key ] = value .replace ("\n " , "" )
438
+ if len (tmpList ):
439
+ settingsDict ['parseList' ] = tmpList
440
+ else :
441
+ print "Error, parse list not found!"
442
+ if "-n" in option :
443
+ settingsDict ['opt' ] = False
444
+ if "-f=" in option :
445
+ fileuploadlist = option .replace ("-f=" , "" )
446
+ if os .path .isfile (fileuploadlist ):
447
+ tmpDict = {}
448
+ fileuploadlinesList = open (fileuploadlist ).readlines ()
449
+ for key , value in enumerate (fileuploadlinesList ):
450
+ rowparts = value .replace ("\n " , "" ).split ("," , 1 )
451
+ if len (rowparts ) == 2 :
452
+ if os .path .isfile (rowparts [1 ]):
453
+ tmpDict [rowparts [0 ]] = rowparts [1 ]
454
+ else :
455
+ print "File '" + rowparts [1 ] + "' not found!"
456
+ sys .exit (1 )
457
+ else :
458
+ print "Error while parsing file " + fileuploadlist + " on line #" + str (key )
459
+ print " ->'" + value .replace ("\n " , "" ) + "'"
460
+ sys .exit (1 )
461
+ if tmpDict :
462
+ settingsDict ['fileDict' ] = tmpDict
463
+ else :
464
+ print "Input filelist not found!"
465
+ sys .exit (1 )
466
+ else :
467
+ print "Option " + option + " not recognized."
468
+ if showlogo :
469
+ print logo
470
+ print helpmenu
471
+ sys .exit (1 )
472
+
473
+ if os .path .exists (sys .argv [- 1 ]):
474
+ inputfile = sys .argv [- 1 ]
475
+ else :
476
+ inputfile = ""
477
+
478
+ if showlogo :
479
+ print logo
480
+
481
+ if inputfile :
482
+ requestList = get_burp_list (inputfile )
483
+ print xss_gen (requestList , settingsDict )
484
+ else :
485
+ print "Error while processing Burp export, please ensure the file exists!"
486
+ sys .exit (1 )
0 commit comments