Skip to content

Instantly share code, notes, and snippets.

@betaveros
Created April 16, 2019 23:41
Show Gist options
  • Save betaveros/f098aba837e30ee1c4cc9879c58d7687 to your computer and use it in GitHub Desktop.
Save betaveros/f098aba837e30ee1c4cc9879c58d7687 to your computer and use it in GitHub Desktop.
some really sketchy makefile patching to get openssl fuzzing to work
import sys, os, subprocess
def check(msg):
if not input(msg + ' (y/n): ').lower().startswith('y'):
print('Aborting')
sys.exit()
subprocess.run('./config enable-fuzz-libfuzzer -DPEDANTIC enable-asan enable-ubsan no-shared -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=fuzzer-no-link enable-ec_nistp_64_gcc_128 -fno-sanitize=alignment enable-tls1_3 enable-weak-ssl-ciphers enable-rc5 enable-md2 enable-ssl3 enable-ssl3-method enable-nextprotoneg --debug'.split(), env={'CC': 'clang'})
check('Does config look ok?')
with open('Makefile') as infile:
with open('Makefile.new', 'w') as outfile:
active = False
for line in infile:
if line.startswith('CFLAGS='):
newline = line.replace('CFLAGS', 'FUZZ_CFLAGS').replace('fuzzer-no-link', 'fuzzer')
outfile.write(line)
outfile.write(newline)
print(' ' + line, end='')
print('+ ' + newline, end='')
print('=' * 40)
elif line.startswith('BIN_CFLAGS='):
newline = line.replace('BIN_CFLAGS', 'BIN_FUZZ_CFLAGS').replace('(CFLAGS)', '(FUZZ_CFLAGS)')
outfile.write(line)
outfile.write(newline)
print(' ' + line, end='')
print('+ ' + newline, end='')
print('=' * 40)
elif line.startswith('fuzz/'):
outfile.write(line)
if ':' in line:
prefix = line.split(':')[0]
if '-' not in prefix and '.' not in prefix:
active = True
print(' ' + line, end='')
elif active:
if '$(BIN_CFLAGS)' in line:
newline = line.replace('$(BIN_CFLAGS)', '$(BIN_FUZZ_CFLAGS)')
outfile.write(newline)
print('- ' + line, end='')
print('+ ' + newline, end='')
print('=' * 40)
active = False
else:
outfile.write(line)
print(' ' + line, end='')
else:
outfile.write(line)
check('Does Makefile.new look ok?')
os.rename('Makefile.new', 'Makefile')
subprocess.run('make')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment