def set_up(self, input_file_path, tmp_dir_path, params): self.input = input_file_path self.output = tmp_dir_path self.params = params self.sane = False # defaults gen = 'dfuzz.gen.autodafe' mut = 'dfuzz.mut.zzuf_10' if len(self.params) > 0: if len(self.params) == 2: gen, mut = self.params else: logging.warning('Wrong %s parameter format,' ' using defaults.', self) gen += '.FuzzWrapper' mut += '.FuzzWrapper' emsg = '[combinator] Unable to load class: "%s"' self.gen_cls = utils.get_class_by_path(gen) if not self.gen_cls: logging.error(emsg, gen) return self.mut_cls = utils.get_class_by_path(mut) if not self.mut_cls: logging.error(emsg, mut) return self.gen = self.gen_cls() self.mut = self.mut_cls() self.sane = True
def validate_module(self, str_mod): ''' Try to import and load `str_mod` module, check required methods. Returns class for valid classes, False otherwise. ''' cls = utils.get_class_by_path(str_mod + '.FuzzWrapper') if not cls: logging.warning('Unable to load wrapper, skipping') return False else: if self.check_methods(cls, str_mod): return cls else: return False
def validate_module(self, str_mod): ''' Try to import and load `str_mod` module, check required methods. Returns class for valid classes, False otherwise. ''' cls = utils.get_class_by_path(str_mod + '.FuzzWrapper') if not cls: logging.warning('Unable to load wrapper, skipping') return False else: if self.check_methods(cls, str_mod): return cls else: return False
def run(self): ''' Set up and run single instance of the class. This takes the input files, runs each of them through specific fuzzer (wrapper) and runs the executable with fuzzed input (via TargetRunner class). ''' cls, params = self.cls_tuple logging.debug('Instantiating class %s', cls) to_run = cls() tmp_dir_path = os.path.join(self.cfg.tmp_dir, str(to_run)) logging.debug('[%s] Creating tmp dir [%s]', to_run, tmp_dir_path) if os.path.isdir(tmp_dir_path): shutil.rmtree(tmp_dir_path) os.mkdir(tmp_dir_path) inputs = self.get_inputs(to_run.method()) for input_file_path in inputs: logging.debug('[%s] Input file: "%s"', to_run, input_file_path) logging.debug('[%s] Set up phase', to_run) to_run.set_up(input_file_path, tmp_dir_path, params) logging.debug('[%s] Run phase', to_run) generator = to_run.run() if generator is None: logging.error('[%s] Terminating due to an error, ' ' no files supplied by the wrapper', to_run) break for file in generator(): if file is None: logging.error('[%s] Skipping input file "%s" ' 'due to an error', input_file_path, to_run) break logging.debug('[%s] Using fuzzed file "%s"', to_run, os.path.basename(file)) if self.cfg.use_no_fuzz: utils.handle_no_fuzz(file, self.cfg.no_fuzz_file, self.cfg.use_no_fuzz) targ_cls = utils.get_class_by_path(self.cfg.target) if not targ_cls: logging.warning('Target class "%s" not found,' ' using default class.', self.cfg.target) targ_cls = target.Target targ = targ_cls(self.cfg) targ.run(file) if self.cfg.debug_output: logging.debug('stdout: %s' ,targ.stdout) logging.debug('stderr: %s' ,targ.stderr) logging.debug('code: %s', targ.code) inc_cls = utils.get_class_by_path(self.cfg.incident) if not inc_cls: logging.warning('Incident class "%s" not found,' ' using default class.', self.cfg.incident) inc_cls = incident.Incident hand_cls = utils.get_class_by_path( self.cfg.incident_handler) if not hand_cls: logging.warning('Incident class "%s" not found,' ' using default class.', self.cfg.incident_handler) hand_cls = handler.IncidentHandler inc = inc_cls(self.cfg, str(to_run), hand_cls) inc.check(targ, file) if self.samples < self.cfg.num_samples: utils.save_sample(file, targ, self.cfg.samples_dir) self.samples += 1 if inputs == []: logging.warning('No input files for method "%s" found', to_run.method()) logging.debug('[%s] Remove tmp dir', to_run) shutil.rmtree(tmp_dir_path)