Ghidrathon 是一个 Ghidra 扩展,为 Ghidra 添加了 Python 3 脚本功能。为什么?Ghidra 原生支持使用 Java 和 Jython 编写脚本。不幸的是,许多开源分析工具,如 capa、Unicorn Engine、angr 等,都是用 Python 3 编写的,这使得在 Ghidra 中使用这些工具变得困难,在某些情况下甚至不可能。更重要的是,安全社区已经为其他 SRE 框架(如 IDA Pro 和 Binary Ninja)发布了一些优秀的插件,但同样,由于这些插件大多使用 Python 3,因此很难将它们移植到 Ghidra。Ghidrathon 帮助您在 Ghidra 中使用现有的和开发新的 Python 3 工具,并使用现代 Python 编写 Ghidra 脚本,同时与 Ghidra 的用户界面紧密集成。它取代了通过 Jython 实现的现有 Python 2.7 扩展。这包括交互式解释器窗口、与 Ghidra 脚本管理器的集成,以及 Ghidra 无头模式下的脚本执行。

请参阅我们的 Ghidra Python 3 脚本示例 此处,以更详细地了解如何为 Ghidra 编写 Python 3 脚本。
欢迎查看:
请按照以下步骤将 Ghidrathon 安装到您的 Ghidra 环境中:
$ python -m pip install -r requirements.txt
$ python ghidrathon_configure.py <absolute_path_to_ghidra_install_dir>
注意:默认情况下,ghidrathon_configure.py 会尝试将名为 ghidrathon.save 的文件写入 <absolute_path_to_ghidra_install_dir>。您可以在运行 ghidrathon_configure.py 和 Ghidra 之前,通过设置 GHIDRATHON_SAVE_PATH 环境变量来指定该文件的写入路径:
$ export GHIDRATHON_SAVE_PATH="/path/to/custom/dir" # Linux/MacOS
$ set GHIDRATHON_SAVE_PATH="C:\path\to\custom\dir" # Windows
注意:系统可能会提示您设置名为 JAVA_HOME 的环境变量。该变量应引用您为 Ghidra 安装所配置的 JDK 的绝对路径。
.zip)安装到 Ghidra 中:
File > Install Extensions...+ 按钮.zip)OkExtension Version Mismatch 窗口提示,请选择 Install Anyway.zip)解压到 <absolute_path_to_ghidra_install_dir>\Ghidra\Extensions您可以通过使用新的 Python 解释器执行步骤 2,将 Ghidrathon 切换为使用不同的 Python 解释器。
您可以通过在虚拟环境中执行步骤 2,将 Python 虚拟环境与 Ghidrathon 一起使用。要切换到不同的虚拟环境,只需在新的虚拟环境中执行步骤 2。
解释器窗口提供对您的 Python 3 解释器的交互式访问。点击“窗口”并选择“Ghidrathon”以打开解释器窗口。

Ghidrathon 直接与 Ghidra 脚本管理器集成,使您能够在 Ghidra 中创建、编辑和执行 Python 3 脚本。点击“Create New Script”并选择“Python 3”以创建新的 Python 3 脚本。点击“Run Script”或“Run Editors's Script”以执行您的 Python 3 脚本,并在 Ghidra Console 窗口中查看脚本输出。

Ghidrathon 帮助您在 Ghidra 无头模式下执行 Python 3 脚本。执行位于 Ghidra 安装文件夹中的 analyzeHeadless 脚本,指定您的 Python 3 脚本,并在控制台窗口中查看脚本输出。
$ analyzeHeadless C:\Users\wampus example -process example.o -postScript ghidrathon_example.py
[...]
INFO SCRIPT: C:\Users\wampus\.ghidra\.ghidra_10.0.3_PUBLIC\Extensions\Ghidrathon-master\ghidra_scripts\ghidrathon_example.py (HeadlessAnalyzer)
Function _init @ 0x101000: 3 blocks, 8 instructions
Function FUN_00101020 @ 0x101020: 1 blocks, 2 instructions
Function __cxa_finalize @ 0x101040: 1 blocks, 2 instructions
Function printf @ 0x101050: 1 blocks, 2 instructions
Function _start @ 0x101060: 1 blocks, 13 instructions
Function deregister_tm_clones @ 0x101090: 4 blocks, 9 instructions
Function register_tm_clones @ 0x1010c0: 4 blocks, 14 instructions
Function __do_global_dtors_aux @ 0x101100: 5 blocks, 14 instructions
[...]
INFO REPORT: Post-analysis succeeded for file: /example.o (HeadlessAnalyzer)
INFO REPORT: Save succeeded for processed file: /example.o (HeadlessAnalyzer)
有关在无头模式下运行 Ghidra 的更多信息,请查看 <absolute_path_to_ghidra_install_dir>/support/analyzeHeadlessREADME.html。
我们开发 Ghidrathon 的最大动机之一,就是能够在 Ghidra 中使用第三方 Python 3 模块。您可以像在典型的 Python 环境中一样,安装模块并开始在 Ghidra 中使用它。这也适用于您之前安装的模块。例如,我们可以安装并使用 Unicorn 来在 Ghidra 中模拟 ARM 代码。

Ghidrathon 提供的脚本体验与 Ghidra 的 Java 和 Jython 扩展非常相似,包括将 GhidraScript 状态实例变量(例如 currentProgram)和 FlatProgramAPI 方法(例如 findBytes)
在 Python builtins 作用域中提供。这意味着您的代码导入的 所有 Python 模块都可以访问这些变量和方法。Ghidrathon 与 Ghidra 的 Java 和 Jython 扩展略有不同,它将 GhidraScript
状态变量公开为 Python 函数调用,而不是直接访问,例如您的 Python 3 代码必须使用函数调用 currentProgram() 来访问 currentProgram。这一小改动可确保您的 Python 3 代码在执行期间获得正确的 GhidraScript 状态变量。请参阅我们的 Ghidra Python 3 脚本示例 此处,以更详细地了解如何为 Ghidra 编写 Python 3 脚本。
Ghidrathon 使用开源项目 Jep 将您的本地 Python 安装链接到 Ghidra。本质上,您的本地 Python 解释器运行在 Ghidra 内部,可以访问您所有的 Python 包 以及 标准 Ghidra 脚本 API。Ghidrathon 还支持 Python 虚拟环境,帮助您创建、隔离和管理那些您可能只想为 Ghidra 使用而安装的包。由于 Ghidrathon 使用您本地的 Python 安装,您可以控制运行在 Ghidra 内部的 Python 版本和环境。
有关 Jep 如何将 Python 嵌入 Java 的更多信息,请参阅其文档 此处。
Ghidrathon 使用开源库 Jep,它通过 Java 本地接口(JNI)将 Python 嵌入到 JVM 中。Ghidra 开发人员不建议在 Ghidra 中使用 JNI,相关原因请参阅 此处。
| 工具 | 版本 | 来源 |
|---|
| Ghidrathon | >= 4.0.0 | https://github.com/mandiant/Ghidrathon/releases |
| Python | >= 3.8.0 | https://www.python.org/downloads |
| Jep | == 4.2.0 | https://pypi.org/project/jep |
| Ghidra | >= 10.3.2 | https://github.com/NationalSecurityAgency/ghidra/releases |
| Java | >= 17.0.0 | https://adoptium.net/temurin/releases |