2020-04-24 20:22:54 +02:00
|
|
|
{ stdenv, stdenvNoCC, fetchFromGitHub, callPackage, makeWrapper
|
2020-05-16 23:13:56 +02:00
|
|
|
, clang, llvm, gcc, which, libcgroup, python, perl, gmp
|
2020-05-16 23:07:46 +02:00
|
|
|
, file, wine ? null, fetchpatch
|
2019-12-29 02:52:31 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
# wine fuzzing is only known to work for win32 binaries, and using a mixture of
|
|
|
|
# 32 and 64-bit libraries ... complicates things, so it's recommended to build
|
|
|
|
# a full 32bit version of this package if you want to do wine fuzzing
|
|
|
|
assert (wine != null) -> (stdenv.targetPlatform.system == "i686-linux");
|
|
|
|
|
|
|
|
let
|
|
|
|
aflplusplus-qemu = callPackage ./qemu.nix { inherit aflplusplus; };
|
|
|
|
qemu-exe-name = if stdenv.targetPlatform.system == "x86_64-linux" then "qemu-x86_64"
|
|
|
|
else if stdenv.targetPlatform.system == "i686-linux" then "qemu-i386"
|
|
|
|
else throw "aflplusplus: no support for ${stdenv.targetPlatform.system}!";
|
|
|
|
libdislocator = callPackage ./libdislocator.nix { inherit aflplusplus; };
|
|
|
|
libtokencap = callPackage ./libtokencap.nix { inherit aflplusplus; };
|
2020-04-24 20:22:54 +02:00
|
|
|
aflplusplus = stdenvNoCC.mkDerivation rec {
|
2019-12-29 02:52:31 +01:00
|
|
|
pname = "aflplusplus";
|
2020-05-16 23:05:02 +02:00
|
|
|
version = "2.65c";
|
2019-12-29 02:52:31 +01:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
2020-04-24 20:22:54 +02:00
|
|
|
owner = "AFLplusplus";
|
2019-12-29 02:52:31 +01:00
|
|
|
repo = "AFLplusplus";
|
|
|
|
rev = version;
|
2020-05-16 23:05:02 +02:00
|
|
|
sha256 = "1np2a3kypb2m8nyv6qnij18yzn41pl8619jzydci40br4vxial9l";
|
2019-12-29 02:52:31 +01:00
|
|
|
};
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
# Note: libcgroup isn't needed for building, just for the afl-cgroup
|
|
|
|
# script.
|
2020-05-16 23:13:56 +02:00
|
|
|
nativeBuildInputs = [ makeWrapper which clang gcc ];
|
|
|
|
buildInputs = [ llvm python gmp ]
|
2019-12-29 02:52:31 +01:00
|
|
|
++ stdenv.lib.optional (wine != null) python.pkgs.wrapPython;
|
|
|
|
|
2020-04-24 20:22:54 +02:00
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
# Replace the CLANG_BIN variables with the correct path
|
|
|
|
substituteInPlace llvm_mode/afl-clang-fast.c \
|
2020-05-16 23:13:56 +02:00
|
|
|
--replace "CLANGPP_BIN" '"${clang}/bin/clang++"' \
|
|
|
|
--replace "CLANG_BIN" '"${clang}/bin/clang"' \
|
2020-04-24 20:22:54 +02:00
|
|
|
--replace 'getenv("AFL_PATH")' "(getenv(\"AFL_PATH\") ? getenv(\"AFL_PATH\") : \"$out/lib/afl\")"
|
|
|
|
|
|
|
|
# Replace "gcc" and friends with full paths in afl-gcc
|
|
|
|
# Prevents afl-gcc picking up any (possibly incorrect) gcc from the path
|
|
|
|
substituteInPlace src/afl-gcc.c \
|
|
|
|
--replace '"gcc"' '"${gcc}/bin/gcc"' \
|
|
|
|
--replace '"g++"' '"${gcc}/bin/g++"' \
|
|
|
|
--replace '"gcj"' '"gcj-UNSUPPORTED"' \
|
|
|
|
--replace '"clang"' '"clang-UNSUPPORTED"' \
|
|
|
|
--replace '"clang++"' '"clang++-UNSUPPORTED"'
|
|
|
|
'';
|
|
|
|
|
2019-12-29 02:52:31 +01:00
|
|
|
makeFlags = [ "PREFIX=$(out)" ];
|
|
|
|
buildPhase = ''
|
|
|
|
common="$makeFlags -j$NIX_BUILD_CORES"
|
|
|
|
make all $common
|
|
|
|
make radamsa $common
|
|
|
|
make -C gcc_plugin CC=${gcc}/bin/gcc CXX=${gcc}/bin/g++ $common
|
|
|
|
make -C llvm_mode $common
|
|
|
|
make -C qemu_mode/libcompcov $common
|
|
|
|
make -C qemu_mode/unsigaction $common
|
|
|
|
'';
|
|
|
|
|
|
|
|
postInstall = ''
|
2020-04-24 20:22:54 +02:00
|
|
|
# remove afl-clang(++) which are just symlinks to afl-clang-fast
|
|
|
|
rm $out/bin/afl-clang $out/bin/afl-clang++
|
|
|
|
|
2019-12-29 02:52:31 +01:00
|
|
|
# the makefile neglects to install unsigaction
|
|
|
|
cp qemu_mode/unsigaction/unsigaction*.so $out/lib/afl/
|
|
|
|
|
|
|
|
# Install the custom QEMU emulator for binary blob fuzzing.
|
|
|
|
cp ${aflplusplus-qemu}/bin/${qemu-exe-name} $out/bin/afl-qemu-trace
|
|
|
|
|
|
|
|
# give user a convenient way of accessing libcompconv.so, libdislocator.so, libtokencap.so
|
|
|
|
cat > $out/bin/get-afl-qemu-libcompcov-so <<END
|
|
|
|
#!${stdenv.shell}
|
|
|
|
echo $out/lib/afl/libcompcov.so
|
|
|
|
END
|
|
|
|
chmod +x $out/bin/get-afl-qemu-libcompcov-so
|
|
|
|
cp ${libdislocator}/bin/get-libdislocator-so $out/bin/
|
|
|
|
cp ${libtokencap}/bin/get-libtokencap-so $out/bin/
|
|
|
|
|
|
|
|
# Install the cgroups wrapper for asan-based fuzzing.
|
2020-04-24 20:22:54 +02:00
|
|
|
cp examples/asan_cgroups/limit_memory.sh $out/bin/afl-cgroup
|
2019-12-29 02:52:31 +01:00
|
|
|
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"
|
|
|
|
|
|
|
|
patchShebangs $out/bin
|
|
|
|
|
|
|
|
'' + stdenv.lib.optionalString (wine != null) ''
|
|
|
|
substitute afl-wine-trace $out/bin/afl-wine-trace \
|
|
|
|
--replace "qemu_mode/unsigaction" "$out/lib/afl"
|
|
|
|
chmod +x $out/bin/afl-wine-trace
|
|
|
|
|
|
|
|
# qemu needs to be fed ELFs, not wrapper scripts, so we have to cheat a bit if we
|
|
|
|
# detect a wrapped wine
|
|
|
|
for winePath in ${wine}/bin/.wine ${wine}/bin/wine; do
|
|
|
|
if [ -x $winePath ]; then break; fi
|
|
|
|
done
|
|
|
|
makeWrapperArgs="--set-default 'AFL_WINE_PATH' '$winePath'" \
|
|
|
|
wrapPythonProgramsIn $out/bin ${python.pkgs.pefile}
|
|
|
|
'';
|
|
|
|
|
2020-05-16 23:07:46 +02:00
|
|
|
installCheckInputs = [ perl file ];
|
2019-12-29 02:52:31 +01:00
|
|
|
doInstallCheck = true;
|
|
|
|
installCheckPhase = ''
|
|
|
|
# replace references to tools in build directory with references to installed locations
|
|
|
|
substituteInPlace test/test.sh \
|
|
|
|
--replace '../libcompcov.so' '`$out/bin/get-afl-qemu-libcompcov-so`' \
|
|
|
|
--replace '../libdislocator.so' '`$out/bin/get-libdislocator-so`' \
|
|
|
|
--replace '../libtokencap.so' '`$out/bin/get-libtokencap-so`'
|
2020-05-16 23:05:02 +02:00
|
|
|
perl -pi -e 's|(?<!\.)(?<!-I)(\.\./)([^\s\/]+?)(?<!\.c)(?<!\.s?o)(?=\s)|\$out/bin/\2|g' test/test.sh
|
2019-12-29 02:52:31 +01:00
|
|
|
cd test && ./test.sh
|
|
|
|
'';
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit libdislocator libtokencap;
|
|
|
|
qemu = aflplusplus-qemu;
|
|
|
|
};
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = ''
|
2020-10-25 09:29:21 +01:00
|
|
|
A heavily enhanced version of AFL, incorporating many features
|
|
|
|
and improvements from the community
|
2019-12-29 02:52:31 +01:00
|
|
|
'';
|
2020-04-24 20:22:54 +02:00
|
|
|
homepage = "https://aflplus.plus";
|
2019-12-29 02:52:31 +01:00
|
|
|
license = stdenv.lib.licenses.asl20;
|
|
|
|
platforms = ["x86_64-linux" "i686-linux"];
|
2020-04-24 20:22:54 +02:00
|
|
|
maintainers = with stdenv.lib.maintainers; [ ris mindavi ];
|
2019-12-29 02:52:31 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in aflplusplus
|