kronflux/TetraMCP

GitHub: kronflux/TetraMCP

一个为 Ghidra 提供统一 MCP 服务器的插件,使兼容 MCP 的 AI 客户端能够作为逆向工程助手直接分析二进制程序。

Stars: 1 | Forks: 0

[![许可证](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) [![GitHub 最新发布](https://img.shields.io/github/v/release/kronflux/TetraMCP)](https://github.com/kronflux/TetraMCP/releases) [![GitHub Stars](https://img.shields.io/github/stars/kronflux/TetraMCP)](https://github.com/kronflux/TetraMCP/stargazers) [![GitHub Forks](https://img.shields.io/github/forks/kronflux/TetraMCP)](https://github.com/kronflux/TetraMCP/network/members) [![GitHub Contributors](https://img.shields.io/github/contributors/kronflux/TetraMCP)](https://github.com/kronflux/TetraMCP/graphs/contributors) ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/kronflux/TetraMCP/build.yml) # Ghidra 的 TetraMCP TetraMCP 是一个为 [Ghidra](https://ghidra-sre.org/) 提供的统一 [Model Context Protocol](https://modelcontextprotocol.io/) (MCP) 服务器,为 AI agent 提供直接访问逆向工程的能力。 TetraMCP 扩展了 Ghidra 的三个核心视角——十六进制、反汇编和调试——并增加了第四个视角:通过 MCP 交付的 LLM 认知层。其结果是一个单一的 Ghidra 扩展,可将任何兼容 MCP 的 AI 客户端转变为逆向工程助手。

TetraMCP

## 概述 TetraMCP 集成了几个关键组件: 1. **原生 MCP 服务器**:通过内嵌的 Jetty 服务器直接在 Ghidra 内运行。无需 Python 桥接或外部进程;它通过 Streamable HTTP 进行通信。 2. **全面的工具集**:在 25 个类别中公开了 120 多种工具,涵盖了从反编译和内存分析到 P-code 仿真以及 AI 增强重命名的所有内容。 3. **AI 集成层**:为 LLM(Anthropic、OpenAI 或兼容 API)提供可选的内置支持,以在分析上下文中自动执行函数解释、变量重命名和注释等任务。 4. **多程序架构**:通过隔离的状态管理,支持对多个打开的二进制文件进行同时分析。 此架构使 AI 助手能够: - 以低级精度反编译、反汇编和分析二进制代码。 - 执行加密常数检测和签名匹配。 - 利用 P-code 仿真进行动态行为检查。 - 使用多 agent 系统的共享上下文模型协作完成复杂的逆向任务。 - 通过集成的 AI 自动执行繁琐的重命名和文档编写任务。 ## 功能 TetraMCP 提供了一套全面的逆向工程功能,按逻辑类别组织如下: ### 高级程序分析 - **反编译与反汇编**:高保真度的 C 语言反编译和汇编列表,支持大函数的分页显示。 - **控制流**:生成控制流图 (CFG) 和调用图,以理解程序逻辑。 - **数据流**:通过 P-code SSA 执行向前/向后数据流追踪。 - **交叉引用**:查询指向或来自地址、函数和数据符号的引用。 ### AI 增强功能 - **自动重命名**:利用 LLM 根据上下文为函数和变量建议有意义的名称。 - **代码解释**:生成函数摘要并直接将其保存为 plate 注释。 - **逐行注释**:自动向反编译代码添加详细注释。 - **基于日志的分析**:从调试日志调用中自动恢复函数名。 ### 丰富的工具集 - **加密检测**:使用嵌入式签名数据库扫描已知常数(AES、SHA、MD5 等)。 - **P-code 仿真**:单步执行代码、检查寄存器并修改内存状态。 - **外部工具**:与 `binwalk`、`YARA` 以及专业的 Go 二进制分析集成。 - **多 Agent 协作**:为复杂的工作流提供共享发现、任务队列和进度跟踪。 # 安装说明 ## 前置条件 - [Ghidra](https://ghidra-sre.org/)(12.0.4 或更高版本) - JDK 21 ## Ghidra 插件安装 首先,下载最新版本的 ZIP 压缩包或从源代码构建(见下文)。然后,将插件添加到 Ghidra: 1. 运行 Ghidra 2. 选择 `File` -> `Install Extensions` 3. 点击 `+` 按钮 4. 选择 `TetraMCP-[version].zip` 文件 5. 重启 Ghidra 6. 在 CodeBrowser 中打开一个二进制文件 7. 导航到 `File` -> `Configure`(插头图标) -> `Developer` 8. 勾选 **TetraMcpPlugin** 以启用它 # 客户端配置 TetraMCP 可与任何支持 **Streamable HTTP 传输**的兼容 MCP 的客户端配合使用。 ### Claude Desktop 配置 将以下内容添加到您的 `claude_desktop_config.json` 中: - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json` - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json` ``` { "mcpServers": { "tetramcp": { "type": "http", "url": "http://localhost:18489/mcp" } } } ``` ### Claude Code 配置 运行以下命令以添加服务器: ``` claude mcp add tetramcp --transport http http://localhost:18489/mcp ``` ### Cursor 配置 在您的项目根目录下创建或编辑 `.cursor/mcp.json`: ``` { "mcpServers": { "tetramcp": { "url": "http://localhost:18489/mcp" } } } ``` ## API 参考 TetraMCP 将 120 多个工具组织到逻辑命名空间中。 ### 程序和实例管理 - `program_info`:程序元数据(名称、架构、编译器、哈希)。 - `instances_list`:列出打开的程序。 - `instances_use`:切换活动的程序上下文。 ### 函数分析 - `functions_decompile`:带分页的 C 语言反编译。 - `functions_disassemble`:汇编列表。 - `functions_rename`:重命名函数。 - `functions_find_undefined`:发现未定义的代码。 ### 内存和数据 - `memory_read`:带 ASCII 的十六进制转储。 - `memory_search_bytes`:带通配符的模式搜索。 - `data_list_strings`:列出带有正则表达式过滤的字符串。 - `structs_create` / `structs_update_field`:管理数据结构。 ### 分析和 AI - `analysis_callgraph`:生成调用图。 - `analysis_cfg`:控制流图。 - `ai_suggest_renames`:由 LLM 驱动的重命名建议。 - `ai_explain_function`:自动生成函数摘要。 ### 仿真 - `emulation_create`:启动 P-code 仿真器。 - `emulation_step`:单步执行。 - `emulation_get_state`:检查寄存器和内存。 ### 多 Agent - `agents_add_finding`:记录分析发现。 - `agents_get_next_task`:协调工作流任务。 ## 会话示例 以下是 AI 助手如何使用 TetraMCP 与 Ghidra 交互的示例: **用户:** ``` Find the main function, explain what it does, and check for any cryptographic constants. ``` **助手:** ``` I'll start by locating the main function and analyzing it. [Uses functions_list with filter "main"] Found 'main' at address 0x00401000. [Uses functions_decompile for 'main'] Retrieved decompiled code. The function initializes a socket and encrypts data before sending. [Uses ai_explain_function for 'main'] LLM Explanation: This function serves as the entry point for the network handler. It allocates a buffer, initializes a cryptographic context, and enters a loop to process incoming data packets. [Uses crypto_scan on the current program] Cryptographic constants detected: - AES S-Box at 0x00402000 - SHA-256 IV at 0x00402100 I have added a plate comment to 'main' with the generated explanation and identified the crypto constants used. ``` **用户:** ``` Rename the buffer variable in main to 'packet_buffer' and check cross-references to the AES S-Box. ``` **助手:** ``` [Uses variables_rename in function 'main' old_name 'buffer' new_name 'packet_buffer'] Variable renamed successfully. [Uses xrefs_to address 0x00402000] Found 2 references to the AES S-Box: - encrypt_data (0x00401150) - decrypt_data (0x00401230) The cryptographic functions have been identified. Would you like me to analyze the 'encrypt_data' function next? ``` # 配置 服务器和 AI 设置在 Ghidra 中的 **Edit > Tool Options** 下进行配置。 ### 服务器设置 (TetraMCP) | 设置 | 默认值 | 描述 | |---------|---------|-------------| | 服务器主机 | `127.0.0.1` | 绑定地址 | | 服务器端口 | `18489` | HTTP 端口 | ### AI 设置 (TetraMCP.AI) | 设置 | 默认值 | 描述 | |---------|---------|-------------| | 启用 AI | `false` | 启用 AI 辅助分析 | | AI 提供商 | `anthropic` | `anthropic` 或 `openai` | | AI 模型 | `claude-sonnet-4-6` | 模型名称 | **本地模型(以 Ollama 为例):** 将提供商设置为 `openai`,API URL 设置为 `http://localhost:11434/v1/chat/completions`,将 API Key 留空,并将模型设置为您的模型名称。 # 架构 TetraMCP 作为单个 Java 代码库在 Ghidra JVM 内运行,从而无需桥接脚本或序列化边界。 ``` MCP Client (Claude, Cursor, etc.) | | Streamable HTTP (:18489/mcp) | Jetty 12 (embedded HTTP server) | MCP Java SDK | Tool Providers (27 providers, 120+ tools) | Ghidra APIs (FlatProgramAPI, DecompInterface, etc.) ``` ## 使用自定义工具进行扩展 实现 `TetraMcpModule` 并通过 Java 的 `ServiceLoader` 注册: ``` public class MyModule implements TetraMcpModule { public String getName() { return "MyTools"; } public List getToolSpecifications(McpServerManager mgr) { // Return tool definitions } } ``` # 从源代码构建 **要求:** JDK 21,Ghidra 12.0.4 或更高版本。 ``` export GHIDRA_INSTALL_DIR=/path/to/ghidra ./gradlew buildExtension ``` 扩展 ZIP 文件将生成在 `dist/` 目录中。 # 许可证 Apache License 2.0。有关完整文本,请参阅 [许可证](LICENSE)。 # 鸣谢 - 美国国家安全局 (NSA) 开发的 [Ghidra](https://ghidra-sre.org/) - [Model Context Protocol](https://modelcontextprotocol.io/) 规范 - [MCP Java SDK](https://github.com/modelcontextprotocol/java-sdk)
标签:AI辅助分析, DLL 劫持, Findomain, Ghidra插件, JS文件枚举, MCP服务器, Petitpotam, 云资产清单, 后台面板检测, 域名枚举, 大语言模型, 逆向工程