-
Notifications
You must be signed in to change notification settings - Fork 1
/
replay.py
192 lines (157 loc) · 5.96 KB
/
replay.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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
raw_input('>>>>>>>')
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 on_enter(self, event):
print '>>>>>> OnPageViewChanged'
def on_exit(self, event):
print '<<<<<< OnPageViewChanged'
def destructor(self, event):
print '>>>>>> Enter destructor'
thread = event.get_thread()
stack_trace = thread.get_stack_trace_with_labels()
label_dump = CrashDump.dump_stack_trace_with_labels(stack_trace)
print label_dump
def a(self, event):
print '>>>>>> GenerateBackground 1'
def b(self, event):
print '>>>>>> GenerateBackground 2'
def c(self, event):
print '<<<<<< GenerateBackground'
def d(self, event):
print '|||||||||||||||||||||||||'
def e(self, event):
print 'XXXXXXXXXXXXXXXXXXXXXXXXX'
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()
event.debug.break_at(pid, 0x00C74BB + base, self.printf_hook)
if module.match_name('AcroForm.api'):
base = module.get_base()
event.debug.break_at(pid, 0x0363ADA + base, self.on_enter)
event.debug.break_at(pid, 0x0363B57 + base, self.on_exit)
event.debug.break_at(pid, 0x035F916 + base, self.destructor)
event.debug.break_at(pid, 0x0363B16 + base, self.a)
event.debug.break_at(pid, 0x0363B36 + base, self.b)
event.debug.break_at(pid, 0x0361F3C + base, self.c)
event.debug.break_at(pid, 0x0361DBE + base, self.d)
event.debug.break_at(pid, 0x0244387 + base, self.e)
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\replay.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')
break
i += 1
if __name__ == '__main__':
main()