根据上一篇文章中的分类方法,AFL属于基于变异的测试、灰盒测试和反馈制导测试。

基本组件及运行流程

  • 常规基于路径覆盖反馈制导的Fuzzer的基本组件
    • Seed Selector(种子选择器)
    • Mutator/Generator(编译器/生成器)
    • Monitor/Filter(监视器/过滤器)
    • Program Instrumentor(程序插桩器,插桩:往程序中插入代码)

使用实例

利用下面的test.c程序实际运行AFL。

test.c

#include <stdio.h> 
#include <stdlib.h> 
#include <unistd.h> 
#include <string.h> 
#include <signal.h> 

int vuln(char *str)
{
    int len = strlen(str);
    if(str[0] == \'A\' && len == 66)
    {
        raise(SIGSEGV);
        //如果输入的字符串的首字符为A并且长度为66,则异常退出
    }
    else if(str[0] == \'F\' && len == 6)
    {
        raise(SIGSEGV);
        //如果输入的字符串的首字符为F并且长度为6,则异常退出
    }
    else
    {
        printf("it is good!\n");
    }
    return 0;
}

int main(int argc, char *argv[])
{
    char buf[100]={0};
    gets(buf);//存在栈溢出漏洞
    printf(buf);//存在格式化字符串漏洞
    vuln(buf);

    return 0;
}

安装AFL

git clone https://github.com/mirrorer/afl	//下载AFL
cd afl	//进入下载后的AFL文件夹
make	//编译AFL
sudo make install

对程序进行处理

afl-clang test.c -o test	//对待测试的程序进行插桩
mkdir in out
cd in
touch SEED.txt
cd ..
echo aaa > in/SEED.txt	//将SEED作为初始种子写入in文件夹中的SEED文件中
afl-fuzz -i in -o out -- ./test @@	//执行fuzzing,in表示输入文件夹,out表示输出文件夹,test是插桩编译后的可执行程序
# wait for crashes

运行流程分析

版权声明:本文为Ricardio原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/Ricardio/p/14305460.html