AFL Fuzzing with ASAN

前言

AFL是使用比较广泛的fuzzing工具,ASAN(AddressSanitizer)是google的一个非常高效的内存错误检测工具,其能够检查出UAF,Heap/Stack buffer overflow, Use after return, Use after scope, Initialization order bugs and Memory leaks。这两者都有基于llvm的版本,所以将这两者相结合效果也是非常好的。

Problem

在用AFL和ASAN来fuzzing heartbleed(教程链接afl-training)的时候出现了一个问题:

1
2
3
Since it seems to be built with ASAN and you have a
restrictive memory limit configured, this is expected; please read
/usr/local/share/doc/afl/notes_for_asan.txt for help

这是因为ASAN工具是跟踪所有内存的,所以理论上可能需要的内存比较大,在32位系统中,最多占用800多MB内存。在64位系统中,ASAN的shadow memory的理论上占用的最大内存是17.5TB和20TB,而一般的电脑并没有这么大的内存,所以可能会使电脑死机。所以AFL会在64位机器运行64位程序的时候,报出这种错误。链接也提供了这种情况的解决方法。

实际上,以上最大内存只是理论上的,一般运行的程序shadow memory所占用的内存并没有这么多,所以第一种解决方法就是使用-m none选项,来忽略此错误:

1
afl-fuzz -i in -o out -m none ./executable

第二种方法就是使用cgroup来限定改程序使用的资源:

1
sudo ~/afl/experimental/asan_cgroups/limit_memory.sh -u usename afl-fuzz -i in -o out -m none ./executable

第二种方法是比较稳妥的方法,并不会对系统造成非常大的影响,因为其限定了程序所使用的内存资源。

引用

  1. AFL: http://lcamtuf.coredump.cx/afl/
  2. ASAN: https://github.com/google/sanitizers/wiki/AddressSanitizer
  3. afl-training: https://github.com/ThalesIgnite/afl-training/tree/master/challenges/heartbleed