forked from bitdefender/simpletracer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-tracer.py
executable file
·50 lines (38 loc) · 1.48 KB
/
test-tracer.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
#!/usr/bin/env python
from pwn import *
import random
import os
process_path = './build-river-tools/bin/river.tracer'
test_lib_path = '/home/alex/build/lib/libhttp-parser.so'
max_tests = 500
max_len = 1024
error_messages = ["Disassembling unknown instruction", "Translating unknown instruction"]
execution_log = 'execution.log'
def find_text_in_file(text, filename):
if text in open(filename).read():
return True
return False
def generate_test():
len = random.randint(1, max_len)
return ''.join(os.urandom(1) for i in range(len))
if __name__ == "__main__":
current_test = 0
while current_test < max_tests:
tracer_process_args = [process_path, '--annotated', '--z3', '-p', test_lib_path, '-o', 'trace.simple.out.' + str(current_test)]
payload = generate_test()
print("Send payload [%d] of len: [%d]" % (current_test, len(payload)))
f = open("input." + str(current_test), 'wb')
f.write(payload)
f.close()
tracer = process(tracer_process_args)
tracer.send(payload)
tracer.stdin.close()
tracer.recvall()
tracer.close()
## check if unk instruction was found in executin log
for e in error_messages:
if find_text_in_file(e, execution_log):
print("Obtained error for payload: [%s] in test: [%d]" % (payload, current_test))
break
os.rename(execution_log, 'execution.log.' + str(current_test))
current_test += 1