-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathPythonTemplateExternalMutationEngine.py
64 lines (55 loc) · 2.24 KB
/
PythonTemplateExternalMutationEngine.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
import json
import configparser
import multiprocessing
import pika
class PythonFuzzer(multiprocessing.Process):
'''
Use this base class to derive your
Python-based fuzzer from. It allows
you to quickly enhance Lucky CAT with
a new fuzzer.
'''
def __init__(self, config_path="fuzzer.cfg"):
super(PythonFuzzer, self).__init__()
self.config = configparser.ConfigParser()
self.config.read(config_path)
def _fuzz_one_test_case(self, test_case_info):
'''
Implement this method in your fuzzer class.
For a demonstartion see luckycat/fuzzers/dummy_fuzzer.py.
In a nutshell, this function takes a JSON document with
including the test case as input. Here you call you execute
the sample and check if a crash occured.
If the target did not crash, then return None.
Otherwise, you should return a dictionary resembling the
following example:
{'fuzzer': NAME_OF_THE_FUZZER,
'filename': test_case_info['filename'],
'signal': CRASH_SIGNAL,
'job_id': sample['job_id'],
}
'''
pass
def _on_test_case(self, channel, method_frame, header_frame, body):
test_case_info = json.loads(body.decode())
res = self._fuzz_one_test_case(test_case_info)
channel.basic_ack(delivery_tag=method_frame.delivery_tag)
if res:
self._send_crash(res)
def _send_crash(self, crash):
conn = pika.BlockingConnection(pika.ConnectionParameters(self.config['DEFAULT']['queue_host']))
channel = conn.channel()
channel.basic_publish(exchange='luckycat',
routing_key=self.config['DEFAULT']['crash_queue'],
body=json.dumps(crash))
conn.close()
def run(self):
connection = pika.BlockingConnection(pika.ConnectionParameters(self.config['DEFAULT']['queue_host']))
channel = connection.channel()
channel.basic_consume(self._on_test_case,
'%s-%s' % (self.config['DEFAULT']['job_name'], 'samples'))
try:
channel.start_consuming()
except KeyboardInterrupt:
channel.stop_consuming()
connection.close()