def upload_inputs_zip(self, path: File) -> None: with tempfile.TemporaryDirectory() as tmp_dir: with zipfile.ZipFile(path, "r") as zip_ref: zip_ref.extractall(tmp_dir) self.logger.info("uploading inputs from zip: `%s`" % path) self.onefuzz.containers.files.upload_dir( self.containers[ContainerType.inputs], Directory(tmp_dir))
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 launch(self, path: Directory, *, os_list: List[OS], targets: List[str], duration=int) -> None: """ Launch all of the fuzzing templates """ for target, config in TARGETS.items(): if target not in targets: continue if config.os not in os_list: continue self.logger.info("launching: %s", target) setup = Directory(os.path.join( path, target)) if config.use_setup else None target_exe = File(os.path.join(path, target, config.target_exe)) inputs = (Directory(os.path.join(path, target, config.inputs)) if config.inputs else None) if setup and config.nested_setup_dir: setup = Directory(os.path.join(setup, config.nested_setup_dir)) job: Optional[Job] = None if config.template == TemplateType.libfuzzer: job = self.of.template.libfuzzer.basic( self.project, target, BUILD, self.pools[config.os].name, target_exe=target_exe, inputs=inputs, setup_dir=setup, duration=duration, vm_count=1, reboot_after_setup=config.reboot_after_setup or False, ) elif config.template == TemplateType.libfuzzer_dotnet: if setup is None: raise Exception("setup required for libfuzzer_dotnet") job = self.of.template.libfuzzer.dotnet( self.project, target, BUILD, self.pools[config.os].name, target_harness=config.target_exe, inputs=inputs, setup_dir=setup, duration=duration, vm_count=1, ) elif config.template == TemplateType.libfuzzer_qemu_user: job = self.of.template.libfuzzer.qemu_user( self.project, target, BUILD, self.pools[config.os].name, inputs=inputs, target_exe=target_exe, duration=duration, vm_count=1, ) elif config.template == TemplateType.radamsa: job = self.of.template.radamsa.basic( self.project, target, BUILD, pool_name=self.pools[config.os].name, target_exe=target_exe, inputs=inputs, setup_dir=setup, check_asan_log=config.check_asan_log or False, disable_check_debugger=config.disable_check_debugger or False, duration=duration, vm_count=1, ) elif config.template == TemplateType.afl: job = self.of.template.afl.basic( self.project, target, BUILD, pool_name=self.pools[config.os].name, target_exe=target_exe, inputs=inputs, setup_dir=setup, duration=duration, vm_count=1, ) else: raise NotImplementedError if not job: raise Exception("missing job")
def launch(self, path: str) -> None: """ Launch all of the fuzzing templates """ for target, config in TARGETS.items(): if target not in self.targets: continue if config.os not in self.os: continue self.logger.info("launching: %s", target) setup = Directory(os.path.join( path, target)) if config.use_setup else None target_exe = File(os.path.join(path, target, config.target_exe)) inputs = (Directory(os.path.join(path, target, config.inputs)) if config.inputs else None) job: Optional[Job] = None if config.template == TemplateType.libfuzzer: job = self.of.template.libfuzzer.basic( self.project, target, BUILD, self.pools[config.os].name, target_exe=target_exe, inputs=inputs, setup_dir=setup, duration=1, vm_count=1, ) elif config.template == TemplateType.radamsa: job = self.of.template.radamsa.basic( self.project, target, BUILD, pool_name=self.pools[config.os].name, target_exe=target_exe, inputs=inputs, setup_dir=setup, check_asan_log=config.check_asan_log or False, disable_check_debugger=config.disable_check_debugger or False, duration=1, vm_count=1, ) elif config.template == TemplateType.afl: job = self.of.template.afl.basic( self.project, target, BUILD, pool_name=self.pools[config.os].name, target_exe=target_exe, inputs=inputs, setup_dir=setup, duration=1, vm_count=1, ) else: raise NotImplementedError if not job: raise Exception("missing job") self.containers[job.job_id] = [] for task in self.of.tasks.list(job_id=job.job_id): self.tasks[task.task_id] = job.job_id self.containers[job.job_id] += [ ContainerWrapper(self.of.containers.get(x.name).sas_url) for x in task.config.containers if x.type in TARGETS[job.config.name].wait_for_files ] self.jobs[job.job_id] = job self.target_jobs[job.job_id] = target
def launch(self, path: Directory, *, os_list: List[OS], targets: List[str], duration=int) -> List[UUID]: """Launch all of the fuzzing templates""" pools = {} for pool in self.of.pools.list(): pools[pool.os] = pool job_ids = [] for target, config in TARGETS.items(): if target not in targets: continue if config.os not in os_list: continue if config.os not in pools.keys(): raise Exception( f"No pool for target: {target} ,os: {config.os}") self.logger.info("launching: %s", target) setup = Directory(os.path.join( path, target)) if config.use_setup else None target_exe = File(os.path.join(path, target, config.target_exe)) inputs = (Directory(os.path.join(path, target, config.inputs)) if config.inputs else None) if setup and config.nested_setup_dir: setup = Directory(os.path.join(setup, config.nested_setup_dir)) job: Optional[Job] = None if config.template == TemplateType.libfuzzer: job = self.of.template.libfuzzer.basic( self.project, target, BUILD, pools[config.os].name, target_exe=target_exe, inputs=inputs, setup_dir=setup, duration=duration, vm_count=1, reboot_after_setup=config.reboot_after_setup or False, target_options=config.target_options, ) elif config.template == TemplateType.libfuzzer_dotnet: if setup is None: raise Exception("setup required for libfuzzer_dotnet") job = self.of.template.libfuzzer.dotnet( self.project, target, BUILD, pools[config.os].name, target_harness=config.target_exe, inputs=inputs, setup_dir=setup, duration=duration, vm_count=1, target_options=config.target_options, ) elif config.template == TemplateType.libfuzzer_qemu_user: job = self.of.template.libfuzzer.qemu_user( self.project, target, BUILD, pools[config.os].name, inputs=inputs, target_exe=target_exe, duration=duration, vm_count=1, target_options=config.target_options, ) elif config.template == TemplateType.radamsa: job = self.of.template.radamsa.basic( self.project, target, BUILD, pool_name=pools[config.os].name, target_exe=target_exe, inputs=inputs, setup_dir=setup, check_asan_log=config.check_asan_log or False, disable_check_debugger=config.disable_check_debugger or False, duration=duration, vm_count=1, ) elif config.template == TemplateType.afl: job = self.of.template.afl.basic( self.project, target, BUILD, pool_name=pools[config.os].name, target_exe=target_exe, inputs=inputs, setup_dir=setup, duration=duration, vm_count=1, target_options=config.target_options, ) else: raise NotImplementedError if config.inject_fake_regression and job is not None: self.of.debug.notification.job(job.job_id) if not job: raise Exception("missing job") job_ids.append(job.job_id) return job_ids