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
/
domato.py
executable file
·220 lines (190 loc) · 7.25 KB
/
domato.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env python
#
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import argparse
import json
import logging
import os
import shutil
import subprocess # nosec
import sys
import tempfile
from typing import Optional
from onefuzztypes.enums import OS, ContainerType, TaskType
from onefuzztypes.models import NotificationConfig
from onefuzztypes.primitives import Container
from onefuzz.api import Onefuzz
from onefuzz.templates import JobHelper
AZCOPY_PATH = os.environ.get("AZCOPY") or shutil.which("azcopy")
if not AZCOPY_PATH:
raise Exception("unable to find 'azcopy' in path or AZCOPY environment variable")
FUZZER_NAME = "domato"
FUZZER_URL = "https://github.com/googleprojectzero/domato.git"
FUZZER_NAME = "domato"
FUZZER_URL = "https://github.com/googleprojectzero/domato.git"
PY_URL = "https://www.python.org/ftp/python/3.7.8/python-3.7.8-amd64.exe"
PY_INSTALLER_ARGS = "/passive InstallAllUsers=1 AssociateFiles=1 PrependPath=1"
PY_INSTALLER = """
Invoke-WebRequest -Uri "%s" -OutFile "c:/python-install.exe"
Start-Process "C:\\python-install.exe" -ArgumentList "%s" -Wait
""" % (
PY_URL,
PY_INSTALLER_ARGS,
)
def add_setup_script(of: Onefuzz, container: Container) -> None:
with tempfile.TemporaryDirectory() as tmpdir:
setup = os.path.join(tmpdir, "setup.ps1")
with open(setup, "w") as handle:
handle.write(PY_INSTALLER)
of.containers.files.upload_file(container, setup)
def upload_to_fuzzer_container(of: Onefuzz, fuzzer_name: str, fuzzer_url: str) -> None:
fuzzer_sas = of.containers.create(Container(fuzzer_name)).sas_url
with tempfile.TemporaryDirectory() as tmpdir:
command = ["git", "clone", "--depth", "1", fuzzer_url, tmpdir]
of.logger.info("Dowloading fuzzer '%s' ...", fuzzer_name)
subprocess.check_call(command)
if AZCOPY_PATH is None:
raise Exception("missing azcopy")
command = [AZCOPY_PATH, "sync", tmpdir, fuzzer_sas]
of.logger.info(
"Uploading fuzzer '%s' to OneFuzz: %s",
fuzzer_name,
" ".join(command),
)
subprocess.check_call(command)
def upload_to_setup_container(of: Onefuzz, helper: JobHelper, setup_dir: str) -> None:
setup_sas = of.containers.get(helper.container_name(ContainerType.setup)).sas_url
if AZCOPY_PATH is None:
raise Exception("missing azcopy")
command = [AZCOPY_PATH, "sync", setup_dir, setup_sas]
of.logger.info("Uploading '%s' to OneFuzz: %s", setup_dir, " ".join(command))
subprocess.check_call(command)
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("build", type=str, help="Target build version.")
parser.add_argument("pool_name", type=str, help="Worker pool")
parser.add_argument("--project", type=str, default="msedge", help="Name of project")
parser.add_argument("--name", type=str, default="browser", help="Name of target")
parser.add_argument(
"--duration", type=int, default=1, help="Hours to run the fuzzing task"
)
parser.add_argument("--vm_sku", default="Standard_DS1_v2", help="VM image to use")
parser.add_argument("--notification_config", help="Notification configuration")
parser.add_argument(
"--platform",
type=OS,
help="Specify Platform. Possible values: %s" % ", ".join([x.name for x in OS]),
)
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.INFO)
if not os.path.exists(args.target_exe):
logging.warning(
"target (%s) does not exist. Unless this is "
"downloaded via in-VM setup script, fuzzing will fail",
args.target_exe,
)
if args.platform is None:
logging.error("Without target exe, platform must be set")
sys.exit(1)
helper = JobHelper(
of,
of.logger,
args.project,
args.name,
args.build,
args.duration,
pool_name=args.pool_name,
target_exe=args.target_exe,
platform=args.platform,
)
upload_to_fuzzer_container(of, FUZZER_NAME, FUZZER_URL)
helper.define_containers(
ContainerType.setup,
ContainerType.readonly_inputs,
ContainerType.crashes,
ContainerType.unique_reports,
ContainerType.reports,
)
helper.create_containers()
helper.setup_notifications(notification_config)
upload_to_setup_container(of, helper, args.setup_dir)
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(FUZZER_NAME)),
(ContainerType.setup, helper.container_name(ContainerType.setup)),
(ContainerType.crashes, helper.container_name(ContainerType.crashes)),
(
ContainerType.readonly_inputs,
helper.container_name(ContainerType.readonly_inputs),
),
]
of.logger.info("Creating generic_generator")
target_command = [
"--no-sandbox",
"--no-first-run",
"--no-default-browser-check",
"--allow-file-access-from-files",
"--disable-popup-blocking",
"--enable-logging=stderr",
"--js-flags='--expose_gc'",
"--window-size=1024,1024",
"--enable-webgl-draft-extensions",
"--enable-experimental-web-platform-features",
"--enable-experimental-canvas-features",
"--user-data-dir=c:\\msedge-data",
"{input}",
]
fuzzer_generator = "python.exe"
fuzzer_generator_options = [
"{tools_dir}/generator.py",
"--output_dir",
"{generated_inputs}",
"--no_of_files",
"1000",
]
of.tasks.create(
job.job_id,
TaskType.generic_generator,
helper.setup_relative_blob_name(args.target_exe, args.setup_dir),
containers,
pool_name=args.pool_name,
target_options=target_command,
duration=args.duration,
generator_exe=fuzzer_generator,
generator_options=fuzzer_generator_options,
reboot_after_setup=True,
)
if __name__ == "__main__":
main()