-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathafl-pytmin.py
92 lines (66 loc) · 1.99 KB
/
afl-pytmin.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
#!/env/python
#
# python afl-pytmin.py <input-dir> <output-dir> <harness-bin>
#
import sys
import os
import subprocess
from Queue import Queue
from threading import Thread
AFL_TMIN_CMD = "/home/debian/tools/fuzzer/afl/afl-2.41b/afl-tmin"
def tmin(workerid, queue, output_dirname, harness_bin):
while True:
data = queue.get()
filename = data["filename"]
counter = data["counter"]
output_path = "%s/%d.rb" %(output_dirname, counter)
args = [
AFL_TMIN_CMD,
"-i",
filename,
"-o",
output_path,
"-t",
"3000",
"-m",
"4096",
"--",
harness_bin,
"@@"
]
print "[i] Processing %s file ... " %(filename)
with open(os.devnull, 'w') as devnull:
p = subprocess.Popen(args, stdout=devnull, stderr=devnull, shell=False)
# p.communicate()
p.wait()
# p.stdout.close()
queue.task_done()
def read_filename(input_dirname):
for f in os.listdir(input_dirname):
yield ("%s/%s" %(input_dirname, f)).strip()
def main():
try:
n_cores = 5
input_dirname = sys.argv[1]
output_dirname = sys.argv[2]
harness_bin = sys.argv[3]
if not os.path.exists(output_dirname):
os.makedirs(output_dirname)
queue = Queue()
# Set up some threads
for i in range(n_cores):
worker = Thread(target=tmin, args=(i, queue, output_dirname, harness_bin, ))
worker.setDaemon(True)
worker.start()
# Fill the queue
counter = 0
for filename in read_filename(input_dirname):
data = { "filename": filename,
"counter": counter }
queue.put(data)
counter = counter + 1
queue.join()
except Exception, e:
print e
if __name__ == "__main__":
main()