Last active
May 4, 2020 08:11
-
-
Save RKX1209/c84bc7a7ebe28dbd490b0482554ffeb5 to your computer and use it in GitHub Desktop.
python3 ./tiny_fuzzer.py -i <initial seed>
This file contains 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/python3 | |
import argparse | |
import HTMLParser | |
import io | |
import os | |
import re | |
import shutil | |
import string | |
import subprocess | |
import sys | |
import random | |
cmd_line = "/bin/ls @@" | |
cur_input = "/tmp/cur_input" | |
def run(cmd): | |
print "[*] Just about to run ", cmd | |
proc = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
stdout, stderr = proc.communicate() | |
print "[*] Run complete..\n" | |
return proc.returncode | |
def execute(path): | |
runcmd=cmd_line.replace("@@", path) | |
print(runcmd) | |
run(runcmd) | |
def readinput(path): | |
with open(path, "rb") as fp: | |
data=fp.read() | |
return data | |
def writeinput(path, data): | |
with open(path, "wb") as fp: | |
fp.write(data) | |
def mutate(data): | |
ldata = list(data) | |
pos = random.randrange(len(ldata)) | |
val = random.randrange(256) | |
ldata[pos] = chr(val) | |
return "".join(ldata) | |
def main(): | |
parser = argparse.ArgumentParser(description="Tiny fuzzer") | |
parser.add_argument('-i','--inputd', help='seed input directory',required=True) | |
args = parser.parse_args() | |
files=os.listdir(args.inputd) | |
# for iseed in files: | |
iseed = files[0] | |
path = os.path.abspath(args.inputd + "/" + iseed) | |
os.system("cp %s %s" % (path, cur_input)) | |
while True: | |
res = execute(cur_input) # Execute PUT with the mutated input | |
data = readinput(cur_input) # Read input data from the file | |
newdata = mutate(data) # Mutate input data read from the file | |
writeinput(cur_input, newdata) # Save mutated input data to the file | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment