环境
Win11
AMD RyZen-5600H
DynamoRIO-Windows-9.93.19557
VS2022-命令行工具
先下载DynamoRIO文件,注意最好下载最新版,省事的话直接下载编译后的版本
下载后,注意其中cmake文件夹路径,因为接下来的WinAFL编译需要用到
如果自己编译则输入
cmake -G"Visual Studio 17 2022" -A Win32 ..
cmake --build . --config RelWithDebInfo
下载WinAFL,
https://github.com/googleprojectzero/winafl
然后开始编译。注意
编译winafl的位数、用到的DynamoRIO的位数和Fuzz目标程序的位数需要保持统一。
在winafl目录中创建文件夹build64并进入目录,然后根据VS的版本 进行编译,其中需要用到DynamoRIO的cmake文件夹路径。
D:\WinAFL\winafl\build64>cmake -G"Visual Studio 17 2022" -A x64 .. -DDynamoRIO_DIR="D:\dynamorio\DynamoRIO-Windows-9.93.19557\DynamoRIO-Windows-9.93.19557\cmake"
D:\WinAFL\winafl\build64>cmake --build . --config Release
编译好后,验证是否能正常Fuzz。
winafl自带一些测试程序可以帮助我们进行验证。
这里我们选择test_gdiplus.exe程序,其正常运行需要提供一张图片作为输入。
进入编译好的winafl的release文件夹中,然后输入以下命令对目标程序进行插桩
D:\WinAFL\winafl\build64\bin\Release> D:\dynamorio\DynamoRIO-Windows-9.93.19557\DynamoRIO-Windows-9.93.19557\bin64\drrun.exe -c winafl.dll -debug -target_module test_gdiplus.exe -target_offset 0x10b0 -fuzz_iterations 5 -nargs 2 -- test_gdiplus.exe D:\Thunder\BHO\image\waiting\003.bmp
这里踩了个坑:
一定要加debug参数,而且一定要加在 -c winafl.dll后面,不要加在前面。
除此之外,要在winafl目录里打开shell并输入此命令,如果换到DynamoRIO中drrun.exe所在目录下运行命令,那么也会插桩失败。
正常的插桩结果应该是,输入命令后,在当前命令执行目录下生成
afl.test_gdiplus.exe.xxxxxxx.proc.log格式文件,打开后有这样的字段
常见的错误结果是
出现错误的可能原因有很多,需要自己逐个排查。
假设已经可以正常插桩,那么就运行以下命令
.\afl-fuzz.exe -debug -i ./test_gdiplus_input -o ./test_gdiplus_output -D D:\dynamorio\DynamoRIO-Windows-9.93.19557\DynamoRIO-Windows-9.93.19557\bin64\ -t 20000 -- -coverage_module test_gdiplus.dll -coverage_module WindowsCodecs.dll -fuzz_iterations 10 -target_module test_gdiplus.exe -target_offset 0x10e0 -nargs 2 -- test_gdiplus.exe @@
注意以下几点:
1.在powershell中不支持@@,会被识别为非法字符
2.命令格式是
afl-fuzz.exe Winafl 选项 -- 插桩选项 -- 目标程序
其中,WinAFL选项必须有 -i 指定输入,-o 指定输出 -D 指定 DynamoRIO路径,-t 指定超时时间
插桩选项 应包括 -coverage_module 一般是DLL ,可以多个 -fuzz_iterations 次数 -target_module 目标程序 -target_offset 偏移 -nargs 参数个数
注意,第一次对目标程序进行Fuzz时需要加上debug方便如果出错进行错误的排查,确认无误后记得取消debug参数,否则会极大影响运行效率。
中间踩了一个坑,-target_module test_gdiplus.exe 写成了 -target_module .\test_gdiplus.exe,结果一直超时报错。所以根据官方文档,如果目标是一个路径,也应该用双引号包住。
详细请参考
https://github.com/googleprojectzero/winafl/blob/master/readme_dr.md
最终运行结果如下:
对于目标程序所要解析的文件,用 -f 参数即可。