我目前正在将libFuzzer集成到一个项目中,该项目可以解析硬盘上的文件。我以前有过使用AFL的经验,其中使用的命令行如下所示:
afl-fuzz -m500 -i input/ -o output/ -t100 -- program_to_fuzz @@...where @@是指向生成的输入的路径。然而,看看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*无能为力。
将缓冲区写回硬盘以取回文件似乎效率极低。有什么办法可以解决这个问题吗?
发布于 2018-12-04 20:33:07
您可以使用LD_PRELOAD并覆盖fread。
发布于 2019-01-21 01:46:09
你可以在谷歌安全团队的this example中这样做。buf_to_file定义的here将获取缓冲区并返回一个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函数释放资源。
https://stackoverflow.com/questions/53460028
复制相似问题