【问题标题】:American Fuzzy Lop fails with a simple exampleAmerican Fuzzy Lop 以一个简单的例子失败了
【发布时间】:2016-03-12 19:03:08
【问题描述】:

我一直在尝试使用 American Fuzzy Lop,但我无法通过这样的简单示例使其工作:

#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;
}

我使用常规 gcc 编译此代码的一个版本,使用 afl-clang 编译另一个版本。然后将 gcc 版本放在输入文件夹中,我这样调用 fuzzer:

afl-fuzz -i input/ -o output/ -m 2G ./a.out @@

但它不起作用。

[*] Attempting dry run with 'id:000000,orig:a.out'...
[*] Spinning up the fork server...

[-] Whoops, the target binary crashed suddenly, before receiving any input
    from the fuzzer! There are several probable explanations:

    - The current memory limit (2.00 GB) is too restrictive, causing the
      target to hit an OOM condition in the dynamic linker. Try bumping up
      the limit with the -m setting in the command line. A simple way confirm
      this diagnosis would be:

      ( ulimit -Sv $[2047 << 10]; /path/to/fuzzed_app )

      Tip: you can use http://jwilk.net/software/recidivm to quickly
      estimate the required amount of virtual memory for the binary.

    - The binary is just buggy and explodes entirely on its own. If so, you
      need to fix the underlying problem or find a better replacement.

    - Less likely, there is a horrible bug in the fuzzer. If other options
      fail, poke <lcamtuf@coredump.cx> for troubleshooting tips.

[-] PROGRAM ABORT : Fork server crashed with signal 6
         Location : init_forkserver(), afl-fuzz.c:2056

我做错了什么?

【问题讨论】:

  • 我不太明白实际传递给程序的参数是什么。
  • AFL 必须有一个规范的代码示例,你可以试试。
  • char name[10]; 可能太短,无法容纳传入的实际参数。使用strncpy(..,..,10) 而不是strcpy
  • 这个想法是在那里有一个溢出。很容易抓到的。我尝试增加数组大小,但结果相同。
  • 不要使用strncpy,因为它不会在溢出情况下终止缓冲区

标签: c gcc american-fuzzy-lop


【解决方案1】:

第一个问题是您将输入作为带有“@@”命令的文件传递给 afl-fuzz,而程序采用命令行参数。 afl 接受来自标准输入或文件的输入。 http://lcamtuf.coredump.cx/afl/README.txt

导致启动崩溃的第二个问题是 afl 为测试用例文件名自动命名:

[*] Attempting dry run with 'id:000000,orig:a.out'...

这足以溢出缓冲区并导致段错误。

【讨论】:

    【解决方案2】:

    要完成 Wintermute 响应,如果您想尝试 AFL 或证明它有效,您可以执行以下操作:

    path 变量是您的 @@ 参数的路径

    char *buff;
    
    if ((buff = malloc(10)) == NULL)
      abort();
    
    if ((fd = fopen(path, "r")) == NULL)
      abort();
    fread(buff, 10, 1, fd);
    
    if (strncmp(buff, "h", 1) == 0)
    {
      if (strncmp(buff, "he", 2) == 0)
      {
        if (strncmp(buff, "hel", 3) == 0)
        {
          if (strncmp(buff, "hell", 4) == 0)
          {
            if (strncmp(buff, "hello", 5) == 0)
            {
              buff[9] = 0; //just to be sure...
              fprintf(stderr, "Nailed it ! input file is %s\n", buff);
              abort();
            }
          }
          else
          {
            abort(); // it should be found quick
          }
        }
      }
    }
    free(buff);
    fclose(fd);
    

    使用abort() 会导致非法指令,AFL 将其视为崩溃。所以在这个例子中,你会遇到多个不同的崩溃。

    【讨论】:

      猜你喜欢
      • 2014-10-27
      • 2021-09-27
      • 2013-09-16
      • 2013-11-22
      • 1970-01-01
      • 2013-10-05
      • 2017-09-29
      • 2019-03-07
      • 1970-01-01
      相关资源
      最近更新 更多