This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
/
honggfuzz.py
153 lines (132 loc) · 4.48 KB
/
honggfuzz.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
#!/usr/bin/env python
#
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import argparse
import json
import logging
import os
import tempfile
from typing import Optional
from onefuzztypes.enums import ContainerType, TaskType
from onefuzztypes.models import NotificationConfig
from onefuzztypes.primitives import Container
from onefuzz.api import Onefuzz
from onefuzz.templates import JobHelper
SETUP = """
cd /onefuzz
apt-get update
apt-get -y install build-essential libbfd-dev libunwind-dev
git clone https://github.com/google/honggfuzz/
cd /onefuzz/honggfuzz
make
"""
def add_setup_script(of: Onefuzz, container: Container) -> None:
with tempfile.TemporaryDirectory() as tmpdir:
setup = os.path.join(tmpdir, "setup.sh")
with open(setup, "w") as handle:
handle.write(SETUP)
of.containers.files.upload_file(container, setup)
def main() -> None:
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument("setup_dir", type=str, help="Target setup directory")
parser.add_argument(
"target_exe", type=str, help="Target executable within setup directory"
)
parser.add_argument("project", type=str, help="Name of project")
parser.add_argument("name", type=str, help="Name of target")
parser.add_argument("build", type=str, help="Target build version.")
parser.add_argument("pool_name", type=str, help="VM pool to use")
parser.add_argument(
"--duration", type=int, default=1, help="Hours to run the fuzzing task"
)
parser.add_argument("--inputs", help="seeds to use")
parser.add_argument("--notification_config", help="Notification configuration")
args = parser.parse_args()
notification_config: Optional[NotificationConfig] = None
if args.notification_config:
with open(args.notification_config) as handle:
notification_config = NotificationConfig.parse_obj(json.load(handle))
of = Onefuzz()
logging.basicConfig(level=logging.WARNING)
of.logger.setLevel(logging.DEBUG)
helper = JobHelper(
of,
of.logger,
args.project,
args.name,
args.build,
args.duration,
pool_name=args.pool_name,
target_exe=args.target_exe,
)
helper.define_containers(
ContainerType.setup,
ContainerType.readonly_inputs,
ContainerType.crashes,
ContainerType.inputs,
ContainerType.reports,
ContainerType.unique_reports,
)
helper.create_containers()
helper.setup_notifications(notification_config)
helper.upload_setup(args.setup_dir, args.target_exe)
if args.inputs:
helper.upload_inputs(args.inputs)
add_setup_script(of, helper.container_name(ContainerType.setup))
containers = [
(ContainerType.setup, helper.container_name(ContainerType.setup)),
(ContainerType.crashes, helper.container_name(ContainerType.crashes)),
(ContainerType.reports, helper.container_name(ContainerType.reports)),
(
ContainerType.unique_reports,
helper.container_name(ContainerType.unique_reports),
),
]
of.logger.info("Creating generic_crash_report task")
job = helper.create_job()
of.tasks.create(
job.job_id,
TaskType.generic_crash_report,
helper.setup_relative_blob_name(args.target_exe, args.setup_dir),
containers,
pool_name=args.pool_name,
duration=args.duration,
)
containers = [
(ContainerType.tools, Container("honggfuzz")),
(ContainerType.setup, helper.container_name(ContainerType.setup)),
(ContainerType.crashes, helper.container_name(ContainerType.crashes)),
(
ContainerType.inputs,
helper.container_name(ContainerType.inputs),
),
]
supervisor_options = [
"-n1",
"--crashdir",
"{crashes}",
"-u",
"-i",
"{input_corpus}",
"--",
"{target_exe}",
"{input}",
]
of.tasks.create(
job.job_id,
TaskType.generic_supervisor,
helper.setup_relative_blob_name(args.target_exe, args.setup_dir),
containers,
pool_name=args.pool_name,
supervisor_exe="/onefuzz/honggfuzz/honggfuzz",
supervisor_options=supervisor_options,
supervisor_input_marker="___FILE___",
duration=args.duration,
vm_count=1,
tags=helper.tags,
)
if __name__ == "__main__":
main()