-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtempCodeRunnerFile.py
77 lines (70 loc) · 2.14 KB
/
tempCodeRunnerFile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from xml.etree import ElementTree as ET
import urllib.parse
import os
import base64
import csv
log_path = "./burp_log2"
def parse_log(log_path):
'''
This function accepts burp log file path
and returns a dict of requests and responses
result = {'GET /page.php...':'200 OK HTTP / 1.1....','':'',.....}
'''
result = {}
if not os.path.exists(log_path):
print("[+] Error!!!", log_path, "doesn't exist..")
exit()
try:
tree = ET.parse(log_path)
except ET.ParseError:
print('[+] Oops..! Please make sure binary data is not present in the log, like raw image dump, flash (.swf files) dump, etc.')
exit()
root = tree.getroot()
for reqs in root.findall('item'):
raw_req = reqs.find('request').text
if raw_req is not None:
raw_req = urllib.parse.unquote(raw_req)
raw_resp = reqs.find('response').text
result[raw_req] = raw_resp
return result
def parseRawHTTPReq(rawreq):
try:
raw = rawreq.decode('utf8')
except Exception as e:
raw = rawreq
headers = {}
sp = raw.split('\r\n\r\n', 1)
if len(sp) > 1:
head = sp[0]
body = sp[1]
else:
head = sp[0]
body = ""
lines = head.split('\r\n')
request_line = lines[0]
method, path, _ = request_line.split(' ', 2)
for line in lines[1:]:
if ': ' in line:
key, value = line.split(': ', 1)
headers[key] = value
return headers, method, body, path
# Open the log file
with open('httplog.csv', "w", newline='') as f:
c = csv.writer(f)
c.writerow(["method", "body", "path", "headers"])
result = parse_log(log_path)
for raw_req in result:
data = []
try:
raaw = base64.b64decode(raw_req.encode('utf-8'))
headers, method, body, path = parseRawHTTPReq(raaw)
data.append(method)
data.append(body)
data.append(path)
data.append(headers)
with open('httplog.csv', "a", newline='') as f:
c = csv.writer(f)
c.writerow(data)
except Exception as e:
print(f"[+] Error processing request: {e}")
continue