Advertisement
teeks99

tk-cs258-4-fuzzer

Oct 16th, 2012
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # 5-line fuzzer below is from Charlie Miller's
  4. # "Babysitting an Army of Monkeys":
  5. # Part 1 - http://www.youtube.com/watch?v=Xnwodi2CBws
  6. # Part 2 - http://www.youtube.com/watch?v=lk5fgCvS2N4
  7.  
  8. # List of files to use as initial seed
  9. file_list=[
  10.     "fuzz_test.kdenlive"
  11.     ]
  12.  
  13. # List of applications to test
  14. apps = [
  15.     "kdenlive"
  16.     ]
  17.  
  18. fuzz_output = "fuzz.kdenlive"
  19.  
  20.  
  21. FuzzFactor = 250
  22. num_tests = 10000
  23.  
  24. ########### end configuration ##########
  25.  
  26. import math
  27. import random
  28. import string
  29. import subprocess
  30. import time
  31.  
  32. failures = 0
  33. dir="/home/tomkent/src/kdenlive"
  34.  
  35.  
  36. for i in range(num_tests):
  37.     file_choice = random.choice(file_list)
  38.     app = random.choice(apps)
  39.  
  40.     buf = bytearray(open(dir + "/" + file_choice, 'rb').read())
  41.    
  42.     # start Charlie Miller code
  43.     numwrites=random.randrange(math.ceil((float(len(buf)) / FuzzFactor)))+1
  44.    
  45.     for j in range(numwrites):
  46.         rbyte = random.randrange(256)
  47.         rn = random.randrange(len(buf))
  48.         buf[rn] = "%c"%(rbyte)
  49.     #end Charlie Miller code
  50.    
  51.     open(dir + "/" + fuzz_output, 'wb').write(buf)
  52.    
  53.     process = subprocess.Popen([app, fuzz_output], cwd=dir)
  54.    
  55.     time.sleep(2)
  56.     crashed = process.poll()
  57.     if crashed:
  58.         # Save the failing file to disk
  59.         failures += 1
  60.         open("fuzz_failure"+str(failures) , 'wb').write(buf)
  61.     else:
  62.         process.terminate()
  63.         process.kill()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement