2021-01-15 10:19:50 +01:00
|
|
|
{ lib, stdenv, fetchFromGitHub, 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
|
2018-12-02 17:26:31 +01:00
|
|
|
afl-qemu = callPackage ./qemu.nix { inherit afl; };
|
2018-08-20 21:11:29 +02:00
|
|
|
qemu-exe-name = if stdenv.hostPlatform.system == "x86_64-linux" then "qemu-x86_64"
|
|
|
|
else if stdenv.hostPlatform.system == "i686-linux" then "qemu-i386"
|
|
|
|
else throw "afl: no support for ${stdenv.hostPlatform.system}!";
|
2018-12-02 17:26:31 +01:00
|
|
|
afl = stdenv.mkDerivation rec {
|
2019-08-15 14:41:18 +02:00
|
|
|
pname = "afl";
|
2020-07-02 03:05:31 +02:00
|
|
|
version = "2.57b";
|
2017-09-05 21:59:43 +02:00
|
|
|
|
2019-12-21 14:50:23 +01:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "google";
|
|
|
|
repo = pname;
|
|
|
|
rev = "v${version}";
|
2020-07-02 03:05:31 +02:00
|
|
|
sha256 = "0fqj3g6ds1f21kxz7m9mc1fspi9r4jg9jcmi60inwxijrc5ncvr6";
|
2018-12-02 17:26:31 +01:00
|
|
|
};
|
2019-01-05 16:58:51 +01:00
|
|
|
enableParallelBuilding = true;
|
2014-11-25 19:42:53 +01:00
|
|
|
|
2018-12-02 17:26:31 +01:00
|
|
|
# Note: libcgroup isn't needed for building, just for the afl-cgroup
|
|
|
|
# script.
|
2021-05-07 23:53:48 +02:00
|
|
|
nativeBuildInputs = [ makeWrapper which llvm.dev ];
|
2019-01-05 16:58:51 +01:00
|
|
|
buildInputs = [ llvm ];
|
2014-11-25 19:42:53 +01:00
|
|
|
|
2019-01-05 16:58:51 +01:00
|
|
|
makeFlags = [ "PREFIX=$(out)" ];
|
|
|
|
postBuild = ''
|
|
|
|
make -C llvm_mode $makeFlags -j$NIX_BUILD_CORES
|
2018-12-02 17:26:31 +01:00
|
|
|
'';
|
2019-01-05 16:58:51 +01:00
|
|
|
postInstall = ''
|
2018-12-02 17:26:31 +01:00
|
|
|
# Install the custom QEMU emulator for binary blob fuzzing.
|
|
|
|
cp ${afl-qemu}/bin/${qemu-exe-name} $out/bin/afl-qemu-trace
|
2015-03-23 03:57:55 +01:00
|
|
|
|
2018-12-02 17:26:31 +01: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"
|
2015-03-23 03:57:55 +01:00
|
|
|
|
2018-12-02 17:26:31 +01:00
|
|
|
# Patch shebangs before wrapping
|
|
|
|
patchShebangs $out/bin
|
2015-04-11 13:43:25 +02:00
|
|
|
|
2018-12-02 17:26:31 +01: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.
|
2020-04-19 00:18:41 +02:00
|
|
|
# first though we need to replace the afl-clang-fast++ symlink with
|
|
|
|
# a real copy to prevent wrapProgram skipping the symlink and confusing
|
|
|
|
# nix's cc wrapper
|
|
|
|
rm $out/bin/afl-clang-fast++
|
|
|
|
cp $out/bin/afl-clang-fast $out/bin/afl-clang-fast++
|
2018-12-02 17:26:31 +01:00
|
|
|
for x in $out/bin/afl-clang-fast $out/bin/afl-clang-fast++; do
|
|
|
|
wrapProgram $x \
|
|
|
|
--prefix AFL_PATH : "$out/lib/afl" \
|
|
|
|
--run 'export AFL_CC=''${AFL_CC:-${clang}/bin/clang} AFL_CXX=''${AFL_CXX:-${clang}/bin/clang++}'
|
|
|
|
done
|
|
|
|
'';
|
2015-04-11 13:43:25 +02:00
|
|
|
|
2019-01-05 16:58:51 +01:00
|
|
|
passthru.qemu = afl-qemu;
|
2014-11-25 19:42:53 +01:00
|
|
|
|
2018-12-02 17:26:31 +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.
|
|
|
|
'';
|
2020-04-24 16:52:00 +02:00
|
|
|
homepage = "https://lcamtuf.coredump.cx/afl/";
|
2021-01-15 10:19:50 +01:00
|
|
|
license = lib.licenses.asl20;
|
2018-12-02 17:26:31 +01:00
|
|
|
platforms = ["x86_64-linux" "i686-linux"];
|
2021-01-15 10:19:50 +01:00
|
|
|
maintainers = with lib.maintainers; [ thoughtpolice ris ];
|
2018-12-02 17:26:31 +01:00
|
|
|
};
|
2017-11-16 18:11:10 +01:00
|
|
|
};
|
2018-12-02 17:26:31 +01:00
|
|
|
in afl
|