forked from sefcom/Witcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manual_verifier.py
executable file
·64 lines (54 loc) · 1.79 KB
/
manual_verifier.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
#!/usr/bin/env -S python3 -m IPython
import requests
import json
import argparse
import os
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--fuzzer-cmd', default='fuzzer-master.cmd')
parser.add_argument('-p', '--port', default=8080, type=int)
parser.add_argument('crash_file')
ARGS = parser.parse_args()
with open(ARGS.fuzzer_cmd) as f:
lines = f.read().strip().split('\n')
cmd = lines[0]
assert not lines[1].strip()
env = {}
for l in lines[2:]:
name = l[:l.index("=")]
val = l[l.index("=")+1:]
env[name] = val
docroot = env['DOCUMENT_ROOT']
script_file = env['SCRIPT_FILENAME']
if script_file.startswith(docroot):
endpoint = script_file[len(docroot):].lstrip('/')
else:
docroot, endpoint = script_file.split("/www/")
method = env['METHOD']
assert method.upper() in {'GET', 'POST'}
login_cookie = env['LOGIN_COOKIE']
with open(ARGS.crash_file, 'rb') as f:
data = f.read().split(b'\0')
if len(data) == 1:
cookies = b''
query_string = data[0] if method == 'GET' else b''
post_data = data[0] if method == 'POST' else b''
elif len(data) == 2:
cookies = data[0]
query_string = data[1] if method == 'GET' else b''
post_data = data[1] if method == 'POST' else b''
else:
cookies, query_string, post_data = data[:3]
URL = f'http://localhost:{ARGS.port}/{endpoint}'
if query_string:
URL += '?' + query_string.decode()
headers = {
'Cookie': login_cookie.encode() + b'; ' + cookies
}
print(f"REQUEST: {URL}, headers: {headers}, payload: {repr(post_data)}")
response = requests.request(method, URL, data=post_data)
print(response.status_code)
print(repr(response.content))
print(response.text)
with open('out.html', 'wb') as f:
f.write(response.content)
os.system('firefox out.html')