AFL fuzzing 二进制文件

前言
前一篇文章记录了 AFL fuzzing tcpdump栈溢出漏洞,这里记录下使用AFL fuzzing gcc 编译二进制文件的详细过程以及踩过的坑。

qemu_mode afl fuzzing
基本步骤

//cd到afl源码目录可以看到文件夹qemu_mode
cd qemu_mode
//里面有一个自动构建qemu fuzzing环境的脚本
curits@curits-virtual-machine:~/Desktop/afl-fuzzing/afl-2.52b/qemu_mode$ ls -alh
drwxr-xr-x  5 curits curits 4.0K 1月  19 10:15 .
drwxr-xr-x 11 curits curits 4.0K 1月  19 10:23 ..
-rwxr-xr-x  1 curits curits 4.7K 1月  19 09:56 build_qemu_support.sh
drwxr-xr-x  2 curits curits 4.0K 1月  19 09:55 patches
//执行./build_qemu_support.sh 便可以自动搭建qemu fuzzing 环境
curits@curits-virtual-machine:~/Desktop/afl-fuzzing/afl-2.52b/qemu_mode$./build_qemu_support.sh

现实往往是骨感的,那些个坑记录一下!!!

------------报错1-------------
curits@curits-virtual-machine:~/Desktop/afl-fuzzing/afl-2.52b/qemu_mode$ ./build_qemu_support.sh
=================================================
AFL binary-only instrumentation QEMU build script
=================================================

[*] Performing basic sanity checks...
[-] Error: 'libtool' not found, please install first.

本着缺什么就安装什么的原则,sudo apt-get install libtool,可以安装完成依旧报这个错,据帖子上说安装完libtool还需要安装libtool-bin,sudo apt-get install libtool-bin解决这个报错。

//解决办法
sudo apt-get install libtool
sudo apt-get install libtool-bin
------------报错2-------------
curits@curits-virtual-machine:~/Desktop/afl-fuzzing/afl-2.52b/qemu_mode$ ./build_qemu_support.sh
=================================================
AFL binary-only instrumentation QEMU build script
=================================================

[*] Performing basic sanity checks...
[-] Error: devel version of 'glib2' not found, please install first

网上搜索一番,说使用 sudo apt-get install libgtk2.0-dev可以解决,但是安装时提示有非常多的依赖

curits@curits-virtual-machine:~/Desktop/afl-fuzzing/afl-2.52b/qemu_mode$ sudo apt-get install libgtk2.0-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 gnupg : Breaks: software-properties-common (<= 0.96.24.3) but 0.96.20.8 is to be installed
 libgtk2.0-dev : Depends: libglib2.0-dev (>= 2.27.3) but it is not going to be installed
                 Depends: libgdk-pixbuf2.0-dev (>= 2.21.0) but it is not going to be installed
                 Depends: libpango1.0-dev (>= 1.20) but it is not going to be installed
                 Depends: libatk1.0-dev (>= 1.29.2) but it is not going to be installed
                 Depends: libcairo2-dev (>= 1.6.4-6.1) but it is not going to be installed
                 Recommends: debhelper but it is not going to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

原因是因为packages broken,google一番,解决办法如下:

sudo apt-get install aptitude
sudo aptitude install libgtk2.0-dev
------------报错3-------------
util/memfd.c:40:12: error: static declaration of ‘memfd_create’ follows non-static declaration
 static int memfd_create(const char *name, unsigned int flags)
            ^~~~~~~~~~~~
In file included from /usr/include/i386-linux-gnu/bits/mman-linux.h:115:0,
                 from /usr/include/i386-linux-gnu/bits/mman.h:45,
                 from /usr/include/i386-linux-gnu/sys/mman.h:41,
                 from /home/curits/Desktop/afl-fuzzing/afl-2.52b/qemu_mode/qemu-2.10.0/include/sysemu/os-posix.h:29,
                 from /home/curits/Desktop/afl-fuzzing/afl-2.52b/qemu_mode/qemu-2.10.0/include/qemu/osdep.h:104,
                 from util/memfd.c:28:
/usr/include/i386-linux-gnu/bits/mman-shared.h:46:5: note: previous declaration of ‘memfd_create’ was here
 int memfd_create (const char *__name, unsigned int __flags) __THROW;
     ^~~~~~~~~~~~
/home/curits/Desktop/afl-fuzzing/afl-2.52b/qemu_mode/qemu-2.10.0/rules.mak:66: recipe for target 'util/memfd.o' failed
make: *** [util/memfd.o] Error 1

编译qemu的时候报错,这是因为memfd_create和glibc中的同名函数冲突了,所以需要给安装包打patche;

cd ./qemu_mode/patches
vim memfd_create.diff
//添加以下patche 并保存
diff -ru qemu-2.10.0-clean/util/memfd.c qemu-2.10.0/util/memfd.c
--- qemu-2.10.0-clean/util/memfd.c      2018-11-20 18:11:00.170271506 +0100
+++ qemu-2.10.0/util/memfd.c    2018-11-20 18:11:13.398423613 +0100
@@ -37,7 +37,7 @@
 #include <sys/syscall.h>
 #include <asm/unistd.h>
 
-static int memfd_create(const char *name, unsigned int flags)
+int memfd_create(const char *name, unsigned int flags)
 {
 #ifdef __NR_memfd_create
     return syscall(__NR_memfd_create, name, flags);

//修改 build_qemu_support.sh安装添加的patch
 patch -p1 <../patches/elfload.diff || exit 1
 patch -p1 <../patches/cpu-exec.diff || exit 1
 patch -p1 <../patches/syscall.diff || exit 1
 patch -p1 <../patches/memfd_create.diff || exit 1
 
//重新执行脚本build_qemu_support.sh编译成功
[+] Build process successful!
[*] Copying binary...
-rwxrwxr-x 1 curits curits 8682792 1月  19 09:58 ../afl-qemu-trace
[+] Successfully created '../afl-qemu-trace'.
[*] Testing the build...
[+] Instrumentation tests passed.
[+] All set, you can now use the -Q mode in afl-fuzz!
------------报错4-------------
curits@curits-virtual-machine:~/Desktop/afl-fuzzing/zerotest$ afl-fuzz -i fuzz_in/ -o fuzz_out/ -Q ./vuln
afl-fuzz 2.52b by <lcamtuf@google.com>
[+] You have 2 CPU cores and 2 runnable tasks (utilization: 100%).
[*] Checking CPU core loadout...
[+] Found a free CPU core, binding to #0.
[*] Checking core_pattern...
[*] Setting up output directories...
[+] Output directory exists but deemed OK to reuse.
[*] Deleting old session data...
[+] Output dir cleanup successful.
[*] Scanning 'fuzz_in/'...
[+] No auto-generated dictionary tokens to reuse.
[*] Creating hard links for all input files...
[*] Validating target binary...

[-] Oops, unable to find the 'afl-qemu-trace' binary. The binary must be built
    separately by following the instructions in qemu_mode/README.qemu. If you
    already have the binary installed, you may need to specify AFL_PATH in the
    environment.

    Of course, even without QEMU, afl-fuzz can still work with binaries that are
    instrumented at compile time with afl-gcc. It is also possible to use it as a
    traditional "dumb" fuzzer by specifying '-n' in the command line.

[-] PROGRAM ABORT : Failed to locate 'afl-qemu-trace'.
         Location : get_qemu_argv(), afl-fuzz.c:7669

在对gcc 编译生成的二进制文件进行fuzzing的时候发现无法定位到 ‘afl-qemu-trace’ ,原因是因为脚本只生成可执行文件,并没有进行安装

//解决办法
cd qemu-2.10.0
sudo make install 

成功fuzzing gcc 编译的二进制文件!!!
在这里插入图片描述

参考链接:
https://blog.csdn.net/qq_38081870/article/details/104380070
https://stackoverflow.com/questions/42738525/i-am-trying-to-install-libgtk2-0-dev-on-ubuntu-14-but-getting-some-error
https://blog.csdn.net/liyihao17/article/details/109981662

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
AFL(American Fuzzy Lop)是一款非常受欢迎的模糊测试工具,可以用于发现软件程序中的漏洞和错误。而QEMU是一款开源的虚拟机监控程序,可以模拟不同的系统架构,用于测试和调试。 在进行AFL QEMU测试二进制之前,我们首先需要安装AFL和QEMU这两个工具。安装完成后,我们可以通过以下步骤进行测试: 1. 准备一个待测试的二进制文件,可以是目标软件程序的可执行文件; 2. 使用AFL二进制文件进行处理,将其变成可模糊测试的目标; 3. 设置AFL和QEMU的参数,如模糊测试的目标文件、输入样本和输出文件等; 4. 运行AFL QEMU,开始进行模糊测试。AFL会根据设置的参数,生成各种变异的输入样本,并将其输入到待测试的二进制文件中; 5. QEMU会模拟执行这些输入样本,并监控目标程序的执行过程。它会在发现异常情况时,如程序崩溃或产生错误输出,记录下这些情况; 6. 模糊测试结束后,AFL会生成一个测试报告,包含了发现的漏洞和错误。我们可以根据这些报告,进行漏洞修复或错误修正。 通过AFL QEMU测试二进制,我们可以有效地发现软件程序中的潜在问题,提高程序的安全性和稳定性。同时,由于AFL和QEMU都是开源工具,可以根据需要进行自定义设置和扩展,以满足不同测试需求。总之,AFL QEMU测试二进制是一种非常有效的方法,可以帮助开发人员提升软件质量和性能。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值