Skip to content

Instantly share code, notes, and snippets.

@dzlab
Created August 26, 2012 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dzlab/3483577 to your computer and use it in GitHub Desktop.
Save dzlab/3483577 to your computer and use it in GitHub Desktop.
A Fuzzer test sccript for randomly testing applications
#!/usr/bin/python
# 5-line fuzzer below is from Charlie Miller's
# "Babysitting an Army of Monkeys":
# Part 1 - http://www.youtube.com/watch?v=Xnwodi2CBws
# Part 2 - http://www.youtube.com/watch?v=lK5fgCvS2N4
# Presentation at http://www.scribd.com/doc/60008912/cmiller-CSW-2010
# List of files to use as initial seed
file_list=[
"War_and_Peace_NT.pdf"
]
# List of applications to test
apps = [
"evince"
]
fuzz_output = "fuzz.pdf"
FuzzFactor = 250
num_tests = 10000
########### end configuration ###########
import math
import random
import string
import subprocess
import time
for i in range(num_tests):
file_choice = random.choice(file_list)
app = random.choice(apps)
buf = bytearray(open(file_choice, 'rb').read())
# start Charlie Miller code
numwrites=random.randrange(math.ceil((float(len(buf)) / FuzzFactor)))+1
for j in range(numwrites):
rbyte = random.randrange(256)
rn = random.randrange(len(buf))
buf[rn] = "%c"%(rbyte)
# end Charlie Miller code
open(fuzz_output, "wb").write(buf)
process = subprocess.Popen([app, fuzz_output])
time.sleep(1)
crashed = process.poll()
if not crashed:
process.terminate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment