Skip to content

Instantly share code, notes, and snippets.

@bnagy
Last active September 23, 2015 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bnagy/067bbfb00481da989d47 to your computer and use it in GitHub Desktop.
Save bnagy/067bbfb00481da989d47 to your computer and use it in GitHub Desktop.
afl-consolidate
#! /usr/bin/env ruby
require 'fileutils'
require 'digest/sha1'
def die_usage
fail "Usage: #{$0} /path/to/fuzzing/root /path/to/output [extension]"
end
class Collision < StandardError; end
def shacp fn, dst, extension
hex = Digest::SHA1.hexdigest File.binread(fn)
target = File.join dst, hex
target << extension
if File.file? target
raise Collision
end
FileUtils.cp fn, target
end
if ARGV.size < 2
die_usage
end
unless File.directory? ARGV[0]
warn "Bad directory #{ARGV[0]}"
die_usage
end
begin
FileUtils.mkdir_p ARGV[1]
rescue
warn "Bad output directory #{ARGV[1]}"
die_usage
end
fuzz_root = File.expand_path ARGV[0]
out_dir = File.expand_path ARGV[1]
copied = 0
duplicates = 0
extension = ""
if ARGV[2]
# strip any leading dot from the user extension string - we only want one
extension = '.' << ARGV[2].sub( /^\./, '')
end
fuzzer_dirs = Dir["#{File.join(fuzz_root, '*')}"].select {|e| File.directory? e}
# Make sure this is really an AFL fuzz root. All dirs should have a queue/
# subdirectory
unless fuzzer_dirs.all? {|fd| File.directory? File.join(fd, 'queue') }
warn "No queue dir in #{fd} - aborting."
die_usage
end
fuzzer_dirs.each {|fd|
warn "Processing #{fd}...\n"
# get files from the queue
Dir[File.join(fd, 'queue', '*')].each {|fn|
# This skips dot dirs by default, so we don't have to worry about .state/
next unless File.file? fn
begin
shacp fn, out_dir, extension
copied += 1
rescue Collision
duplicates += 1
rescue
fail "Error while copying #{fn} - #{$!}"
end
}
# Now get all the crash dirs
Dir[File.join(fd, 'crash*')].each {|cd|
next unless File.directory? cd
Dir[File.join(cd, '*')].each {|fn|
next unless File.file? fn
begin
shacp fn, out_dir, extension
copied += 1
rescue Collision
duplicates += 1
rescue
fail "Error while copying #{fn} - #{$!}"
end
}
}
}
warn "#{copied} copied, #{duplicates} duplicates."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment