Skip to content

Instantly share code, notes, and snippets.

@prusnak
Created August 2, 2015 20:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save prusnak/f750d50f5ffc1246ed59 to your computer and use it in GitHub Desktop.
Save prusnak/f750d50f5ffc1246ed59 to your computer and use it in GitHub Desktop.
Simple Python Fuzzer
def none(): return None
objects = ['none', 'bool', 'int', 'float', 'str', 'list', 'dict', 'tuple', 'set', 'object', 'bytes', 'bytearray']
f = open('/dev/urandom', 'rb')
def choice(a):
i = ord(f.read(1)) % len(a)
return a[i]
cnt_ok = 0
cnt_ex = 0
def fuzz_function(func, param):
global cnt_ok, cnt_ex
try:
print(func, param)
func(param)
print('OK')
cnt_ok += 1
except Exception as ex:
print('Exception:', ex)
cnt_ex +=1
def fuzz_method(obj, method):
fuzz_function(getattr(obj, method), [])
for l in range(1, 7):
for v in objects:
fuzz_function(getattr(obj, method), [eval(v)()] * l)
for v1 in objects:
for v2 in objects:
fuzz_function(getattr(obj, method), [eval(v1)(), eval(v2)()])
def fuzz_object(obj):
methods = dir(obj)
for m in methods:
fuzz_method(obj, m)
for o in objects:
fuzz_object(eval(o)())
print('Cases run:', cnt_ok + cnt_ex)
print('Cases OK: ', cnt_ok)
print('Cases Ex :', cnt_ex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment