def __init__(self): # self.field = [] self.bots = [] self.mutator = Mutator() self.graphics = BotGraphics() self.generateMap() self.graphics.setStat(0, "ITERATION") self.graphics.setStat(2, "MOVE") self.graphics.setStat(4, "LAST BEST") self.stat = Stats()
def finishSetup(self, ign): # we have all the pieces the mutator needs self.mutator = Mutator( self.original_file, self.mutation_types, self.original_file_name, self.factory.tmp_directory) # enter continuous loop self.lc = LoopingCall(self.getNextMutation) self.lc.start(0)
def start(self, command, original_file, timeout, temp_directory, mutation_type): # create the consumers for i in range(self.max_processes): process = Process(target=Executor, args=(timeout, self.q_to, self.q_from)) self.processes.append(process) process.start() # create the thread to get consumer output self.monitor_thread = Thread(target=self.monitor) self.monitor_thread.start() # create the mutator mutator = Mutator(original_file, temp_directory, mutation_type) # print some useful information, and figure out some relative percentages mutator.print_statistics() ten_percent = mutator.total_mutations / 10 percent = 0 for counter, (offset, value_index, value_type, new_file) in enumerate(mutator.createNext()): while not self.q_to.empty(): sleep(.1) # check if we hit a 10% mark if counter % ten_percent == 0: print '%02d%% - %s' % (percent, ctime()) percent += 10 # add the job to the queue self.q_to.put({ 'command': command, 'args': '%s' % new_file, 'offset': offset, 'value_index': value_index, 'value_type': value_type, 'new_file': new_file }) self.stop()
def start(self, command, original_file, timeout, temp_directory, mutation_type): # create the consumers for i in range(self.max_processes): process = Process(target=Executor, args=(timeout, self.q_to, self.q_from)) self.processes.append(process) process.start() # create the thread to get consumer output self.monitor_thread = Thread(target=self.monitor) self.monitor_thread.start() # create the mutator mutator = Mutator(original_file, temp_directory, mutation_type) # print some useful information, and figure out some relative percentages mutator.print_statistics() ten_percent = mutator.total_mutations / 10 percent = 0 for counter, (offset, value_index, value_type, new_file) in enumerate(mutator.createNext()): while not self.q_to.empty(): sleep(0.1) # check if we hit a 10% mark if counter % ten_percent == 0: print "%02d%% - %s" % (percent, ctime()) percent += 10 # add the job to the queue self.q_to.put( { "command": command, "args": "%s" % new_file, "offset": offset, "value_index": value_index, "value_type": value_type, "new_file": new_file, } ) self.stop()
def __init__(self, program, original_file, log_file_name, mutation_type, directory): print 'FuzzerFactory(...) started' self.mutation_generator = MutationGenerator(mutation_type) # create the list of mutations self.mutator = None # to create the files that reportedly cause crashes self.mutations = self.mutation_generator.getValues() self.mutations_range = range(len(self.mutations)) self.file_name = split(original_file)[1] # just the filename self.program = program self.log_file_name = log_file_name # just the name self.directory = directory # directory to save crash causing files self.log_file = None # the opened instance self.contents = None self.contents_range = None self.generator = self.createGenerator() self.clients = [] # list of clients self.crashes = [] # list of crashes self.mutations_executed = 0 # number of mutations executed so far self.paused = False # make sure we can read the original target file try: self.contents = open(original_file, 'rb').read() self.contents_range = range(len(self.contents)) except Exception as e: quit('Unable to open "%s" and read the contents. Error: %s' % (original_file, e)) # make sure we can write to the logfile try: self.log_file = open(self.log_file_name, 'w') except Exception as e: quit('Unable to open logfile "%s". Error: %s' % (self.log_file_name, self.log_file)) # we have all the pieces for the mutator now self.mutator = Mutator(self.contents, self.mutations, self.file_name, self.directory) # a thread to handle user input and print statistics menu_thread = Thread(target=self.menu) menu_thread.start()
def mutate( self ): randVal = uniform( 0 , 1 ) if ( randVal <= GeneticCode.MUTATION_PROBABILITY ): Mutator.mutate( self )
def StartFuzzer(self): # Main fuzzing loop print '[+]', datetime.now().strftime( "%Y:%m:%d::%H:%M:%S"), 'Using debugger : ', self.conf.DEBUGGER popup = PopUpKiller() thread.start_new_thread(popup.POPUpKillerThread, ()) thread.start_new_thread(self.TempDirCleanThread, ()) sleep(1) if self.OpenXMLFormat: print '[+]', datetime.now().strftime( "%Y:%m:%d::%H:%M:%S" ), 'Loading base files in memory from : ', self.conf.open_xml_office_files off = OfficeFileProcessor( UNPACKED_OFFICE_PATH=self.conf.open_xml_office_files, TEMP_PATH=self.conf.fuzztempfolder, oxml=True, PACKED_OFFICE_PATH=self.conf.packed_open_xml_office_files) ALL_DOCS_IN_MEMORY = off.LoadFilesInMemory() if (len(ALL_DOCS_IN_MEMORY)) == 0: print '[+]', datetime.now().strftime( "%Y:%m:%d::%H:%M:%S" ), 'No Open XML files provided as base file @', self.conf.open_xml_office_files exit() mut = Mutator( OpenXML=True, handlers=self.conf.FILE_FORMAT_HANDLERS, files_to_be_fuzzed=self.conf.FILES_TO_BE_FUZZED, no_of_files_to_be_fuzzed=self.conf.NUMBER_OF_FILES_TO_MUTATE, auto_id_file_type=self.conf.AUTO_IDENTIFY_INTERNAL_FILE_FORAMT, all_handlers=self.conf.ALL_MUTATION_SCRIPTS, all_inmem_docs=ALL_DOCS_IN_MEMORY ) # Passing file format handler and type print '[+]', datetime.now().strftime( "%Y:%m:%d::%H:%M:%S"), 'Starting Fuzzing' while 1: self.CurrentTestCaseName = choice(ALL_DOCS_IN_MEMORY.keys( )) # randomly select one office file loaded in memory. fuzzed_office_dict = mut.Mutate( ALL_DOCS_IN_MEMORY[self.CurrentTestCaseName], self.CurrentTestCaseName ) # fuzzed_office_dict only have xml strings in it. off.Pack2OfficeDoc2( self.CurrentTestCaseName, fuzzed_office_dict ) # Packed the fuzzed file back to wordfile. # TODO : One check can be implemented whether the files provided has proper handler application PROG_NAME = self.conf.APP_LIST[self.CurrentTestCaseName.split( '.')[-1]] # Find the program name arg = os.getcwd( ) + '\\' + self.conf.fuzztempfolder + '\\' + self.CurrentTestCaseName # if self.debugger == 'pydbg': dbg = pydbg() dbg.set_callback( EXCEPTION_ACCESS_VIOLATION, self.AccessViolationHandlerPYDBG) # AV handler dbg.set_callback(EXCEPTION_GUARD_PAGE, self.AccessViolationHandlerPYDBG ) # Guard Page AV handler thread.start_new_thread(self.StillRunningPYDBG, (dbg, )) # Killer Thread Started extra_arg = " ".join(self.extra_cmd_arg) dbg.load(PROG_NAME, extra_arg + ' ' + arg, show_window=True) dbg.run() if self.debugger == 'winappdbg': self.extra_cmd_arg = list( self.basic_cmd_arg) # Reset it to basic self.extra_cmd_arg.insert(0, PROG_NAME) self.extra_cmd_arg.insert(len(self.extra_cmd_arg), arg) debug = Debug(self.AccessViolationHandlerWINAPPDBG, bKillOnExit=True) proc = debug.execv(self.extra_cmd_arg) thread.start_new_thread(self.StillRunningWINAPPDBG, (proc, )) debug.loop() sleep(self.conf.FUZZ_LOOP_DELAY) else: print '[+] ' + datetime.now().strftime( "%Y:%m:%d::%H:%M:%S" ) + ' Loading Binary files files in memory from : ', self.conf.binary_office_files off = OfficeFileProcessor( UNPACKED_OFFICE_PATH=self.conf.binary_office_files, TEMP_PATH=self.conf.fuzztempfolder, oxml=False, PACKED_OFFICE_PATH=self.conf.packed_open_xml_office_files) ALL_DOCS_IN_MEMORY = off.LoadFilesInMemory() if (len(ALL_DOCS_IN_MEMORY)) == 0: print '[+]', datetime.now().strftime( "%Y:%m:%d::%H:%M:%S" ), ' No Binary files provided as base file @', self.conf.binary_office_files exit() mut = Mutator( OpenXML=False, handlers=self.conf.FILE_FORMAT_HANDLERS, files_to_be_fuzzed=self.conf.FILES_TO_BE_FUZZED, no_of_files_to_be_fuzzed=self.conf.NUMBER_OF_FILES_TO_MUTATE, auto_id_file_type=self.conf.AUTO_IDENTIFY_INTERNAL_FILE_FORAMT, all_handlers=self.conf.ALL_MUTATION_SCRIPTS, all_inmem_docs=ALL_DOCS_IN_MEMORY) print '[+]', datetime.now().strftime( "%Y:%m:%d::%H:%M:%S"), 'Starting Fuzzing' while 1: #print 'loop start ' self.CurrentTestCaseName = choice(ALL_DOCS_IN_MEMORY.keys( )) # randomly select one office file loaded in memory. fuzzed_office_bin = mut.Mutate( ALL_DOCS_IN_MEMORY[self.CurrentTestCaseName], self.CurrentTestCaseName ) # fuzzed_office_dict only have xml strings in it. off.Pack2OfficeDoc2(self.CurrentTestCaseName, fuzzed_office_bin) PROG_NAME = self.conf.APP_LIST[self.CurrentTestCaseName.split( '.')[-1]] # FInd the program name arg = os.getcwd( ) + '\\' + self.conf.fuzztempfolder + '\\' + self.CurrentTestCaseName # if self.debugger == 'pydbg': dbg = pydbg() dbg.set_callback( EXCEPTION_ACCESS_VIOLATION, self.AccessViolationHandlerPYDBG) # AV handler dbg.set_callback(EXCEPTION_GUARD_PAGE, self.AccessViolationHandlerPYDBG ) # Guard Page AV handler thread.start_new_thread(self.StillRunningPYDBG, (dbg, )) # Killer Thread Started extra_arg = " ".join(self.extra_cmd_arg) dbg.load(PROG_NAME, extra_arg + ' ' + arg, show_window=True) dbg.run() if self.debugger == 'winappdbg': self.extra_cmd_arg = list( self.basic_cmd_arg) # Reset it to basic self.extra_cmd_arg.insert(0, PROG_NAME) # Add progname self.extra_cmd_arg.insert(len(self.extra_cmd_arg), arg) debug = Debug(self.AccessViolationHandlerWINAPPDBG, bKillOnExit=True) proc = debug.execv(self.extra_cmd_arg) thread.start_new_thread(self.StillRunningWINAPPDBG, (proc, )) debug.loop() sleep(self.conf.FUZZ_LOOP_DELAY)
class GameLogic: def __init__(self): # self.field = [] self.bots = [] self.mutator = Mutator() self.graphics = BotGraphics() self.generateMap() self.graphics.setStat(0, "ITERATION") self.graphics.setStat(2, "MOVE") self.graphics.setStat(4, "LAST BEST") self.stat = Stats() #Building map object def generateMap(self): for i in range(WIDTH): line = [] for j in range(HEIGHT): line.append(EMPTY) self.field.append(line) #Add given amount of food randomly to the field def addFood(self, times): for i in range(times): y = random.randint(0, HEIGHT - 1) x = random.randint(0, WIDTH - 1) self.field[x][y] = FOOD self.graphics.setFood(x, y) # Add given amount of poison randomly to the field def addPoison(self, times): for i in range(times): y = random.randint(0, HEIGHT - 1) x = random.randint(0, WIDTH - 1) self.field[x][y] = POISON self.graphics.setPoison(x, y) # Delete all information from square on the map def remove(self, x, y): self.field[x][y] = EMPTY self.graphics.destroy(x, y) def newBots(self): for i in range(BOTS): y = random.randint(0, HEIGHT - 1) x = random.randint(0, WIDTH - 1) self.bots.append(Bot(x, y, i)) self.graphics.newBot(x, y, 0) self.graphics.update() def randomisePositions(self): for bot in self.bots: y = random.randint(0, HEIGHT - 1) x = random.randint(0, WIDTH - 1) bot.setX(x) bot.setY(y) self.graphics.newBot(x, y, 0) self.graphics.update() def Mutate(self): self.bots = self.mutator.mutation(self.bots, 5, 2, 15) self.randomisePositions() def moveBot(self, xi, yi, xf, yf, counter): self.graphics.moveBot(xi, yi, xf, yf, counter) if self.field[xi][yi] == FOOD: self.graphics.setFood(xi, yi) if self.field[xi][yi] == POISON: self.graphics.setPoison(xi, yi) def killBot(self, bot): bot.kill() self.stat.addTop(bot.getIndex()) #Run one round of simulation #If bot doesnt eat enought or eats poison it dies def runRound(self): i = 0 while (i < 50): deads = 0 # print(deads) for bot in self.bots: bot.resetCounter() #bot.resetPointer() while (bot.getCounter() != 0): if bot.getEnergy() == 0: self.killBot(bot) if bot.isAlive(): action = bot.action() self.interpritate(action, bot) self.graphics.setText(bot.getX(), bot.getY(), bot.getEnergy()) if (action > 0 and action <= 8): break else: deads += 1 self.graphics.destroy(bot.getX(), bot.getY()) break if (deads == BOTS): self.graphics.setStat(5, self.stat.getMove()) print("Round is done") break self.stat.addMove() self.graphics.setStat(1, self.stat.getMove()) self.graphics.update() #Bot class returns an action code, which is interprited here def run(self, times): for i in range(0, times): self.runRound() self.Mutate() def interpritate(self, action, bot): if (action > 0 and action <= 8): self.move(action, bot) bot.increasepointer(1) if (action > 8 and action <= 16): self.eat(action, bot) bot.increasepointer(1) if (action > 16 and action <= 24): self.convertPoison(action, bot) bot.increasepointer(1) if (action > 24 and action <= 32): self.scan(action, bot) if (action > 32): self.pointerJump(bot, action) #fOR EACH ACTION CODE THERE ARE INSTRUCTIONS WHAT TO DO def move(self, place, bot): if (place == 1): targX = bot.getX() - 1 targY = bot.getY() - 1 if (tryCordinates(targX, targY)): X = bot.getX() Y = bot.getY() bot.setY(targY) bot.setX(targX) self.moveBot(X, Y, targX, targY, bot.getEnergy()) if (place == 2): targX = bot.getX() targY = bot.getY() - 1 if (tryCordinates(targX, targY)): X = bot.getX() Y = bot.getY() bot.setY(targY) bot.setX(targX) self.moveBot(X, Y, targX, targY, bot.getEnergy()) if (place == 3): targX = bot.getX() + 1 targY = bot.getY() - 1 if (tryCordinates(targX, targY)): X = bot.getX() Y = bot.getY() bot.setY(targY) bot.setX(targX) self.moveBot(X, Y, targX, targY, bot.getEnergy()) if (place == 4): targX = bot.getX() + 1 targY = bot.getY() if (tryCordinates(targX, targY)): X = bot.getX() Y = bot.getY() bot.setY(targY) bot.setX(targX) self.moveBot(X, Y, targX, targY, bot.getEnergy()) if (place == 5): targX = bot.getX() + 1 targY = bot.getY() + 1 if (tryCordinates(targX, targY)): X = bot.getX() Y = bot.getY() bot.setY(targY) bot.setX(targX) self.moveBot(X, Y, targX, targY, bot.getEnergy()) if (place == 6): targX = bot.getX() targY = bot.getY() + 1 if (tryCordinates(targX, targY)): X = bot.getX() Y = bot.getY() bot.setY(targY) bot.setX(targX) self.moveBot(X, Y, targX, targY, bot.getEnergy()) if (place == 7): targX = bot.getX() - 1 targY = bot.getY() + 1 if (tryCordinates(targX, targY)): X = bot.getX() Y = bot.getY() bot.setY(targY) bot.setX(targX) self.moveBot(X, Y, targX, targY, bot.getEnergy()) if (place == 8): targX = bot.getX() - 1 targY = bot.getY() if (tryCordinates(targX, targY)): X = bot.getX() Y = bot.getY() bot.setY(targY) bot.setX(targX) self.moveBot(X, Y, targX, targY, bot.getEnergy()) def pointerJump(self, bot, address): bot.jumpPointer(address) def eat(self, target, bot): if (target == 9): targX = bot.getX() - 1 targY = bot.getY() - 1 try: if (self.field[targX][targY] == FOOD): bot.addEnergy(FOODENERGY) self.remove(targX, targY) if (self.field[targX][targY] == POISON): self.killBot(bot) self.remove(targX, targY) except: pass if (target == 10): targX = bot.getX() targY = bot.getY() - 1 try: if (self.field[targX][targY] == FOOD): bot.addEnergy(FOODENERGY) self.remove(targX, targY) if (self.field[targX][targY] == POISON): self.killBot(bot) self.remove(targX, targY) except: pass if (target == 11): targX = bot.getX() + 1 targY = bot.getY() - 1 try: if (self.field[targX][targY] == FOOD): bot.addEnergy(FOODENERGY) self.remove(targX, targY) if (self.field[targX][targY] == POISON): self.killBot(bot) self.remove(targX, targY) except: pass if (target == 12): targX = bot.getX() + 1 targY = bot.getY() try: if (self.field[targX][targY] == FOOD): bot.addEnergy(FOODENERGY) self.remove(targX, targY) if (self.field[targX][targY] == POISON): self.killBot(bot) self.remove(targX, targY) except: pass if (target == 13): targX = bot.getX() + 1 targY = bot.getY() + 1 try: if (self.field[targX][targY] == FOOD): bot.addEnergy(FOODENERGY) self.remove(targX, targY) if (self.field[targX][targY] == POISON): self.killBot(bot) self.remove(targX, targY) except: pass if (target == 14): targX = bot.getX() targY = bot.getY() + 1 try: if (self.field[targX][targY] == FOOD): bot.addEnergy(FOODENERGY) self.remove(targX, targY) if (self.field[targX][targY] == POISON): self.killBot(bot) self.remove(targX, targY) except: pass if (target == 15): targX = bot.getX() - 1 targY = bot.getY() + 1 try: if (self.field[targX][targY] == FOOD): bot.addEnergy(FOODENERGY) self.remove(targX, targY) if (self.field[targX][targY] == POISON): self.killBot(bot) self.remove(targX, targY) except: pass if (target == 16): targX = bot.getX() - 1 targY = bot.getY() try: if (self.field[targX][targY] == FOOD): bot.addEnergy(FOODENERGY) self.remove(targX, targY) if (self.field[targX][targY] == POISON): self.killBot(bot) self.remove(targX, targY) except: pass def convertPoison(self, target, bot): if (target == 17): targX = bot.getX() - 1 targY = bot.getY() - 1 try: if (self.field[targX][targY] == POISON): bot.addEnergy(FOODENERGY) self.remove(targX, targY) except: pass if (target == 18): targX = bot.getX() targY = bot.getY() - 1 try: if (self.field[targX][targY] == POISON): bot.addEnergy(FOODENERGY) self.remove(targX, targY) except: pass if (target == 19): targX = bot.getX() + 1 targY = bot.getY() - 1 try: if (self.field[targX][targY] == POISON): bot.addEnergy(FOODENERGY) self.remove(targX, targY) except: pass if (target == 20): targX = bot.getX() + 1 targY = bot.getY() try: if (self.field[targX][targY] == POISON): bot.addEnergy(FOODENERGY) self.remove(targX, targY) except: pass if (target == 21): targX = bot.getX() + 1 targY = bot.getY() + 1 try: if (self.field[targX][targY] == POISON): bot.addEnergy(FOODENERGY) self.remove(targX, targY) except: pass if (target == 22): targX = bot.getX() targY = bot.getY() + 1 try: if (self.field[targX][targY] == POISON): bot.addEnergy(FOODENERGY) self.remove(targX, targY) except: pass if (target == 23): targX = bot.getX() - 1 targY = bot.getY() + 1 try: if (self.field[targX][targY] == POISON): bot.addEnergy(FOODENERGY) self.remove(targX, targY) except: pass if (target == 24): targX = bot.getX() - 1 targY = bot.getY() try: if (self.field[targX][targY] == POISON): bot.addEnergy(FOODENERGY) self.remove(targX, targY) except: pass def scan(self, target, bot): if (target == 25): targX = bot.getX() - 1 targY = bot.getY() - 1 if (tryCordinates(targX, targY)): if (self.field[targX][targY] == POISON): bot.increasepointer(2) if (self.field[targX][targY] == FOOD): bot.increasepointer(3) if (self.field[targX][targY] == EMPTY): bot.increasepointer(4) if (self.field[targX][targY] == WALL): bot.increasepointer(5) else: bot.increasepointer(1) if (target == 26): targX = bot.getX() targY = bot.getY() - 1 if (tryCordinates(targX, targY)): if (self.field[targX][targY] == POISON): bot.increasepointer(2) if (self.field[targX][targY] == FOOD): bot.increasepointer(3) if (self.field[targX][targY] == EMPTY): bot.increasepointer(4) if (self.field[targX][targY] == WALL): bot.increasepointer(5) else: bot.increasepointer(1) if (target == 27): targX = bot.getX() + 1 targY = bot.getY() - 1 if (tryCordinates(targX, targY)): if (self.field[targX][targY] == POISON): bot.increasepointer(2) if (self.field[targX][targY] == FOOD): bot.increasepointer(3) if (self.field[targX][targY] == EMPTY): bot.increasepointer(4) if (self.field[targX][targY] == WALL): bot.increasepointer(5) else: bot.increasepointer(1) if (target == 28): targX = bot.getX() + 1 targY = bot.getY() if (tryCordinates(targX, targY)): if (self.field[targX][targY] == POISON): bot.increasepointer(2) if (self.field[targX][targY] == FOOD): bot.increasepointer(3) if (self.field[targX][targY] == EMPTY): bot.increasepointer(4) if (self.field[targX][targY] == WALL): bot.increasepointer(5) else: bot.increasepointer(1) if (target == 29): targX = bot.getX() + 1 targY = bot.getY() + 1 if (tryCordinates(targX, targY)): if (self.field[targX][targY] == POISON): bot.increasepointer(2) if (self.field[targX][targY] == FOOD): bot.increasepointer(3) if (self.field[targX][targY] == EMPTY): bot.increasepointer(4) if (self.field[targX][targY] == WALL): bot.increasepointer(5) else: bot.increasepointer(1) if (target == 30): targX = bot.getX() targY = bot.getY() + 1 if (tryCordinates(targX, targY)): if (self.field[targX][targY] == POISON): bot.increasepointer(2) if (self.field[targX][targY] == FOOD): bot.increasepointer(3) if (self.field[targX][targY] == EMPTY): bot.increasepointer(4) if (self.field[targX][targY] == WALL): bot.increasepointer(5) else: bot.increasepointer(1) if (target == 31): targX = bot.getX() - 1 targY = bot.getY() + 1 if (tryCordinates(targX, targY)): if (self.field[targX][targY] == POISON): bot.increasepointer(2) if (self.field[targX][targY] == FOOD): bot.increasepointer(3) if (self.field[targX][targY] == EMPTY): bot.increasepointer(4) if (self.field[targX][targY] == WALL): bot.increasepointer(5) else: bot.increasepointer(1) if (target == 32): targX = bot.getX() - 1 targY = bot.getY() if (tryCordinates(targX, targY)): if (self.field[targX][targY] == POISON): bot.increasepointer(2) if (self.field[targX][targY] == FOOD): bot.increasepointer(3) if (self.field[targX][targY] == EMPTY): bot.increasepointer(4) if (self.field[targX][targY] == WALL): bot.increasepointer(5) else: bot.increasepointer(1)
class FuzzerClientProtocol(amp.AMP): def __init__(self): self.executor = Executor() self.original_file = None self.original_file_name = None self.mutation_types = None self.program = None self.mutator = None def connectionMade(self): setupDeferreds = [self.getOriginalFile(), self.getProgram(), self.getMutationTypes()] defer.gatherResults(setupDeferreds).addCallback(self.finishSetup).addErrback(stop) def finishSetup(self, ign): # we have all the pieces the mutator needs self.mutator = Mutator( self.original_file, self.mutation_types, self.original_file_name, self.factory.tmp_directory) # enter continuous loop self.lc = LoopingCall(self.getNextMutation) self.lc.start(0) def getNextMutation(self): ''' Ask the server for the next mutation ''' return (self.callRemote(commands.GetNextMutation) # return deferred .addCallback(self.executeNextMutation) .addErrback(stop)) def executeNextMutation(self, mutation): if mutation['stop']: stop("Server said to stop") return False if mutation['pause']: print 'Sever said to pause - sleeping for 60 seconds' sleep(60) return True # create the mutated file new_file_name = self.mutator.createMutatedFile(mutation['offset'], mutation['mutation_index']) # execute it print '(%d,%d)' % (mutation['offset'], mutation['mutation_index']), output = self.executor.execute(self.program, new_file_name) if output: print 'Got output, Offset = %d, Mutation_Index = %d, File = %s' % (mutation['offset'], mutation['mutation_index'], new_file_name) self.callRemote( commands.LogResults, mutation_index=mutation['mutation_index'], offset=mutation['offset'], output=output, filename=new_file_name ) # copy the file - it caused a crash copy("%s"%new_file_name, "%s"%join(self.factory.save_directory, split(new_file_name)[-1])) # remove the file remove("%s"%new_file_name) @defer.inlineCallbacks def getOriginalFile(self): ''' get original file and file name''' response = yield self.callRemote(commands.GetOriginalFile) print '[*] Got original_file :', response['original_file_name'] self.original_file = response['original_file'] self.original_file_name = response['original_file_name'] @defer.inlineCallbacks def getMutationTypes(self): ''' get list of mutations that will be used ''' response = yield self.callRemote(commands.GetMutationTypes) print '[*] Got mutation types' self.mutation_types = response['mutation_types'] @defer.inlineCallbacks def getProgram(self): ''' get target program that will be executed ''' response = yield self.callRemote(commands.GetProgram) print '[*] Got program :', response['program'] self.program = response['program']
def mutate(self): randVal = uniform(0, 1) if (randVal <= GeneticCode.MUTATION_PROBABILITY): Mutator.mutate(self)