
Ghidralligator 是一款基于 Ghidra libsla 的 C++ 多架构 pcode 模拟器,专为配合 AFL++ 进行模糊测试而设计。
它允许进行基于模拟的模糊测试,同时在处理运行于特殊架构上的二进制文件时保持可观的性能。
其可扩展性使得模拟几乎所有架构都变得容易(只要你能编写相应的 Sleigh 规范文件),从而对任意代码片段进行模糊测试。
Ghidralligator 可在 Linux 系统上运行。仅需要拥有支持 C++17 的 GCC 版本(已在 GCC 12.2.0 上测试并正常工作)。
Ghidra 依赖项已嵌入项目自身的 "./src/" 目录中。
要正确安装 Ghidralligator,你必须按如下方式下载并编译 AFL++:
git clone https://github.com/AFLplusplus/AFLplusplus
cd AFLplusplus
make distrib
sudo make install
git clone https://github.com/airbus-cyber/ghidralligator
cd ghidralligator
make ghidralligator
"./specfiles" 文件夹中找到一组默认的 .sla 文件。Ghidralligator 旨在填补既有模拟器之间的空白:一类模拟器需要大量配置和手动修改才能对二进制文件进行插桩、运行和模糊测试,而另一类“黑盒”模拟器几乎不可扩展,不适合特定且不常见的应用场景。
其主要用途是闭源二进制文件的漏洞研究,尤其是针对运行在特殊架构上的嵌入式设备应用/固件。
Ghidralligator 是 afl_ghidra_emu 的后继者。它大幅提升了执行速度,并包含堆内存损坏检测(ASAN)等实用功能。
可以检测多种内存损坏:越界读/写操作、释放后使用、双重释放、读取未初始化内存、读/写/执行访问违规……
要运行 Ghidralligator,必须完成以下步骤:
为了理解如何使用 Ghidralligator,我们提供了一个在不同架构上编译的易受攻击程序的示例。
你可以运行 run_examples.sh 来实际查看 ASAN 机制。
Ghidralligator 提供多个命令行选项:
usage: ./ghidralligator [OPTION]
-h Print this help and exit.
-m [replay|fuzz] Specify an emulation strategy. [REQUIRED]
In 'replay' mode, the emulator will only launch the program once, exiting after a single loop.
In 'fuzz' mode, this program must be launched through AFL.
-c [FILENAME] Specify the emulator json configuration file to load. [REQUIRED]
-i [FILENAME] Specify a test-case file to insert during a replay session. [OPTIONAL]
-I Display info log (/!\ Slow down the emulation). [OPTIONAL]
-D Display debug and info log (/!\ Slow down the emulation). [OPTIONAL]
-t Store log in ./ghidraligator.log file. [OPTIONAL]
标准模拟的使用方法:
$ ./ghidralligator -m replay -c examples/x86/config.json -I -i examples/x86/input/normal_use_case.bin

标准 AFL++ 模糊测试会话的使用方法:
mkdir afl_inputs afl_outputs
echo -n "AAAAAA" > ./afl_inputs/input.bin
$ AFL_SKIP_BIN_CHECK=1 afl-fuzz -D -i ./afl_inputs -o ./afl_outputs/ -- ./ghidralligator -m fuzz -c examples/x86/config.json

Ghidralligator 可以借助 .sla 文件(Sleigh 指令定义文件)模拟代码。Ghidra 社区提供的 SLA 文件可能只有部分实现。为了获得一致的模拟效果,用户可能需要完善相关的 Sleigh 架构定义或添加一些钩子。
Ghidralligator 基于 Ghidra,而 Ghidra 并非为高性能模拟而设计。因此,在标准架构(x86 Linux / Windows 二进制文件)上,它无法与 afl_qemu 等经典模糊测试器竞争。
由于 Ghidra 项目在不断演进,不建议为未来的 Ghidra 版本手动更新 Ghidralligator 依赖项。该工具是使用 Ghidra 11.0.3 反编译器源码构建和测试的。未来版本可能会导致其失效,且不支持 11.0.3 以下版本的向后兼容性。这对用户来说是透明的,因为 Ghidra 依赖项已包含在本仓库中。
Ghidralligator 根据 Apache 许可证 2.0 版 发布。
Ghidralligator 代码包含来自 NationalSecurityAgency 的 Ghidra 项目的代码,该项目根据 Apache 许可证 2.0 发布。
Ghidralligator 配置文件解析器包含 Niels Lohmann 的 C++ json 库,该库根据 MIT 许可证 发布。
Ghidralligator 模块包含 Yann Collet 的 xxHash 库,该库根据 BSD 2-Clause 许可证 发布。