-
Notifications
You must be signed in to change notification settings - Fork 1
/
fuzzer.py
156 lines (130 loc) · 4.92 KB
/
fuzzer.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import sys
import struct
import threading
import os as op
import ctypes
from winappdbg.win32 import *
from time import sleep
from winappdbg import System
from winappdbg import Debug, EventHandler, HexDump, Crash, CrashDump
user32 = ctypes.windll.user32
try:
from winappdbg import CrashDAO
except ImportError:
raise ImportError("Error: SQLAlchemy is not installed!")
class Fuzzer(EventHandler):
def __init__(self, logfile):
EventHandler.__init__(self)
self.modules = {}
self.loaded_modules = {}
self.logfile = logfile
self.crashed = 0
def exception(self, event):
code = event.get_exception_code()
if code in [EXCEPTION_ACCESS_VIOLATION, EXCEPTION_ARRAY_BOUNDS_EXCEEDED, EXCEPTION_ILLEGAL_INSTRUCTION, EXCEPTION_PRIV_INSTRUCTION, EXCEPTION_STACK_OVERFLOW, EXCEPTION_GUARD_PAGE]:
thread = event.get_thread()
process = event.get_process()
address = event.get_fault_address()
context = thread.get_context()
stack_trace = thread.get_stack_trace_with_labels()
t = '=======CRASH CONTEXT==============='
print t
self.logfile.write(t + '\n')
regs_dump = CrashDump.dump_registers(context)
eip = thread.get_pc()
code = thread.disassemble_around(eip)
print regs_dump
self.logfile.write(regs_dump)
code_dump = CrashDump.dump_code(code,eip)
label_dump = CrashDump.dump_stack_trace_with_labels(stack_trace)
print code_dump
print label_dump
self.logfile.write(code_dump + '\n')
self.logfile.write(label_dump + '\n')
for module_name in self.modules:
m = module_name + ' ' + hex(self.modules[module_name])
print m
self.logfile.write(m + '\n')
self.logfile.write('[**]' + repr(Rands) + '\n')
self.crashed = 1
process.kill()
def load_dll(self, event):
pid = event.get_pid()
module = event.get_module()
process = event.get_process()
base = module.get_base()
self.modules[module.get_name()] = base
def printf_hook(self, event):
global Rands
process = event.get_process()
thread = event.get_thread()
registers = thread.get_context()
eax = registers['Eax']
d = process.peek_string(eax, fUnicode = True)
if d[0] == '\x02':
try:
Rands.append(int(d[1:].strip()))
except:
print repr(d)
raw_input('[SHIT HAPPENS]')
elif d[0] == '\x01':
print d[1:]
self.logfile.write(d[1:] + '\n')
elif d[0] == '\x03':
process.kill()
def create_process(self, event):
pid = event.get_pid()
process = event.get_process()
for module in process.iter_modules():
if module.match_name('EScript.api'):
base = module.get_base()
if len(sys.argv) >= 2:
event.debug.break_at(pid, 0x00C74BB + base, self.printf_hook)
else:
event.debug.break_at(pid, 0x00C76C4 + base, self.printf_hook)
Rands = []
def fuzz_one(iteration, logfile):
EXECUTALBE_PATH = r'C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe'
PDF_PATH = op.getcwd() + r'\trusted\fuzz.pdf'
# PDF_PATH = op.getcwd() + r'\test.pdf'
fuzzer = Fuzzer(logfile)
system = System()
process = system.start_process( EXECUTALBE_PATH + ' ' + PDF_PATH )
hMsgBox = None
while not hMsgBox:
try:
hMsgBox = FindWindowA('#32770', 'Warning: JavaScript Window - ')
except:
pass
sleep(5)
try:
SetForegroundWindow(hMsgBox)
except:
pass
user32.keybd_event(0xd, 0xd, 0, 0)
user32.keybd_event(0xd, 0xd, 2, 0)
with Debug( fuzzer, bKillOnExit = True ) as debug:
try:
debug.attach(process.get_pid())
debug.loop()
except KeyboardInterrupt:
print "Interrupted by user"
debug.stop()
finally:
debug.stop()
return fuzzer.crashed
def main():
global Rands
i = 0
while (1):
fname = 'logs\\runs\\iter%d' % i
logfile = open(fname, 'w')
crashed = fuzz_one(i, logfile)
logfile.close()
Rands = []
op.system('taskkill /f /im adobe_licutil.exe')
if crashed:
op.system('move %s %s' % (fname, 'logs\\crashes'))
i += 1
if __name__ == '__main__':
main()