1 { lib, stdenv, fetchFromGitHub, callPackage, makeWrapper
2 , clang, llvm, which, libcgroup
6 afl-qemu = callPackage ./qemu.nix { inherit afl; };
7 qemu-exe-name = if stdenv.hostPlatform.system == "x86_64-linux" then "qemu-x86_64"
8 else if stdenv.hostPlatform.system == "i686-linux" then "qemu-i386"
9 else throw "afl: no support for ${stdenv.hostPlatform.system}!";
10 afl = stdenv.mkDerivation rec {
14 src = fetchFromGitHub {
18 sha256 = "0fqj3g6ds1f21kxz7m9mc1fspi9r4jg9jcmi60inwxijrc5ncvr6";
20 enableParallelBuilding = true;
22 # Note: libcgroup isn't needed for building, just for the afl-cgroup
24 nativeBuildInputs = [ makeWrapper which llvm.dev ];
25 buildInputs = [ llvm ];
27 makeFlags = [ "PREFIX=$(out)" ];
29 make -C llvm_mode $makeFlags -j$NIX_BUILD_CORES
32 # Install the custom QEMU emulator for binary blob fuzzing.
33 cp ${afl-qemu}/bin/${qemu-exe-name} $out/bin/afl-qemu-trace
35 # Install the cgroups wrapper for asan-based fuzzing.
36 cp experimental/asan_cgroups/limit_memory.sh $out/bin/afl-cgroup
37 chmod +x $out/bin/afl-cgroup
38 substituteInPlace $out/bin/afl-cgroup \
39 --replace "cgcreate" "${libcgroup}/bin/cgcreate" \
40 --replace "cgexec" "${libcgroup}/bin/cgexec" \
41 --replace "cgdelete" "${libcgroup}/bin/cgdelete"
43 # Patch shebangs before wrapping
44 patchShebangs $out/bin
46 # Wrap afl-clang-fast(++) with a *different* AFL_PATH, because it
47 # has totally different semantics in that case(?) - and also set a
48 # proper AFL_CC and AFL_CXX so we don't pick up the wrong one out
50 # first though we need to replace the afl-clang-fast++ symlink with
51 # a real copy to prevent wrapProgram skipping the symlink and confusing
53 rm $out/bin/afl-clang-fast++
54 cp $out/bin/afl-clang-fast $out/bin/afl-clang-fast++
55 for x in $out/bin/afl-clang-fast $out/bin/afl-clang-fast++; do
57 --prefix AFL_PATH : "$out/lib/afl" \
58 --run 'export AFL_CC=''${AFL_CC:-${clang}/bin/clang} AFL_CXX=''${AFL_CXX:-${clang}/bin/clang++}'
62 passthru.qemu = afl-qemu;
65 description = "Powerful fuzzer via genetic algorithms and instrumentation";
67 American fuzzy lop is a fuzzer that employs a novel type of
68 compile-time instrumentation and genetic algorithms to
69 automatically discover clean, interesting test cases that
70 trigger new internal states in the targeted binary. This
71 substantially improves the functional coverage for the fuzzed
72 code. The compact synthesized corpora produced by the tool are
73 also useful for seeding other, more labor or resource-intensive
74 testing regimes down the road.
76 homepage = "https://lcamtuf.coredump.cx/afl/";
77 license = lib.licenses.asl20;
78 platforms = ["x86_64-linux" "i686-linux"];
79 maintainers = with lib.maintainers; [ thoughtpolice ris ];