【问题标题】:Libfuzzer target for on-disk parsing用于磁盘解析的 Libfuzzer 目标
【发布时间】:2018-11-24 16:15:06
【问题描述】:

我目前正在将libFuzzer 集成到一个解析硬盘驱动器上的文件的项目中。我在 AFL 方面有过一些经验,其中使用了像这样的命令行:

afl-fuzz -m500 -i input/ -o output/ -t100 -- program_to_fuzz @@

...@@ 是生成输入的路径。 然而,看着libFuzzer,我看到模糊目标看起来像这样:

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  DoSomethingInterestingWithMyAPI(Data, Size);
  return 0;  // Non-zero return values are reserved for future use.
}

我了解输入不是以文件的形式提供的,而是作为内存中的缓冲区提供的。问题是我试图模糊测试的程序处理文件并通过fread() 调用获取其数据。在任何时候都不应该将整个输入加载到内存中(在一般情况下,它甚至可能不适合);所以我对const uint8_t* 无能为力。

将缓冲区写回硬盘以取回文件似乎效率极低。有没有办法解决这个问题?

【问题讨论】:

  • 也许tmpfs 上的文件会有所帮助(在 Linux 的情况下——它是一个 RAM 磁盘,因此无需写入底层磁盘,但仍有一些 fs 系统调用开销......)。接下来,您可以mmap 这个文件,然后将memcpy 数据放入其中,但不确定如何正确处理文件大小。

标签: fuzzing libfuzzer


【解决方案1】:

您可以使用 LD_PRELOAD 并覆盖 fread。

【讨论】:

    【解决方案2】:

    您可以像谷歌安全团队的this example 那样做。 定义 here 的 buf_to_file 获取您的缓冲区并返回一个 char* 路径名,然后您可以将其传递给您的目标:
    (来自https://github.com/google/security-research-pocs/blob/master/autofuzz/fuzz_utils.h#L27

    // Write the data provided in buf to a new temporary file. This function is  
    // meant to be called by LLVMFuzzerTestOneInput() for fuzz targets that only  
    // take file names (and not data) as input.  
    //  
    // Return the path of the newly created file or NULL on error. The caller should  
    // eventually free the returned buffer (see delete_file).   
    extern "C" char *buf_to_file(const uint8_t *buf, size_t size);
    

    请务必使用delete_file 函数释放资源。

    【讨论】:

    • 欢迎来到 StackOverFlow!虽然这个答案可能会有所帮助,但指向第三方网站的链接可能会随着时间的推移而失效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-20
    • 1970-01-01
    • 2013-02-04
    • 2018-04-11
    • 2011-04-20
    • 1970-01-01
    • 2018-09-12
    相关资源
    最近更新 更多