AFL的安装和使用(三)——FFmpeg的白盒测试

至于这里是不是白盒测试我也不好说,就是有源码的情况下怎么使用AFL进行插桩和fuzzing,以FFmpeg为例(接上一篇博客:https://blog.csdn.net/qysh123/article/details/114794833

其实这个问题也有很多朋友介绍了,例如:(https://blog.csdn.net/m0_37907383/article/details/105419989),但是我总觉得不是很详细,也有些问题没cover到。

首先,按照这里:https://lcamtuf.coredump.cx/afl/QuickStartGuide.txt

我们只需要在FFmpeg目录下运行:

CC=/path/to/afl-gcc CXX=/path/to/afl-g++ ./configure --disable-shared

然后再make即可。上面这个指令的目的是指定用afl-gcc和afl-g++做为编译器。可是如果我按照上面这么做,以我机子上的目录为例:

CC=/home/yu/Projects/afl-2.52b/afl-gcc CXX=/home/yu/Projects/afl-2.52b/afl-g++ ./configure --disable-shared

可以发现运行以后的输出是:

install prefix            /usr/local
source path               .
C compiler                gcc
C library                 glibc

这明显还是没指定到afl-gcc啊,至少在ubuntu上这样是不行的。说到这里吐槽一个博客文章:https://blog.csdn.net/youkawa/article/details/45696317

虽然很多人收藏评论这篇文章,但我想知道,这篇文章里的第3步的截图是些什么鬼?自己都不看的吗?看了看别人说的instrumentation的过程,也是类似:https://blog.csdn.net/abcdyzhang/article/details/53727221

没办法,想想肯定是这个指令的问题,如果我们在google里输入:afl gcc example,第一个结果是这里:https://fuzzing-project.org/tutorial3.html,这里说的稍微有点区别,我结合我机子上的目录运行一下:

./configure CC=/home/yu/Projects/afl-2.52b/afl-gcc CXX=/home/yu/Projects/afl-2.52b/afl-g++ --disable-shared

结果竟然报错:

Unknown option "CC=/home/yu/Projects/afl-2.52b/afl-gcc".
See ./configure --help for available options.

其实按照别人的介绍,如果想要指定gcc编译器,用./configure CC=/home/yu/Projects/afl-2.52b/afl-gcc 按道理来说是可以的,具体参考这里:https://blog.csdn.net/kingboy100/article/details/53571510/,但是我偏偏就遇到了报错?可能是ubuntu版本的问题吧(我的是Ubuntu 20.04.2 LTS)。

按照这个建议用help看了一下,发现应该改成:

./configure --cc=/home/yu/Projects/afl-2.52b/afl-gcc --cxx=/home/yu/Projects/afl-2.52b/afl-g++ --disable-shared

这样运行了以后发现明显就对了:

install prefix            /usr/local
source path               .
C compiler                /home/yu/Projects/afl-2.52b/afl-gcc
C library                 glibc
ARCH                      x86 (generic)

呵呵呵呵呵,这么多教程,没有一个可以直接用的,我也是无语了!

那么指定好之后就make即可,按照官方的quick start guide:https://lcamtuf.coredump.cx/afl/QuickStartGuide.txt,应该运行:

make clean all

我不知道为什么需要clean,具体可以参考这里:https://blog.csdn.net/electrocrazy/article/details/79348357

不过如果我直接运行上面这个命令,FFmpeg的编译过程就会报:

./ffbuild/pkgconfig_generate.sh: 21: .: Can't open libavfilter/libavfilter.version
make: *** [ffbuild/library.mak:102:libavdevice/libavdevice.pc] 错误 127

这个嘛,谁知道是怎么回事呢,改成依次运行:

make clean
make

经过一段时间等待之后,就编译好了。这时候我们在目录下就有了经过插桩的FFmpeg可执行文件。这时候,和我的上一篇博客类似,运行:

afl-fuzz -m none -i in -o out2 ./ffmpeg -i @@

就可以启动fuzzing了。这里我用out2是因为之前用了out,结果out目录被锁了,不知道为什么。另外,如果没有-m none,会报错:

[-] Whoops, the target binary crashed suddenly, before receiving any input
    from the fuzzer! There are several probable explanations:

    - The current memory limit (50.0 MB) is too restrictive, causing the
      target to hit an OOM condition in the dynamic linker. Try bumping up
      the limit with the -m setting in the command line. A simple way confirm
      this diagnosis would be:

      ( ulimit -Sv $[49 << 10]; /path/to/fuzzed_app )

      Tip: you can use http://jwilk.net/software/recidivm to quickly
      estimate the required amount of virtual memory for the binary.

    - The binary is just buggy and explodes entirely on its own. If so, you
      need to fix the underlying problem or find a better replacement.

    - Less likely, there is a horrible bug in the fuzzer. If other options
      fail, poke <lcamtuf@coredump.cx> for troubleshooting tips.

[-] PROGRAM ABORT : Fork server crashed with signal 11
         Location : init_forkserver(), afl-fuzz.c:2201

呵呵呵,如果所有情况下都是这样,为什么不默认加上-m none呢?具体可以参考这里:https://blog.csdn.net/weixin_48505549/article/details/110945509

总之经过上面的尝试,至少完成了源码插桩和fuzzing启动的过程。这里就先简单总结这么多。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值