2018-07-21 02:44:44 +02:00
|
|
|
{ stdenv, fetchurl, callPackage, makeWrapper
|
2017-09-05 21:59:43 +02:00
|
|
|
, clang, llvm, which, libcgroup
|
|
|
|
}:
|
2014-11-25 19:42:53 +01:00
|
|
|
|
2015-03-23 03:57:55 +01:00
|
|
|
let
|
|
|
|
afl-qemu = callPackage ./qemu.nix {};
|
|
|
|
qemu-exe-name = if stdenv.system == "x86_64-linux" then "qemu-x86_64"
|
|
|
|
else if stdenv.system == "i686-linux" then "qemu-i386"
|
|
|
|
else throw "afl: no support for ${stdenv.system}!";
|
|
|
|
in
|
2017-09-05 21:59:43 +02:00
|
|
|
|
2014-11-25 19:42:53 +01:00
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
name = "afl-${version}";
|
2017-11-16 18:11:10 +01:00
|
|
|
version = "2.52b";
|
2014-11-25 19:42:53 +01:00
|
|
|
|
|
|
|
src = fetchurl {
|
|
|
|
url = "http://lcamtuf.coredump.cx/afl/releases/${name}.tgz";
|
2017-11-16 18:11:10 +01:00
|
|
|
sha256 = "0ig0ij4n1pwry5dw1hk4q88801jzzy2cric6y2gd6560j55lnqa3";
|
2014-11-25 19:42:53 +01:00
|
|
|
};
|
|
|
|
|
2015-04-11 13:43:25 +02:00
|
|
|
# Note: libcgroup isn't needed for building, just for the afl-cgroup
|
|
|
|
# script.
|
2018-02-10 08:21:23 +01:00
|
|
|
buildInputs = [ makeWrapper llvm which ];
|
2015-03-23 03:57:55 +01:00
|
|
|
|
2015-04-11 13:43:25 +02:00
|
|
|
buildPhase = ''
|
|
|
|
make PREFIX=$out
|
2015-05-13 13:52:56 +02:00
|
|
|
cd llvm_mode
|
2017-09-05 21:59:43 +02:00
|
|
|
make PREFIX=$out
|
2015-05-13 13:52:56 +02:00
|
|
|
cd ..
|
2015-04-11 13:43:25 +02:00
|
|
|
'';
|
2015-03-23 03:57:55 +01:00
|
|
|
installPhase = ''
|
|
|
|
# Do the normal installation
|
|
|
|
make install PREFIX=$out
|
|
|
|
|
|
|
|
# Install the custom QEMU emulator for binary blob fuzzing.
|
|
|
|
cp ${afl-qemu}/bin/${qemu-exe-name} $out/bin/afl-qemu-trace
|
|
|
|
|
2015-04-11 13:43:25 +02:00
|
|
|
# Install the cgroups wrapper for asan-based fuzzing.
|
|
|
|
cp experimental/asan_cgroups/limit_memory.sh $out/bin/afl-cgroup
|
|
|
|
chmod +x $out/bin/afl-cgroup
|
|
|
|
substituteInPlace $out/bin/afl-cgroup \
|
|
|
|
--replace "cgcreate" "${libcgroup}/bin/cgcreate" \
|
|
|
|
--replace "cgexec" "${libcgroup}/bin/cgexec" \
|
|
|
|
--replace "cgdelete" "${libcgroup}/bin/cgdelete"
|
|
|
|
|
|
|
|
# Patch shebangs before wrapping
|
|
|
|
patchShebangs $out/bin
|
|
|
|
|
2015-04-12 05:00:54 +02:00
|
|
|
# Wrap afl-clang-fast(++) with a *different* AFL_PATH, because it
|
|
|
|
# has totally different semantics in that case(?) - and also set a
|
|
|
|
# proper AFL_CC and AFL_CXX so we don't pick up the wrong one out
|
|
|
|
# of $PATH.
|
|
|
|
for x in $out/bin/afl-clang-fast $out/bin/afl-clang-fast++; do
|
|
|
|
wrapProgram $x \
|
|
|
|
--prefix AFL_PATH : "$out/lib/afl" \
|
2018-02-10 08:21:23 +01:00
|
|
|
--run 'export AFL_CC=''${AFL_CC:-${clang}/bin/clang} AFL_CXX=''${AFL_CXX:-${clang}/bin/clang++}'
|
2015-04-12 05:00:54 +02:00
|
|
|
done
|
2015-03-23 03:57:55 +01:00
|
|
|
'';
|
2014-11-25 19:42:53 +01:00
|
|
|
|
2017-11-16 18:11:10 +01:00
|
|
|
passthru = {
|
|
|
|
qemu = afl-qemu;
|
|
|
|
};
|
|
|
|
|
2014-11-25 19:42:53 +01:00
|
|
|
meta = {
|
|
|
|
description = "Powerful fuzzer via genetic algorithms and instrumentation";
|
|
|
|
longDescription = ''
|
|
|
|
American fuzzy lop is a fuzzer that employs a novel type of
|
|
|
|
compile-time instrumentation and genetic algorithms to
|
|
|
|
automatically discover clean, interesting test cases that
|
|
|
|
trigger new internal states in the targeted binary. This
|
|
|
|
substantially improves the functional coverage for the fuzzed
|
|
|
|
code. The compact synthesized corpora produced by the tool are
|
|
|
|
also useful for seeding other, more labor or resource-intensive
|
|
|
|
testing regimes down the road.
|
|
|
|
'';
|
|
|
|
homepage = "http://lcamtuf.coredump.cx/afl/";
|
|
|
|
license = stdenv.lib.licenses.asl20;
|
2018-02-10 08:37:23 +01:00
|
|
|
platforms = ["x86_64-linux" "i686-linux"];
|
2014-11-25 19:42:53 +01:00
|
|
|
maintainers = [ stdenv.lib.maintainers.thoughtpolice ];
|
|
|
|
};
|
|
|
|
}
|