1
1
#!/usr/bin/env python
2
2
3
- import sys
4
3
from bs4 import BeautifulSoup
5
- import base64
6
- import json
4
+
7
5
import os
6
+ import sys
7
+ import json
8
+ import base64
9
+ import binascii
8
10
import mimetypes
9
11
10
12
# Import burp export and return a list of decoded data
@@ -13,33 +15,32 @@ def get_burp_list(filename):
13
15
return []
14
16
15
17
with open (filename ) as f :
16
- filecontents = f .read ()
18
+ filecontents = f .read ()
17
19
18
20
archive = BeautifulSoup (filecontents , "xml" )
19
21
20
22
requestList = []
21
- item = archive .find_all ('item' )
22
23
23
24
for item in archive .find_all ('item' ):
24
25
tmpDict = {}
25
26
tmpDict ['request' ] = base64 .b64decode (item .request .string )
26
27
tmpDict ['response' ] = base64 .b64decode (item .response .string )
27
28
tmpDict ['url' ] = item .url .string
28
29
requestList .append (tmpDict )
29
- del tmpDict
30
30
31
31
return requestList
32
32
33
33
# Return hex encoded string output of binary input
34
34
def payload_encode_file (input_file ):
35
- filecontents = open (input_file ).read ()
36
- hue = filecontents .encode ("hex" )
35
+ with open (input_file ) as f :
36
+ filecontents = f .read ()
37
+ hue = binascii .hexlify (filecontents )
37
38
filecontents = '\\ x' + '\\ x' .join (hue [i :i + 2 ] for i in xrange (0 , len (hue ), 2 )) # Stackoverflow, because pythonistic
38
39
return filecontents
39
40
40
41
# Return hex encoded string output of binary input
41
42
def payload_encode_input (filecontents ):
42
- hue = filecontents . encode ( "hex" )
43
+ hue = binascii . hexlify ( filecontents )
43
44
filecontents = '\\ x' + '\\ x' .join (hue [i :i + 2 ] for i in xrange (0 , len (hue ), 2 )) # Stackoverflow, because pythonistic
44
45
return filecontents
45
46
@@ -71,18 +72,16 @@ def parse_request(input_var, url):
71
72
headerList = []
72
73
host = ""
73
74
for line in header_lines :
74
- tmpList = line .split (": " )
75
+ key , value = line .split (": " , 1 )
75
76
headerDict = {}
76
- headerDict ['Key' ] = tmpList [ 0 ]
77
- headerDict ['Value' ] = tmpList [ 1 ]
77
+ headerDict ['Key' ] = key
78
+ headerDict ['Value' ] = value
78
79
79
80
# Grab important values
80
81
if headerDict ['Key' ].lower () == "host" :
81
82
host = headerDict ['Value' ]
82
83
83
84
headerList .append (headerDict )
84
- del headerDict
85
- del tmpList
86
85
87
86
postisupload = False
88
87
fileboundary = ""
@@ -122,9 +121,6 @@ def parse_request(input_var, url):
122
121
123
122
tmp ['body' ] = sectionBody
124
123
bodyList .append (tmp )
125
- del tmp
126
- del sectionHeader
127
- del sectionBody
128
124
129
125
else :
130
126
# Create a list of body values (check for JSON, etc)
@@ -133,14 +129,11 @@ def parse_request(input_var, url):
133
129
body_var_List = body_data .split ("&" )
134
130
body_var_List = filter (None , body_var_List )
135
131
for item in body_var_List :
136
- tmpList = item .split ("=" )
132
+ key , value = item .split ("=" , 1 )
137
133
bodyDict = {}
138
- bodyDict ['Key' ] = tmpList [ 0 ]
139
- bodyDict ['Value' ] = tmpList [ 1 ]
134
+ bodyDict ['Key' ] = key
135
+ bodyDict ['Value' ] = value
140
136
bodyList .append (bodyDict )
141
- del tmpList
142
- del bodyDict
143
-
144
137
145
138
# Returned dict, chocked full of useful information formatted nicely for your convienience!
146
139
returnDict = {}
@@ -165,9 +158,7 @@ def parse_response(input_var, url):
165
158
flags = []
166
159
167
160
# Split request into headers/body and parse header into list
168
- request_parts = input_var .split ("\r \n \r \n " )
169
- header_data = request_parts [0 ]
170
- body_data = request_parts [1 ]
161
+ header_data , body_data = input_var .split ("\r \n \r \n " , 1 )
171
162
header_lines = header_data .split ("\r \n " )
172
163
header_lines = filter (None , header_lines ) # Filter any blank lines
173
164
@@ -181,17 +172,15 @@ def parse_response(input_var, url):
181
172
headerList = []
182
173
content_type = ""
183
174
for line in header_lines :
184
- tmpList = line .split (": " )
175
+ key , value = line .split (": " , 1 )
185
176
headerDict = {}
186
- headerDict ['Key' ] = tmpList [ 0 ]
187
- headerDict ['Value' ] = tmpList [ 1 ]
177
+ headerDict ['Key' ] = key
178
+ headerDict ['Value' ] = value
188
179
189
180
if headerDict ['Key' ].lower () == "Content-Type" .lower ():
190
181
content_type = headerDict ['Value' ]
191
182
192
183
headerList .append (headerDict )
193
- del headerDict
194
- del tmpList
195
184
196
185
# Returned dict, chocked full of useful information formatted nicely for your convienience!
197
186
returnDict = {}
@@ -261,9 +250,7 @@ def xss_gen(requestList, settingsDict):
261
250
# Each request is done as a function that one requestion completion, calls the next function.
262
251
# The result is an unclobered browser and no race conditions! (Because cookies may need to be set, etc)
263
252
264
- # Counter for function numbers
265
- i = 0
266
- for conv in requestList :
253
+ for i , conv in enumerate (requestList ):
267
254
requestDict = parse_request (conv ['request' ], conv ['url' ])
268
255
responseDict = parse_response (conv ['response' ], conv ['url' ]) # Currently unused, for future heuristics
269
256
@@ -290,9 +277,6 @@ def xss_gen(requestList, settingsDict):
290
277
multipart += 'Content-Disposition: form-data; name="' + item ['name' ] + '"; filename="' + item ['filename' ] + '"\\ r\\ n'
291
278
multipart += 'Content-Type: ' + content_type + '\\ r\\ n\\ r\\ n'
292
279
multipart += filecontents + '\\ r\\ n'
293
-
294
- del filecontents
295
- del content_type
296
280
else :
297
281
multipart += 'Content-Disposition: form-data; name="' + item ['name' ] + '"; filename="' + item ['filename' ] + '"\\ r\\ n'
298
282
multipart += 'Content-Type: ' + item ['contenttype' ] + '\\ r\\ n\\ r\\ n'
@@ -339,7 +323,6 @@ def xss_gen(requestList, settingsDict):
339
323
340
324
payload += " }\n "
341
325
payload += "\n "
342
- i += 1
343
326
344
327
payload += "</script>"
345
328
return payload
@@ -389,7 +372,6 @@ def xss_gen(requestList, settingsDict):
389
372
tmpList [key ] = value .replace ("\n " , "" )
390
373
if len (tmpList ):
391
374
settingsDict ['parseList' ] = tmpList
392
- del tmpList
393
375
else :
394
376
print "Error, parse list not found!"
395
377
if "-f=" in option :
@@ -409,12 +391,8 @@ def xss_gen(requestList, settingsDict):
409
391
print "Error while parsing file " + fileuploadlist + " on line #" + str (key )
410
392
print " ->'" + value .replace ("\n " , "" ) + "'"
411
393
sys .exit ()
412
- del rowparts
413
394
if tmpDict :
414
395
settingsDict ['fileDict' ] = tmpDict
415
-
416
- del tmpDict
417
- del fileuploadlinesList
418
396
else :
419
397
print "Input filelist not found!"
420
398
sys .exit ()
0 commit comments