Created
July 22, 2012 17:49
-
-
Save yyl/3160488 to your computer and use it in GitHub Desktop.
fuzzer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!usr/bin/python | |
############ constants | |
apps = ["/Applications/Adobe Reader.app/Contents/MacOS/AdobReader", | |
"/Applications/Preview.app/Contents/MacOS/Preview" | |
] | |
file_list = ["sample1.pdf"] | |
fuzz_output = "fuzzed.pdf" | |
FuzzFactor = 250 | |
num_tests = 10000 | |
############# code | |
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()) | |
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) | |
open(fuzz_output, 'wb').write(buf) | |
process = subprocess.Popen([app, fuzz_output]) | |
time.sleep(4) | |
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