def main(req: func.HttpRequest) -> func.HttpResponse: logging.info("Python HTTP trigger function processed a request.") o = Onefuzz() o.config( endpoint=os.environ.get("ONEFUZZ_ENDPOINT"), authority=os.environ.get("ONEFUZZ_AUTHORITY"), client_id=os.environ.get("ONEFUZZ_CLIENT_ID"), ) info = o.info.get() return func.HttpResponse(info.json())
def __init__(self, resource_group: str = None, onefuzz_config_path: str = None) -> None: self.onefuzz = Onefuzz(config_path=onefuzz_config_path) self.intial_config = self.onefuzz.instance_config.get() self.instance_name = urlparse( self.onefuzz.config().endpoint).netloc.split(".")[0] if resource_group: self.resource_group = resource_group else: self.resource_group = self.instance_name
def main() -> None: of = Onefuzz() containers = [x.name for x in of.containers.list()] for entry in of.notifications.list(): container = entry.container if container not in containers: continue files = of.containers.files.list(container).files assert len(files), "missing files in report container: %s" % container assert files[0].endswith(".json"), "not .json extension: %s" % files[0] data = json.loads(of.containers.files.get(container, files[0])) print("checking", data["task_id"]) check_call(["python", "check-ado.py", "--title", data["task_id"]])
def test_path_resolution(self) -> None: helper = JobHelper( Onefuzz(), logging.getLogger(), "a", "b", "c", False, target_exe=File("README.md"), job=Job( job_id=UUID("0" * 32), state=JobState.init, config=JobConfig(project="a", name="a", build="a", duration=1), ), ) values = { (File("filename.txt"), None): "filename.txt", (File("dir/filename.txt"), None): "filename.txt", (File("./filename.txt"), None): "filename.txt", (File("./filename.txt"), Directory(".")): "filename.txt", (File("dir/filename.txt"), Directory("dir")): "filename.txt", (File("dir/filename.txt"), Directory("dir/")): "filename.txt", (File("dir/filename.txt"), Directory("./dir")): "filename.txt", (File("./dir/filename.txt"), Directory("./dir/")): "filename.txt", } expected = "filename.txt" if sys.platform == "linux": filename = File("/unused/filename.txt") values[(filename, None)] = expected values[(filename, Directory("/unused"))] = expected values[(filename, Directory("/unused/"))] = expected if sys.platform == "windows": for filename in [ File("c:/unused/filename.txt"), File("c:\\unused/filename.txt"), File("c:\\unused\\filename.txt"), ]: values[(filename, None)] = expected values[(filename, Directory("c:/unused"))] = expected values[(filename, Directory("c:/unused/"))] = expected values[(filename, Directory("c:\\unused\\"))] = expected values[(filename, Directory("c:\\unused\\"))] = expected for (args, expected) in values.items(): self.assertEqual(helper.target_exe_blob_name(*args), expected) with self.assertRaises(ValueError): helper.target_exe_blob_name(File("dir/filename.txt"), Directory("other_dir"))
def main() -> None: onefuzz = Onefuzz() jobs = onefuzz.jobs.list() for job in jobs: print( "job:", str(job.job_id)[:8], ":".join([job.config.project, job.config.name, job.config.build]), ) for task in onefuzz.tasks.list(job_id=job.job_id): if task.state in ["stopped", "stopping"]: continue print( " ", str(task.task_id)[:8], task.config.task.type, task.config.task.target_exe, )
def execute(request: OnefuzzTemplateRequest, config: OnefuzzTemplate) -> None: # This is intended to emulate what the service would execute, which assumes # the storage containers have been created and content uploaded to them. o = Onefuzz() for template_notification in config.notifications: for task_container in request.containers: if task_container.type == template_notification.container_type: o.notifications.create(task_container.name, template_notification.notification) job = o.jobs.create_with_config(config.job) tasks = [] for task_config in config.tasks: task_config.job_id = job.job_id if task_config.prereq_tasks: # the model checker verifies prereq_tasks in u128 form are index refs to # previously generated tasks task_config.prereq_tasks = [ tasks[x.int].task_id for x in task_config.prereq_tasks ] tasks.append(o.tasks.create_with_config(task_config))
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_coverage_exe", type=str, help= "Target executable within setup directory with coverage instrumentation", ) 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("tools", type=str, help="tools directory") parser.add_argument("--duration", type=int, default=24, help="Hours to run the fuzzing task") parser.add_argument("--inputs", help="seeds to use") args = parser.parse_args() of = Onefuzz() logging.basicConfig(level=logging.WARNING) of.logger.setLevel(logging.INFO) helper = JobHelper( of, of.logger, args.project, args.name, args.build, args.duration, pool_name=args.pool_name, target_exe=args.target_coverage_exe, ) helper.define_containers( ContainerType.setup, ContainerType.analysis, ContainerType.inputs, ContainerType.tools, ) helper.create_containers() helper.upload_setup(args.setup_dir, args.target_coverage_exe) if args.inputs: helper.upload_inputs(args.inputs) of.containers.files.upload_file(helper.containers[ContainerType.tools], f"{args.tools}/source-coverage.sh") containers = [ (ContainerType.setup, helper.containers[ContainerType.setup]), (ContainerType.analysis, helper.containers[ContainerType.analysis]), (ContainerType.tools, helper.containers[ContainerType.tools]), # note, analysis is typically for crashes, but this is analyzing inputs (ContainerType.crashes, helper.containers[ContainerType.inputs]), ] of.logger.info("Creating generic_analysis task") of.tasks.create( helper.job.job_id, TaskType.generic_analysis, helper.setup_relative_blob_name(args.target_coverage_exe, args.setup_dir), containers, pool_name=args.pool_name, duration=args.duration, analyzer_exe="{tools_dir}/source-coverage.sh", analyzer_options=["{target_exe}", "{output_dir}", "{input}"], ) print(f"job:{helper.job.json(indent=4)}")
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.containers[ContainerType.setup]) containers = [ (ContainerType.setup, helper.containers[ContainerType.setup]), (ContainerType.crashes, helper.containers[ContainerType.crashes]), (ContainerType.reports, helper.containers[ContainerType.reports]), (ContainerType.unique_reports, helper.containers[ContainerType.unique_reports]), ] of.logger.info("Creating generic_crash_report task") of.tasks.create( helper.job.job_id, TaskType.generic_crash_report, helper.target_exe_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.containers[ContainerType.setup]), (ContainerType.crashes, helper.containers[ContainerType.crashes]), ( ContainerType.inputs, helper.containers[ContainerType.inputs], ), ] supervisor_options = [ "-n1", "--crashdir", "{crashes}", "-u", "-i", "{input_corpus}", "--", "{target_exe}", "{input}", ] of.tasks.create( helper.job.job_id, TaskType.generic_supervisor, helper.target_exe_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, )
def main() -> int: return execute_api(Ossfuzz(Onefuzz(), logging.getLogger("ossfuzz")), [Command], "0.0.1")
def main() -> int: return execute_api(Onefuzz(), [Endpoint, Command], __version__)
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.containers[ContainerType.setup]) containers = [ (ContainerType.setup, helper.containers[ContainerType.setup]), (ContainerType.crashes, helper.containers[ContainerType.crashes]), (ContainerType.reports, helper.containers[ContainerType.reports]), (ContainerType.unique_reports, helper.containers[ContainerType.unique_reports]), ] of.logger.info("Creating generic_crash_report task") of.tasks.create( helper.job.job_id, TaskType.generic_crash_report, helper.target_exe_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.containers[ContainerType.setup]), (ContainerType.crashes, helper.containers[ContainerType.crashes]), ( ContainerType.readonly_inputs, helper.containers[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( helper.job.job_id, TaskType.generic_generator, helper.target_exe_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, )
class APIRestrictionTests: def __init__(self, resource_group: str = None, onefuzz_config_path: str = None) -> None: self.onefuzz = Onefuzz(config_path=onefuzz_config_path) self.intial_config = self.onefuzz.instance_config.get() self.instance_name = urlparse( self.onefuzz.config().endpoint).netloc.split(".")[0] if resource_group: self.resource_group = resource_group else: self.resource_group = self.instance_name def restore_config(self) -> None: self.onefuzz.instance_config.update(self.intial_config) def assign(self, group_id: UUID, member_id: UUID) -> None: instance_config = self.onefuzz.instance_config.get() if instance_config.group_membership is None: instance_config.group_membership = {} if member_id not in instance_config.group_membership: instance_config.group_membership[member_id] = [] if group_id not in instance_config.group_membership[member_id]: instance_config.group_membership[member_id].append(group_id) self.onefuzz.instance_config.update(instance_config) def assign_current_user(self, group_id: UUID) -> None: onefuzz_service_appId = az_cli([ "ad", "signed-in-user", "show", ]) member_id = UUID(onefuzz_service_appId["objectId"]) print(f"adding user {member_id}") self.assign(group_id, member_id) def test_restriction_on_current_user(self) -> None: print("Checking that the current user can get jobs") self.onefuzz.jobs.list() print("Creating test group") group_id = uuid.uuid4() print("Adding restriction to the jobs endpoint") instance_config = self.onefuzz.instance_config.get() if instance_config.api_access_rules is None: instance_config.api_access_rules = {} instance_config.api_access_rules["/api/jobs"] = ApiAccessRule( allowed_groups=[group_id], methods=["GET"], ) self.onefuzz.instance_config.update(instance_config) restart_instance(self.instance_name, self.resource_group) time.sleep(20) print("Checking that the current user cannot get jobs") try: self.onefuzz.jobs.list() failed = False except Exception: failed = True pass if not failed: raise Exception("Current user was able to get jobs") print("Assigning current user to test group") self.assign_current_user(group_id) restart_instance(self.instance_name, self.resource_group) time.sleep(20) print("Checking that the current user can get jobs") self.onefuzz.jobs.list()
def main() -> int: return execute_api(Run(Onefuzz(), logging.getLogger("integration")), [Command], "0.0.1")
def __init__(self, onefuzz_config_path=None): self.onefuzz = Onefuzz(config_path=onefuzz_config_path)