WinAFL学习笔记(一)—— WinAFL环境搭建
环境配置
工具 | 版本 | 链接 |
---|---|---|
windows | 10 | |
Visual Studio | 2019 | https://visualstudio.microsoft.com/zh-hans/vs/ |
git | 2.31.0 | https://gitscm.com/download/win |
CMake | 3.20.0 | https://cmake.org/files |
dynamorio | Source Code | https://github.com/DynamoRIO/dynamorio |
winafl | Source Code | https://github.com/ivanfratric/winafl |
安装步骤
1)安装git
安装步骤:双击运行安装包,一路next即可
注意:安装完后需要手动将git安装路径/usr/bin
添加到环境变量中
2)安装CMake
安装步骤:双击运行安装包,在其中一步需要勾选Add CMake to the system PATH for all users
,其它地方一路next
3)编译dynamorio
编译32位
1)首先找到Virsual Studio文件夹中的vcvarsall.bat所在目录,并打开cmd
2)执行以下命令
>vcvarsall x86
>cd dynamorio源码目录
>mkdir build32 && cd build32
>cmake -G"Visual Studio 16 2019" -A Win32 ..
>cmake --build . --config RelWithDebInfo
编译64位
1)首先找到Virsual Studio文件夹中的vcvarsall.bat所在目录,并打开cmd
2)执行以下命令
>vcvarsall amd64_x86
>cd dynamorio源码目录
>mkdir build64 && cd build64
>cmake -G"Visual Studio 16 2019" -A x64 ..
>cmake --build . --config RelWithDebInfo
4)编译winafl
编译32位
1)首先找到Virsual Studio文件夹中的vcvarsall.bat所在目录,并打开cmd
2)执行以下命令
>vcvarsall x86
>cd winafl源码目录
>mkdir build32 && cd build32
>cmake -G"Visual Studio 16 2019" -A Win32 .. -DDynamoRIO_DIR=dynamorio源码目录\build32\cmake
>cmake --build . --config Release
编译64位
1)首先找到Virsual Studio文件夹中的vcvarsall.bat所在目录,并打开cmd
2)执行以下命令
>vcvarsall amd64_x86
>cd winafl源码目录
>mkdir build64 && cd build64
>cmake -G"Visual Studio 16 2019" -A x64 .. -DDynamoRIO_DIR=dynamorio源码目录\build64\cmake
>cmake --build . --config Release
测试
准备一个测试用例test.exe,代码如下
#include <stdio.h>
#include <windows.h>
int main(int argc, char *argv[])
{
char tmp[30];
char buff[1024];
FILE *fp;
if(argc>=2)
{
fp = fopen(argv[1], "rb");
if(fp == NULL)
{
printf("can not load file!\n");
return 1;
}
fgets(buff, 1024, fp); //读取文件内容
fclose(fp);
strcpy(tmp, buff); //存在栈溢出漏洞
printf("%s\n", tmp);
return 1;
}
return 0;
}//test.exe
准备一个文本文件input.txt,内容如下
abcdefghijklmnopqrstuvwxyz
测试dynamorio
1)检测程序会执行哪些代码块
C:\MyFuzz\dynamorio\build32\bin32\drrun.exe -t drcov -- test.exe
测试结果
2)使用winafl.dll检测模块执行概况
注意:winafl.dll需和test.exe在同一目录
C:\MyFuzz\dynamorio\build32\bin32\drrun.exe -c winafl.dll -debug -target_module test.exe -target_offset 0x12f0 -fuzz_iterations 10 -nargs 2 -- test.exe input.txt
winafl参数说明
-debug //必须为debug模式, 结束后会生成一个log文件
-target_module //目标程序(只能有一个), 也是target_offset所在的模块
-target_offset //目标程序偏移,相对于target_module的偏移,在method无法导出的时候使用
-fuzz_iterations //目标程序重新启动一次内运行目标函数(即target_method)的最大迭代数
-nargs //目标程序执行所需要的参数个数(包括目标程序本身)
-target_module //目标函数,需要export或者调试符号(pdb)
-coverage_module //计算覆盖率的模块,也就是目标程序会调用的模块(dll); (可以有多个)
测试结果
测试winafl
1)在Release目录下创建两个文件夹in和out
2)将input.txt放入in文件夹中
3)afl-fuzz测试
afl-fuzz.exe -i in -o out -D C:\MyFuzz\dynamorio\build32\bin32 -t 20000+ -- -coverage_module ntdll.dll -fuzz_iterations 5000 -target_module test.exe -target_offset 0x12f0 -nargs 2 -- test.exe @@
参数说明
-i //存放样本的目录
-o //保存输出数据,包括 crash文件、测试用例等
-D //DynamoRIO的路径 (drrun, drconfig)
-t msec //每一次样本执行的超时时间
第一个"--"分割符 //后面跟的是插桩的参数
第二个"--"分割符 //后面跟的是目标程序的参数
@@ //引用 -i 参数的中的测试用例
测试结果
各模块含义
Process timing //Fuzzer运行时长、以及距离最近发现的路径、崩溃和挂起经过了多长时间
Overall results //Fuzzer当前状态的概述
Cycle progress //当前Fuzz的进展
Map coverage //目标二进制文件中的插桩代码所观察到覆盖范围的细节
Stage progress //Fuzzer现在正在执行的文件变异策略、执行次数和执行速度
Findings in depth //有关我们找到的执行路径,异常和挂起数量的信息
Fuzzing strategy yields //关于突变策略产生的最新行为和结果的详细信息
Path geometry //有关Fuzzer找到的执行路径的信息
CPU load //CPU利用率
4)查看out目录
重点查看crashes目录,这个目录中保存运行异常时的文本信息
可以直观观察到是由于生成的文本长度过长使程序产生栈溢出而导致崩溃