-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfuzz_x8664_linux.py
executable file
·83 lines (56 loc) · 1.94 KB
/
fuzz_x8664_linux.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
78
79
80
81
82
83
#!/usr/bin/env python3
import functools
import os
from qiling import Qiling
from qiling.const import QL_VERBOSE
from qiling.os.posix import stat
from crusher_qiling import QilingInstrumentation, read_path_arguments
class MyPipe:
"""Fake stdin to handle incoming fuzzed keystrokes."""
def __init__(self):
self.buf = b""
def write(self, s: bytes):
self.buf += s
def read(self, size: int) -> bytes:
ret = self.buf[:size]
self.buf = self.buf[size:]
return ret
def fileno(self) -> int:
return 0
def show(self):
pass
def clear(self):
pass
def flush(self):
pass
def close(self):
self.outpipe.close()
def lseek(self, offset: int, origin: int):
pass
def fstat(self):
return stat.Fstat(self.fileno())
def place_input_callback(instrumentation: QilingInstrumentation, stdin_mock: MyPipe):
"""Called with every newly generated input."""
stdin_mock.write(instrumentation.cur_input)
stdin_mock = MyPipe()
ql = Qiling(
["./x8664_fuzz"],
"./rootfs",
verbose=QL_VERBOSE.OFF, # keep qiling logging off
console=False, # thwart program output
stdin=stdin_mock, # redirect stdin to our fake one
stdout=None,
stderr=None,
)
args = read_path_arguments()
instrumentation = QilingInstrumentation(args.input_path, [ql.os.exit_point], args.lighthouse)
# get image base address
ba = ql.loader.images[0].base
# make process crash whenever __stack_chk_fail@plt is about to be called.
# this way afl will count stack protection violations as crashes
ql.hook_address(callback=lambda x: os.abort(), address=ba + 0x1225)
# set a hook on main() to let unicorn fork and start instrumentation
ql.hook_address(callback=instrumentation.start_fuzzing_hook, address=ba + 0x122C)
instrumentation.set_input_callback(functools.partial(place_input_callback, stdin_mock=stdin_mock))
# okay, ready to roll
instrumentation.run(ql)