import errno import os import os.path import sys import time
from driller import Driller
defsave_input(content, dest_dir, count): """Saves a new input to a file where AFL can find it. File will be named id:XXXXXX,driller (where XXXXXX is the current value of count) and placed in dest_dir. """ name = 'id:%06d,driller' % count withopen(os.path.join(dest_dir, name), 'wb') as destfile: destfile.write(content)
# Figure out directories and inputs withopen(os.path.join(fuzzer_dir, 'fuzz_bitmap'), 'rb') as bitmap_file: fuzzer_bitmap = bitmap_file.read() source_dir = os.path.join(fuzzer_dir, 'queue') dest_dir = os.path.join(fuzzer_dir, '..', 'driller', 'queue')
# Make sure destination exists try: os.makedirs(dest_dir) except os.error as e: if e.errno != errno.EEXIST: raise
seen = set() # Keeps track of source files already drilled count = len(os.listdir(dest_dir)) # Helps us name outputs correctly
# Repeat forever in case AFL finds something new whileTrue: # Go through all of the files AFL has generated, but only once each for source_name in os.listdir(source_dir): if source_name in seen ornot source_name.startswith('id:'): continue seen.add(source_name) withopen(os.path.join(source_dir, source_name), 'rb') as seedfile: seed = seedfile.read()
print('Drilling input: %s' % seed) for _, new_input in Driller(binary, seed, fuzzer_bitmap).drill_generator(): save_input(new_input, dest_dir, count) count += 1
# Try a larger input too because Driller won't do it for you seed = seed + b'0000' print('Drilling input: %s' % seed) for _, new_input in Driller(binary, seed, fuzzer_bitmap).drill_generator(): save_input(new_input, dest_dir, count) count += 1 time.sleep(10)
$ cd workdir/output/fuzzer-master/crashes $ ls id:000000,sig:11,sync:driller,src:000016 README.txt $ catid\:000000\,sig\:11\,sync\:driller\,src\:000016 7/42a8