-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfuzzer.py
74 lines (49 loc) · 1.54 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
#!/usr/bin/python
#Fuzzer for testing texmaker
#http://www.xm1math.net/texmaker/
import math
import random
import string
import subprocess
import time
#List of files to use as initial seed
file_list=[]
for i in range(1,11):
file_name = "./tests/test"+ str(i) + ".tex"
file_list.append(file_name)
#Application to test
app = "/Applications/texmaker.app/Contents/MacOS/texmaker"
fuzz_output = "fuzzed_input.tex"
fuzz_factor = 50
num_tests = 200
verbose = False
for i in range(num_tests):
file_choice = random.choice(file_list)
buf= bytearray(open(file_choice, 'rb').read()) #read in binary
#5-line fuzzer from Charlie MIller's "Babysitting an Army of Monkeys"
#---------------------------------------------------------
num_writes = random.randrange(math.ceil((float(len(buf)) / fuzz_factor ))) +1
for j in range(num_writes):
rbyte = random.randrange(256)
rn = random.randrange(len(buf))
buf[rn] = "%c"%(rbyte)
#----------------------------------------------------------
#save mutated input
open(fuzz_output, 'wb').write(buf)
#open application with mutated input
process = subprocess.Popen([app,fuzz_output])
#see what happens
time.sleep(1)
crashed=process.poll()
#process.terminate()
if crashed:
#renaming input file
crashing_file = "crash_"+file_choice
subprocess.call(['rename',file_choice,crashing_file], shell=True)
print "process crashed with input file " + crashing_file
exit(1)
if not crashed:
if verbose:
print "Test", i, "file "+ file_choice + " OK"
process.terminate()
print "All tests OK"