Created
July 9, 2017 21:19
-
-
Save bcoles/f5431856a31cf46d6897f2e77c155534 to your computer and use it in GitHub Desktop.
A Ruby port of Charlie Miller's infamous 5 line Python dumb fuzzer
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/env ruby | |
# | |
# A Ruby port of Charlie Miller's infamous 5 line Python dumb fuzzer | |
# ~ bcoles | |
=begin | |
# Original Python code: | |
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) | |
=end | |
require 'securerandom' | |
infile = '/path/to/in_file' | |
outfile = '/path/to/out_file' | |
data = IO.binread infile | |
fuzz_factor = 250 | |
num_writes = SecureRandom.random_number((data.size / fuzz_factor.to_f).ceil) + 1 | |
new_data = data.dup | |
num_writes.times do | |
position = SecureRandom.random_number data.size | |
new_byte = SecureRandom.random_number 256 | |
new_data.tap { |stream| stream.setbyte position, new_byte } | |
end | |
File.open(outfile, 'w') do |file| | |
file.write new_data | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment