Libfuzzer 提供了两个 API 来开发自定义修改器。
size_t LLVMFuzzerCustomMutator(uint8_t *Data, size_t Size, size_t MaxSize, unsigned int Seed)
size_t LLVMFuzzerCustomCrossOver(const uint8_t *Data1, size_t Size1, const uint8_t *Data2, size_t Size2, uint8_t *Out, size_t MaxOutSize, unsigned int Seed)
这些 API 应该如何使用?模糊器必须是确定性的。我如何确保使用自定义突变器?
最佳答案
您只需要在您的 LLVMFuzzerTestOneInput
旁边实现这些功能。 .
google/fuzzing repository has a tutorial on how to implement structure-aware fuzzing .
此外,您可以从 CustomMutatorTest.cpp 中获得灵感。 , 和 CustomCrossOverTest.cpp , 来自 LLVM 存储库。
The fuzzer is required to be deterministic.
是的,但是在这里您将编写不同的变异函数;突变将在您的
LLVMFuzzerTestOneInput
之前发生叫做。但是,它们也有类似的要求。
如 source code 中所述, 旁边
LLVMFuzzerCustomMutator
, 和 LLVMFuzzerCustomCrossOver
分别:Optional user-provided custom mutator. Mutates raw data in [Data, Data+Size) inplace. Returns the new size, which is not greater than MaxSize. Given the same Seed produces the same mutation.
Optional user-provided custom cross-over function. Combines pieces of Data1 & Data2 together into Out. Returns the new size, which is not greater than MaxOutSize. Should produce the same mutation given the same Seed.
即 两次调用相同的变异函数
Data
和 seed
应该产生相同的结果。最后一件事:您不需要同时实现这两个功能;
LLVMFuzzerCustomMutator
大多数情况下应该足够了。
关于clang - 如何使用 libfuzzers 自定义修改器 API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62706527/