Winafl学习笔记
最近在跟师傅们学习Winafl,也去搜集了一些资料,有了一些自己的理解,就此记录一下。
Winafl是一个运行时插桩工具,可以提高crash的捕获率。
同时也有自己的遗传算法,可以根据代码覆盖程度进行Fuzz
下载winafl
https://github.com/ivanfratric/winafl
下载DynamoRio
https://github.com/DynamoRIO/dynamorio/wiki/Downloads
winafl包里包含源码和编译好的,可以直接使用编译好的,也可以自己去编译。
编译winafl的步骤
For a 32-bit build:
mkdir build32
cd build32
cmake .. -DDynamoRIO_DIR=..\path\to\DynamoRIO\cmake
cmake --build . --config Release
For a 64-bit build:
mkdir build64
cd build64
cmake -G"Visual Studio 10 Win64" .. -DDynamoRIO_DIR=..\path\to\DynamoRIO\cmake
cmake --build . --config Release
//DDynamoRIO_DIR是你下载的DynamoRio的路径
要运行winafl只需要winafl本体+DynamoRio,其中DynamoRio用于提供动态插桩的支持。
使用方式在github的说明中已经给出。注意的是要保证被fuzz程序的同目录下存在winafl.dll
对于程序的输入来说,需要在-i选项下给出输入的文件。并且要最后附加@@
如果要fuzz 64位程序,则winafl和DynamoRIO也要指定为64位的,反之亦然。
下面是对官方readme的部分翻译
) Using WinAFL
--------------- Note: If you are using pre-built binaries you'll need to download DynamoRIO
release 6.1.- from https://github.com/DynamoRIO/dynamorio/wiki/Downloads.
If you built WinAFL from source, you can use whatever version of DynamoRIO
you used to build WinAFL. The command line for afl-fuzz on Windows is different than on Linux. Instead of %s [ afl options ] -- [instrumentation options] -- it now looks like this afl-fuzz [afl options] -- [instrumentation options] -- target_cmd_line The followin afl-fuzz options are supported: -i dir - input directory with test cases
-o dir - output directory for fuzzer findings
-D dir - directory containing DynamoRIO binaries (drrun, drconfig)
-t msec - timeout for each run
-f file - location read by the fuzzed program
-M \\ -S id - distributed mode
-x dir - optional fuzzer dictionary Please refer to the original AFL documentation for more info on these flags. The following instrumentation options are used -covtype - the type of coverage being recorded. Supported options are
bb (basic block, default) or edge. -coverage_module - module for which to record coverage. Multiple module flags
are supported. -target_module - module which contains the target function to be fuzzed.
Either -target_method or -target_offset need to be
specified together with this option. -target_method - name of the method to fuzz in persistent mode. A symbol
for the method needs to be exported for this to work.
Otherwise use -target_offset instead. -target_offset - offset of the method to fuzz from the start of the module. -fuzz_iterations - Maximum nuber of iterations for the target function to run
before restarting the target process. -nargs - Number of arguments the fuzzed method takes. This is used
to save/restore the arguments between runs. -debug - Debug mode. Does not try to connect to the server. Outputs
a log file containing loaded modules, opened files and
coverage infrormation. -logdir - specifies in which directory the log file will be written
(only to be used with -debug). In general, you should perform the following steps when fuzzing a new target: . Make sure your target is running correctly without instrumentations. . Open the target binary in WinDbg and locate the function you want to fuzz.
Note the offset of the function from the start of the module. For example, if
you want to fuzz the main function and happen to have symbols around, you can
use the following windbg command: x test!main . Make sure that the target is running correctly under DynamoRIO. For this
purpose you can use the standalone debug mode of WinAFL client which does not
require connecting to afl-fuzz. Make sure you use the drrun.exe and winafl.dll
version which corresponds to your target ( vs. bit). Example command line path\to\DynamoRIO\bin64\drrun.exe -c winafl.dll -debug
-target_module test_gdiplus.exe -target_offset 0x1270 -fuzz_iterations
-nargs -- test_gdiplus.exe input.bmp You should see the output corresponding to your target function being run
times after which the target executable will exit. A .log file should be
created in the current directory. The log file contains useful information
such as the files and modules loaded by the target as well as the dump of AFL
coverage map. In the log you should see pre_fuzz_handler and post_fuzz_handler
being run exactly times as well as your input file being open in each
iteration. Note the list of loaded modules for setting the -coverage_module
flag. Note that you must use the same values for module names as seen in the
log file (case sensitive). . Now you should be ready to fuzz the target. First, make sure that both
afl-fuzz.exe and winafl.dll are in the current directory. As stated earlier,
the command line for afl-fuzz on Windows is afl-fuzz [afl options] -- [instrumentation options] -- target_cmd_line Please refer above for the list of supported AFL and instrumentation options. In AFL options, you must specify the DynamoRIO binaries directory via the new
-D option. You need to match the DynamoRIO and winafl.dll build ( vs. bit)
to the target binary. -t (timeout) option is mandatory for winafl as execution
time can vary significantly under instrumentation so it’s not a good idea to
rely on the auto-determined values. You can use the same winafl options as in step but remember to exclude the
-debug flag and you'll probably want to increase the iteration count. Note that, unlike linux AFL, in WinAFL the default coverage mode is basic
block. This is because in multithreaded (i.e. most real-world) applications
every context switch would be interpreted as new coverage even when no new
coverage actually occured. If you are confident that all your coverage modules
execute only a single thread at a time you can change this by adding
-covtype edge
to your instrumentation flags. As in afl-fuzz on Linux you can replace the input file param of the target
binary with @@ An example command line would look like afl-fuzz.exe -i in -o out -D C:\work\winafl\DynamoRIO\bin64 -t --
-coverage_module gdiplus.dll -coverage_module WindowsCodecs.dll
-fuzz_iterations -target_module test_gdiplus.exe -target_offset 0x1270
-nargs -- test_gdiplus.exe @@ That’s it. Happy fuzzing! Let me know if you find any bugs.
- -i 测试样本的输入目录
- -o fuzz结果的输出目录
- -D DynamoRIO所处的目录
- -t 每次的运行时间
- -f 被fuzz的进程要读取的文件
- -x 可选fuzzer目录
使用说明
- 首先找出要fuzz的函数基于模块的地址偏移
- 要保证程序可以正常的跑在DynamoRIO下面,可以通过WinAFL的独立调试模式来测试这一点。独立调试模式不会使用fuzz部分(使用-debug选项)
- 要想正常运行,必须要保证afl-fuzz.exe和winafl.dll在同一目录下
- afl-fuzz [afl options] -- [instrumentation options] -- target_cmd_line
- -D选项是必须启用的,用于指定DynamoRIO所处的目录
- -t选项也是必须启用的,由于不同的选项导致的执行效率不同。所以-t的时间应该灵活设置。
- 默认是支持多线程的程序记录的。如果是单线程程序可以使用-covtype edge选项
instrumentation options
- -covtype 设置记录方式,为多线程和单线程程序所使用。bb/edge
- -coverage_module 设置要记录的模块,支持多个模块的记录
- -target_module fuzz目标函数所处的模块,必须要设置-target_method或-target_offset
- -target_method 只有有符号表的情况下才能用的方法,根据符号名去搞
- -target_offset 要fuzz函数的相对模块头的偏移
- -fuzz_iterations 目标函数的最大迭代次数
- -nargs 被fuzz的函数有几个参数?
- -debug 不会连接fuzzer部分,只会输出一个日志文件。包含加载的模块、打开的文件和输出报告。
- -logdir 只在-debug下可用,输出的log文件的位置
Winafl学习笔记的更多相关文章
- js学习笔记:webpack基础入门(一)
之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...
- PHP-自定义模板-学习笔记
1. 开始 这几天,看了李炎恢老师的<PHP第二季度视频>中的“章节7:创建TPL自定义模板”,做一个学习笔记,通过绘制架构图.UML类图和思维导图,来对加深理解. 2. 整体架构图 ...
- PHP-会员登录与注册例子解析-学习笔记
1.开始 最近开始学习李炎恢老师的<PHP第二季度视频>中的“章节5:使用OOP注册会员”,做一个学习笔记,通过绘制基本页面流程和UML类图,来对加深理解. 2.基本页面流程 3.通过UM ...
- 2014年暑假c#学习笔记目录
2014年暑假c#学习笔记 一.C#编程基础 1. c#编程基础之枚举 2. c#编程基础之函数可变参数 3. c#编程基础之字符串基础 4. c#编程基础之字符串函数 5.c#编程基础之ref.ou ...
- JAVA GUI编程学习笔记目录
2014年暑假JAVA GUI编程学习笔记目录 1.JAVA之GUI编程概述 2.JAVA之GUI编程布局 3.JAVA之GUI编程Frame窗口 4.JAVA之GUI编程事件监听机制 5.JAVA之 ...
- seaJs学习笔记2 – seaJs组建库的使用
原文地址:seaJs学习笔记2 – seaJs组建库的使用 我觉得学习新东西并不是会使用它就够了的,会使用仅仅代表你看懂了,理解了,二不代表你深入了,彻悟了它的精髓. 所以不断的学习将是源源不断. 最 ...
- CSS学习笔记
CSS学习笔记 2016年12月15日整理 CSS基础 Chapter1 在console输入escape("宋体") ENTER 就会出现unicode编码 显示"%u ...
- HTML学习笔记
HTML学习笔记 2016年12月15日整理 Chapter1 URL(scheme://host.domain:port/path/filename) scheme: 定义因特网服务的类型,常见的为 ...
- DirectX Graphics Infrastructure(DXGI):最佳范例 学习笔记
今天要学习的这篇文章写的算是比较早的了,大概在DX11时代就写好了,当时龙书11版看得很潦草,并没有注意这篇文章,现在看12,觉得是跳不过去的一篇文章,地址如下: https://msdn.micro ...
随机推荐
- 「Vue」程序式路由导航用法
1.button发起点击请求<mt-button type='primary' size='large' plain @click="topdcmt(id)">商品评论 ...
- Cloudstack 虚拟机实例(四)
虚拟机实例 默认的模板并没有被下载 修改全局设置 secstorage.allowed.internal.sites 设置 ,二级存储ISO镜像和模板可以下载,IP网段 重启服务/etc/init. ...
- 科学计算三维可视化---Traits属性的监听
Traits属性的监听 HasTraits对象所有Traits属性都自动支持监听功能,当每个Traits属性发生变化时,HasTraits对象会通知监听此属性的函数 两种监听模式 静态监听 动态监听 ...
- python 远程执行命令、发布文件
最近有个需求,想获取部分服务器上运行了那些应用服务,一台台去看,太费劲了,参考牛人写了此脚本,后期再加上一个前端页面做一些简单的运维维护的工作,凑合着先用着,待完善, 注:此脚本依懒于安装fabric ...
- Elasticsearch技术解析与实战(五)Document解析
1.手动指定document id 一般来说,是从某些其他的系统中,导入一些数据到es时,会采取这种方式,就是使用系统中已有数据的唯一标识,作为es中document的id. PUT /index/t ...
- [转载]strtok函数和strtok_r函数
1.一个应用实例 网络上一个比较经典的例子是将字符串切分,存入结构体中.如,现有结构体 typedef struct person{ char name[25]; char sex[1 ...
- 2016-2017-2 《Java程序设计》第七周学习总结
20155313 2016-2017-2 <Java程序设计>第七周学习总结 第十二章 Lambda 12.1认识Lambda语法 12.1.1Lambda语法概览 在java中引入了La ...
- Linux基础操作-分区概念
开启Linux系统前添加一块大小为20G的SCSI硬盘 开启系统,右击桌面,打开终端 为新加的硬盘分区,一个主分区大小为10G,剩余空间给扩展分区,在扩展分区上划分两个逻辑分区,大小各5G 进入分区工 ...
- OpenCV LIBTIFF_4.0 link errors
以前用Caffe用的好好的,今天重装后居然报了很多这样的错误 /usr/lib/libopencv_highgui.so.' 1> /usr/lib/libopencv_highgui.so.' ...
- NOIP 2016 迟来的满贯
17-03-22,雨 17-03-22,一个特别重要的日子 在这一天,本蒻攻克了NOIP 2016最难的一题,D1T2——天天爱跑步 实现了NOIP 2016的AK! YAYAYAYAYAYAY 自然 ...