def clean_tmp_unix(self, extras=[]): ''' Starts at the top level of tmpdir and deletes files, directories and symlinks owned by the same uid as the current process. ''' my_uid = os.getuid() for basename in os.listdir(self.tmp_dir): path = os.path.join(self.tmp_dir, basename) try: if os.path.islink(path): path_uid = os.lstat(path).st_uid else: path_uid = os.stat(path).st_uid if my_uid == path_uid: if os.path.isfile(path): os.remove(path) elif os.path.islink(path): os.unlink(path) elif os.path.isdir(path): shutil.rmtree(path) except (IOError, OSError): # we don't mind these exceptions as they're usually indicative # of a file that got deleted before we could do the same continue # We've just cleaned tmp, which is the default watchdog file location # If BFF dies before the watchdog file is recreated, UbuFuzz won't # notice touch_watchdog_file()
def _setup_watchdog(self): # short circuit if we're not using the watchdog if not TWDF.use_watchdog: logger.debug('skipping watchdog setup') return logger.debug('setup watchdog') # setup our watchdog file toucher touch_watchdog_file() # set up the watchdog timeout within the VM and restart the daemon with WatchDog(TWDF.wdf, self.config['runoptions']['watchdogtimeout']) as watchdog: watchdog()
def _setup_watchdog(self): # short circuit if we're not using the watchdog if not TWDF.use_watchdog: logger.debug('skipping watchdog setup') return logger.debug('setup watchdog') # setup our watchdog file toucher touch_watchdog_file() # set up the watchdog timeout within the VM and restart the daemon with WatchDog( TWDF.wdf, self.config['runoptions']['watchdogtimeout']) as watchdog: watchdog()
def _analyze(self, testcase): ''' Loops through all known analyzer_classes for a given testcase :param testcase: ''' for analyzer_class in self.analyzer_classes: touch_watchdog_file() analyzer_instance = analyzer_class(self.cfg, testcase) if analyzer_instance: try: analyzer_instance.go() except AnalyzerEmptyOutputError: logger.warning( 'Unexpected empty output from analyzer_class. Continuing')
def _do_iteration(self, seedfile, range_obj, seednum): # Prevent watchdog from rebooting VM. # If /tmp/fuzzing exists and is stale, the machine will reboot touch_watchdog_file() with LinuxIteration(seedfile=seedfile, seednum=seednum, workdirbase=self.working_dir, outdir=self.outdir, sf_set=self.seedfile_set, uniq_func=self._testcase_is_unique, config=self.config, fuzzer_cls=self.fuzzer_cls, runner_cls=self.runner_cls, ) as iteration: try: iteration() except FuzzerExhaustedError: # Some fuzzers run out of things to do. They should # raise a FuzzerExhaustedError when that happens. logger.info( 'Done with %s, removing from set', seedfile.basename) self.seedfile_set.remove_file(seedfile)
def _do_iteration(self, seedfile, range_obj, seednum): # Prevent watchdog from rebooting VM. # If /tmp/fuzzing exists and is stale, the machine will reboot touch_watchdog_file() with LinuxIteration( seedfile=seedfile, seednum=seednum, workdirbase=self.working_dir, outdir=self.outdir, sf_set=self.seedfile_set, uniq_func=self._testcase_is_unique, config=self.config, fuzzer_cls=self.fuzzer_cls, runner_cls=self.runner_cls, ) as iteration: try: iteration() except FuzzerExhaustedError: # Some fuzzers run out of things to do. They should # raise a FuzzerExhaustedError when that happens. logger.info('Done with %s, removing from set', seedfile.basename) self.seedfile_set.remove_file(seedfile)
def _pre_minimize(self, testcase): touch_watchdog_file()