AFL(afl-qemu mode)的安装和使用(一)

由于科研的需要,不得不学习一下AFL的使用。先吐槽一句:虽然是很有名的工具,但是竟然安装起来都不能很顺利,真的是太垃圾了!怎么说呢,从学术界到开源,总是能碰到让人很无语,觉得很SB的问题,不得不让人感叹这个世界上大部分人和事都太垃圾,让人只能呵呵。也许也是因为软件系统的复杂度,导致了种种不完美。

参考这里介绍的流程:https://blog.csdn.net/salmonwilliam/article/details/112846864

首先在AFL官网下载:https://lcamtuf.coredump.cx/afl/

Latest source tarball for the tool

下载下来之后解压,然后依次运行:

make
sudo make install

然后按照上面那个博客里的说法:在终端输入afl-后tab,就能看到很多命令。

我们希望使用afl-qemu,那还需要进行以下操作:

cd qemu_mode
./build_qemu_support.sh

如果有些lib没有安装的,会报:[-] Error: 'automake' not found, please install first. 类似于这种的错。这些都比较好说,缺什么安装什么就行了。让人觉得无语的第一点是这个报错:

ERROR: Cannot use 'python', Python 2.6 or later is required.
       Note that Python 3 or later is not yet supported.
       Use --python=/path/to/python to specify a supported Python.

看到这个真的很无语啊……,想到我的anaconda上有python 2.7的,就先activate了2.7的环境,然后再运行就不报这个错了。ps:Use --python=/path/to/python to specify a supported Python. 这种提示有啥用呢,我实在不知道应该在什么地方specify。

把python的问题解决之后,又报了第二个让人无语的错

util/memfd.c:40:12: error: static declaration of ‘memfd_create’ follows non-static declaration

看上面那个教程中也提到了这个报错,想问问,这种事情没有人管的么?真的是太垃圾了。参考了这里的教程:https://blog.csdn.net/liyihao17/article/details/109981662,这个问题就解决了。顺便说一句,像

patch -p1 <../patches/elfload.diff || exit 1
patch -p1 <../patches/cpu-exec.diff || exit 1

在build_qemu_support.sh的131行左右。

然后再运行一遍,又报了第三个让人无语的错

/home/yu/Projects/afl-2.52b/qemu_mode/qemu-2.10.0/linux-user/syscall.c:261:16: error: static declaration of ‘gettid’ follows non-static declaration,心里不禁想问候有些人啊,解决方法按照这里的介绍:

https://blog.csdn.net/geniusle201/article/details/111028697

按理说,加上一个diff文件,将其放在patches文件夹下,然后再改build_qemu_support.sh就可以了,可是问题是,我们在patches目录下,已经有了名为:syscall.diff的文件,如果直接下面这些内容拷到这个文件底部:

--- qemu-2.10.0-clean/linux-user/syscall.c	2020-03-12 18:47:47.898592169 +0100
+++ qemu-2.10.0/linux-user/syscall.c	2020-03-12 19:16:41.563074307 +0100
@@ -34,6 +34,7 @@
 #include <sys/resource.h>
 #include <sys/swap.h>
 #include <linux/capability.h>
+#include <linux/sockios.h> // https://lkml.org/lkml/2019/6/3/988
 #include <sched.h>
 #include <sys/timex.h>
 #ifdef __ia64__
@@ -116,6 +117,8 @@ int __clone2(int (*fn)(void *), void *ch
 #include "qemu.h"

+extern unsigned int afl_forksrv_pid;
+
 #ifndef CLONE_IO
 #define CLONE_IO                0x80000000      /* Clone io context */
 #endif
 
@@ -256,7 +259,9 @@ static type name (type1 arg1,type2 arg2,
 #endif

 #ifdef __NR_gettid
-_syscall0(int, gettid)
+// taken from https://patchwork.kernel.org/patch/10862231/
+#define __NR_sys_gettid __NR_gettid
+_syscall0(int, sys_gettid)
 #else
 /* This is a replacement for the host gettid() and must return a host
    errno. */
@@ -6219,7 +6224,8 @@ static void *clone_func(void *arg)
     cpu = ENV_GET_CPU(env);
     thread_cpu = cpu;
     ts = (TaskState *)cpu->opaque;
-    info->tid = gettid();
+    // taken from https://patchwork.kernel.org/patch/10862231/
+    info->tid = sys_gettid();
     task_settid(ts);
     if (info->child_tidptr)
         put_user_u32(info->tid, info->child_tidptr);
@@ -6363,9 +6369,11 @@ static int do_fork(CPUArchState *env, un
                mapping.  We can't repeat the spinlock hack used above because
                the child process gets its own copy of the lock.  */
             if (flags & CLONE_CHILD_SETTID)
-                put_user_u32(gettid(), child_tidptr);
+                // taken from https://patchwork.kernel.org/patch/10862231/
+                put_user_u32(sys_gettid(), child_tidptr);
             if (flags & CLONE_PARENT_SETTID)
-                put_user_u32(gettid(), parent_tidptr);
+                // taken from https://patchwork.kernel.org/patch/10862231/
+                put_user_u32(sys_gettid(), parent_tidptr);
             ts = (TaskState *)cpu->opaque;
             if (flags & CLONE_SETTLS)
                 cpu_set_tls (env, newtls);
@@ -11402,7 +11410,8 @@ abi_long do_syscall(void *cpu_env, int n
         break;
 #endif
     case TARGET_NR_gettid:
-        ret = get_errno(gettid());
+        // taken from https://patchwork.kernel.org/patch/10862231/
+        ret = get_errno(sys_gettid());
         break;
 #ifdef TARGET_NR_readahead
     case TARGET_NR_readahead:

再运行的时候会报这个错:

Hunk #2 FAILED at 117.
Hunk #3 succeeded at 259 (offset 2 lines).
Hunk #4 succeeded at 6224 (offset 2 lines).
Hunk #5 succeeded at 6369 (offset 2 lines).
Hunk #6 succeeded at 11410 (offset 2 lines).
1 out of 6 hunks FAILED -- saving rejects to file linux-user/syscall.c.rej

看这个是我们刚才加的117行的diff没法用,也没仔细看看细节,尝试把上面这些diff重新放在了一个名为syscall2.diff的文件中,并且在build_qemu_support.sh中加入:

patch -p1 <../patches/syscall2.diff || exit 1

发现还是不行,感觉是两个diff文件冲突了,所以在build_qemu_support.sh文件中把syscall.diff去掉:

patch -p1 <../patches/elfload.diff || exit 1
patch -p1 <../patches/cpu-exec.diff || exit 1
patch -p1 <../patches/syscall2.diff || exit 1
patch -p1 <../patches/memfd_create.diff || exit 1

再运行一遍build_qemu_support.sh,就可以了:

[+] Build process successful!
[*] Copying binary...
-rwxrwxr-x 1 yu yu 10956720 Mar 13 19:33 ../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!

呵呵呵,做完了这些,觉得无力吐槽,虽然AFL已经是很有名的工具了,竟然有这么多弱智的错误,不得不说这个领域真的是太浮躁和让人失望

  • 7
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 15
    评论
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值