模糊测试工具American Fuzzy Lop

发表于:2016-5-19 11:28

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:妞妞乌SirSir    来源:51Testing软件测试网采编

  顾名思义, American Fuzzy Lop 是一款用于测试程序安全性的模糊测试工具, 官网简介如下:
  American fuzzy lop is a security-oriented 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 improve the functional coverage for the fuzzed code. The compact synthesized corpora produced by a tool are also useful for seeding other, more labor-or resource-intensive testing regimes down the road.
  简单来说, 这款工具能够在程序运行的时候注入自己的code, 然后自动产生testcase进行模糊测试.
  
官网截图
  AFL 好在哪?
  无需配置, 速度快, 可以应对复杂的程序.
void test(char *buf)
{
int n = 0;
if(buf[0] == 'b') n++;
if(buf[1] == 'a') n++;
if(buf[2] == 'd') n++;
if(buf[3] == '!') n++;
if(n == 4) {
crash();
}
}
  上面的例子中, 需要2^32 或者4百万个尝试才能出发一次崩溃, 这显然效率是很低的. 如果我们一秒钟尝试1000次, 那么出发崩溃所需要的时间就是 2^32/1000/3600/24 = 49 天.
  下面我们来尝试一下用AFL来进行模糊测试.
  首先编写一个目标程序.
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
void test (char *buf) {
int n = 0;
if(buf[0] == 'b') n++;
if(buf[1] == 'a') n++;
if(buf[2] == 'd') n++;
if(buf[3] == '!') n++;
if(n == 4) {
raise(SIGSEGV);
}
}
int main(int argc, char *argv[]) {
char buf[5];
FILE* input = NULL;
input = fopen(argv[1], "r");
if (input != 0) {
fscanf(input, "%4c", &buf);
test(buf);
fclose(my_file):
}
return 0;
}
  然后编译一下
  ./afl-gcc crasher.c -o crash
  因为这个程序是读文件的, 所以我们得给他一个测试用例.
  mkdir testcase
  echo 'jianshu' > testcase/file
  然后开跑!
  ./afl-fuzz -i testcase -o output/ ./crash @@
  
机器截图
  通过 run time - last uniq crash的时间可以看出, afl只用了20秒就将程序crash了. 当然, 这是在实验室机器跑的, 如果是一般的机器的话, 时间可能久一点, 我在自己的Mac上跑的时间是15分钟. 对比起暴力测试方法要用49天, afl对效率的提高不止一点半点.
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号