Skip to content

Instantly share code, notes, and snippets.

@clobrano
Last active December 21, 2015 12:59
Show Gist options
  • Select an option

  • Save clobrano/6309524 to your computer and use it in GitHub Desktop.

Select an option

Save clobrano/6309524 to your computer and use it in GitHub Desktop.
Random test exercise for 'Software test' course at Udacity. Here I apply the Charlie Miller python script to try find bugs in linux software to show photos (Gthumb, F-Spot and Shotwell)
#!/usr/bin/env python
# List of files to use as initial seed
file_list = [
'/home/carlo/Immagini/2013/08/15/IMG_20130815_154000.jpg',
'/home/carlo/Immagini/2013/08/15/IMG_20130815_154023.jpg',
'/home/carlo/Immagini/2013/08/15/IMG_20130815_154029.jpg',
'/home/carlo/Immagini/2013/08/15/PANO_20130815_095210.jpg'
]
# List of applications to test
apps = [
'/usr/bin/shotwell',
'/usr/bin/f-spot',
'/usr/bin/gthumb'
]
fuzz_output = 'fuzz.jpg'
file_output = 'output.log'
FUZZ_FACTOR = 250
NUM_TEST = 10000
############## END CONFIGURATION #############
import math
import random
import string
import subprocess
import time
test_output = open(file_output, 'w')
test_output.write('Configuration: \n')
test_output.write('Fuzz factor: %d, Num tests %d\n' % (FUZZ_FACTOR, NUM_TEST))
test_output.write('Apps:\n')
for app in apps:
test_output.write('\t%s\n' % app)
test_output.write('Files:\n')
for file_choice in file_list:
test_output.write('\t%s\n' % file_choice)
test_output.write('####################\n\n')
for i in range(NUM_TEST):
app = random.choice(apps)
file_choice = random.choice(file_list)
buf = bytearray(open(file_choice, 'rb').read())
# start Charlie Miller code
numwrites=random.randrange(math.ceil((float(len(buf)) / FUZZ_FACTOR)))+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:
test_output.write('SUCCESS test %d: App %s with file %s, NumWrites %d OK\n' %
(i,
app,
file_choice,
numwrites))
process.terminate()
else:
test_output.write('FAIL test %d: App %s with file %s, NumWrites %d crashed!\n' %
(i,
app,
file_choice,
numwrites))
test_output.flush()
test_output.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment