Re fuzzing

From dslsdzc/rev-skills · View interactive version

Re fuzzing is an AI agent skill from the GitHub repository dslsdzc/rev-skills. 覆盖率引导模糊测试:AFL++/libFuzzer/honggfuzz、插桩与语料初始化、 afl-fuzz 运行参数、覆盖率(afl-cov)、字典/结构化输入。 触发词:fuzz、模糊测试、AFL、afl-fuzz、libFuzzer、honggfuzz、 覆盖率、corpus、语料、dictionary、挖洞、fuzzing。

How to use this skill

Skill file

覆盖率引导模糊测试(AFL++ / libFuzzer / honggfuzz)

何时使用 / 何时不用

工具准备

所有工具先验证再使用。fuzz 是动态执行,一律在沙箱内跑([[re-analyze/platform-tips]] 最高原则,见 [[re-sandbox]])。

AFL++ —— 覆盖率引导 fuzz 主力

```sh

git clone https://github.com/AFLplusplus/AFLplusplus && cd AFLplusplus

make distrib # 需要 clang/LLVM 工具链

sudo make install

```

clang / LLVM —— libFuzzer 宿主 + ASAN 编译器

libFuzzer —— 库函数 / 单函数 fuzz(随 clang 附带)

```sh

clang -fsanitize=fuzzer -x c /dev/null -o /tmp/fztest && /tmp/fztest -runs=1

```

输出含 INFO: libFuzzer 即 OK(/tmp/fztest 用完可删)

honggfuzz —— 硬件计数器 / 多线程 fuzz 备选

```sh

sudo apt install build-essential binutils-dev libunwind-dev libblocksruntime-dev clang

git clone https://github.com/google/honggfuzz && cd honggfuzz && make

```

afl-cov —— 覆盖率统计(gcov/lcov 前端)

```sh

git clone https://github.com/mrash/afl-cov && cd afl-cov

```

操作步骤

按顺序执行;每步产物(harness 源码、语料目录、fuzz 输出目录)记录路径,供 [[re-crash-triage]] / 报告引用。

  1. 目标与插桩选择:

```sh

CC=afl-clang-fast CXX=afl-clang-fast++ AFL_USE_ASAN=1 ./configure && make

# 简单单文件目标:

afl-clang-fast -fsanitize=address -g -O1 -o target target.c

```

```c

/* fuzz_target.c —— 以 libpng 的 png_read 入口为例 */

#include <stdint.h>

extern int my_parse(const char data, size_t len); / 目标解析入口 */

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {

my_parse((const char *)data, size);

return 0;

}

```

libFuzzer 编译:clang -fsanitize=fuzzer,address -g -O1 -o fuzz_target fuzz_target.c target_lib.c

AFL++ 编译同一 harness:afl-clang-fast -fsanitize=fuzzer,address -o fuzz_target_afl fuzz_target.c(afl-clang-fast 拦截 -fsanitize=fuzzer 并链接自带 driver),运行 afl-fuzz -i in -o out -- ./fuzz_target_afl @@

  1. 语料初始化:

```sh

mkdir in out

# 每个种子是目标可正常解析的最小有效输入(别拿空文件起步)

cp seed_sample.bin in/

afl-cmin -i in -o in_min -- ./target @@ # 去重:只留覆盖不同路径的种子

```

  1. afl-fuzz 运行参数:

```sh

afl-fuzz -i in_min -o out -m none -t 1000+ -x dict.txt -- ./target @@

```

  1. 覆盖率(afl-cov):

```sh

gcc -fprofile-arcs -ftest-coverage -g -O0 -o target_gcov target.c

```

```sh

./afl-cov -d out --live --coverage-cmd "cat AFL_FILE | ./target_gcov" --code-dir .

```

产出在 out/cov/,HTML 报告 out/cov/web/(lcov/genhtml 生成)

  1. 字典 / 结构化输入:

跨域联合

常见坑与陷阱

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.