AFL入门介绍

1、AFL简介

AFL(American Fuzzy Lop)是由安全研究员Michał Zalewski(@lcamtuf)开发的一款基于覆盖引导(Coverage-guided)的模糊测试工具,它通过记录输入样本的代码覆盖率,从而调整输入样本以提高覆盖率,增加发现漏洞的概率。其工作流程大致如下:

①从源码编译程序时进行插桩,以记录代码覆盖率(Code Coverage);

②选择一些输入文件,作为初始测试集加入输入队列(queue);

③将队列中的文件按一定的策略进行“突变”;

④如果经过变异文件更新了覆盖范围,则将其保留添加到队列中;

⑤上述过程会一直循环进行,期间触发了crash的文件会被记录下来。

AFL

2、AFL变异的方式

bitflip:按位翻转,1变为0,0变为1

arithmetic:整数加/减算术运算

interest:把一些特殊内容替换到原文件中

dictionary:把自动生成或用户提供的token替换/插入到原文件中

havoc:“大破坏”,是前面几种变异的组合

splice:“连接”,此阶段会将两个文件拼接起来得到一个新的文件

3、AFL安装和使用

系统:Ubuntu 16.04        AFL:afl-2.52b

下载AFL源码(https://github.com/google/AFL/),解压后,编译安装。
 

make

sudo make install

下面我们进行一个简单的AFL实验了解其使用流程。

3.1准备被测程序

首先创建一个简单的test.c源文件,里面放入我们要测的c程序。

3.2插桩编译

编译过程和普通gcc编译也是一样,除了使用的命令需要带上afl-前缀,因此

afl-gcc -g -o test test.c 

-g选项为使用gdb调试所需,如果不调试就不需加此选项。

3.3准备种子语料库

mkdir fuzz_in fuzz_out
echo '1+1' > fuzz_in/seed

3.4开始测试

执行命令,

afl-fuzz -i fuzz_in -o fuzz_out ./test

命令会报错,

[-] Hmm, your system is configured to send core dump notifications to an
    external utility. This will cause issues: there will be an extended delay
    between stumbling upon a crash and having this information relayed to the
    fuzzer via the standard waitpid() API.

    To avoid having crashes misinterpreted as timeouts, please log in as root
    and temporarily modify /proc/sys/kernel/core_pattern, like so:

    echo core >/proc/sys/kernel/core_pattern

[-] PROGRAM ABORT : Pipe at the beginning of 'core_pattern'
         Location : check_crash_handling(), afl-fuzz.c:7275
[-] Whoops, your system uses on-demand CPU frequency scaling, adjusted
    between 781 and 4003 MHz. Unfortunately, the scaling algorithm in the
    kernel is imperfect and can miss the short-lived processes spawned by
    afl-fuzz. To keep things moving, run these commands as root:

    cd /sys/devices/system/cpu
    echo performance | tee cpu*/cpufreq/scaling_governor

    You can later go back to the original state by replacing 'performance' with
    'ondemand'. If you don't want to change the settings, set AFL_SKIP_CPUFREQ
    to make afl-fuzz skip this check - but expect some performance drop.

[-] PROGRAM ABORT : Suboptimal CPU scaling governor
         Location : check_cpu_governor(), afl-fuzz.c:7337

具体原因上述信息已经提到了,大致就是AFL测试时用到功能需要还没有开启,因此,切换到root用户执行上面报错中给出的命令即可。因为上述命令中修改的都是/proc/sys目录下的文件,二者Linux内核映射出来的逻辑文件,并非实际的磁盘文件,重启之后所有修改都会丢失。

echo core | sudo tee /proc/sys/kernel/core_pattern
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor


再次执行命令,

afl-fuzz -i fuzz_in -o fuzz_out ./test

可以正常运行,输出一段信息后呈现如下界面,表示fuzz已经开始了,可以在该界面中查看运行时间、崩溃数量等信息。

 

ctrl-C结束fuzz,可以看到当前目录下已经多出了fuzz_out目录,这是本次模糊测试的结果。

4、fuzz结果分析

crashes:导致目标接收致命signal而崩溃的独特测试用例queue:存放所有具有独特执行路径的测试用例。AFL输出文件:

crashes/README.txt:保存了目标执行这些crashes文件的命令行参数。

hangs:导致目标超时的独特测试用例。

fuzzer_stats:afl-fuzz的运行状态。

plot_data:用于afl-plot绘图。

 参考文献:

AFL漏洞挖掘技术漫谈(一):用AFL开始你的第一次Fuzzing - FreeBuf网络安全行业门户

AFL-数据变异_baizhi2361的博客-CSDN博客

入门AFL | I'm dev

  • 8
    点赞
  • 54
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值