Fuzz学习笔记(一)—— WinAFL环境搭建与基本使用

环境配置

工具版本链接
windows10
Visual Studio2019https://visualstudio.microsoft.com/zh-hans/vs/
git2.31.0https://gitscm.com/download/win
CMake3.20.0https://cmake.org/files
dynamorioSource Codehttps://github.com/DynamoRIO/dynamorio
winaflSource Codehttps://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目录下创建两个文件夹inout
在这里插入图片描述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目录,这个目录中保存运行异常时的文本信息
在这里插入图片描述在这里插入图片描述
可以直观观察到是由于生成的文本长度过长使程序产生栈溢出而导致崩溃

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值