0

我是第一次尝试 AFL,因此我发现了一个非常简单的易受攻击的 C 代码,我可以用它来测试 AFL。

问题中的C代码是

#include <stdio.h>
#include <string.h>

int main(int argc, char * argv[]){
        char name[10];

        if ( argc > 1 ){
                strcpy(name, argv[1]);
                printf("HELLO %s\n", name);
        }

        return 0;
}

我通过运行编译该代码afl-gcc test.c -o test并对其进行了测试,以确保它在假设的情况下崩溃(运行./test $(python3 -c "print('A'*26)")将按预期给出分段错误)

这里的问题是,我创建了一个测试用例echo -en "test\x00" > input/testcase并运行 AFL afl-fuzz -i afl_in -o afl_out -- ./test,但一天后它仍然没有发现任何崩溃。

我还尝试创建一个会强制它崩溃的测试用例,python3 -c "print('A'*26)" > input/testcase但它仍然运行并且没有找到任何东西。

这被认为是最简单的例子,所以我可以更好地了解 AFL,但事实证明这是一个挑战。任何人都可以帮忙吗?

4

1 回答 1

1

正如尼克奥德尔在评论中发布的那样

似乎 AFL 期望被测程序从 STDIN 读取而不是参数。github.com/google/AFL#6-fuzzing-binaries

该 URL 之后显示了一个实验模块,该模块允许 AFL 从参数中读取,为此我只需在现有代码中添加 2 行:

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "argv-fuzz-inl.h" // <-- Argv fuzz module


int main(int argc, char * argv[]){
        AFL_INIT_ARGV(); // <-- needed near the very beginning of main().
        char name[10];

        if ( argc > 1 ){
                strcpy(name, argv[1]);
                printf("HELLO %s\n", name);
        }

        return 0;
}

之后我再次编译它,一切都按预期工作。

于 2021-09-19T14:02:07.720 回答