Pyghidra升
   
用于基于Ghidra的逆向工程的令牌高效MCP服务器。使用Swift、Objective-C和Hermes支持分析ELF、Mach-O和PE二进制文件。
快速开始
1.先决条件
需要JDK 21+和Ghidra 11.x。
# macOS
brew install openjdk@21
brew install --cask ghidra
# Ubuntu/Debian
sudo apt install openjdk-21-jdk
# Download Ghidra from https://ghidra-sre.org
# Arch Linux
sudo pacman -S jdk21-openjdk
yay -S ghidraGhidra在 /opt/ghidra 或 ~/ghidra 会自动找到。集 GHIDRA_INSTALL_DIR 仅适用于非标准路径。
2.安装pyghidra lite
pip install pyghidra-lite3.添加到克劳德代码
创建 .mcp.json 在您的项目中(或 ~/.claude.json 全球):
{
"mcpServers": {
"pyghidra-lite": {
"command": "pyghidra-lite"
}
}
}4.使用它
You: Analyze the binary at /path/to/binaries/app
Claude: [calls load, info, code...]安装
PyPI(推荐)
pip install pyghidra-liteArch Linux(AUR)
yay -S python-pyghidra-lite来源
git clone https://github.com/johnzfitch/pyghidra-lite
cd pyghidra-lite
pip install -e .MCP配置
克劳德桌面
添加 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)或 %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"pyghidra-lite": {
"command": "uvx",
"args": ["pyghidra-lite"]
}
}
}uvx 自动在第一次运行时从PyPI安装pyghidra lite。Ghidra是自动检测的;集 GHIDRA_INSTALL_DIR 在 env 如果需要:
{
"mcpServers": {
"pyghidra-lite": {
"command": "uvx",
"args": ["pyghidra-lite"],
"env": {
"GHIDRA_INSTALL_DIR": "/path/to/ghidra"
}
}
}
}克劳德代码
创建 .mcp.json 在您的项目中(或 ~/.claude.json 全球):
{
"mcpServers": {
"pyghidra-lite": {
"command": "pyghidra-lite"
}
}
}直接模式(跳过代理)
对于单会话使用或调试,请直接运行服务器:
{
"mcpServers": {
"pyghidra-lite": {
"command": "pyghidra-lite",
"args": ["serve"]
}
}
}具有明确的Ghidra路径
{
"mcpServers": {
"pyghidra-lite": {
"command": "pyghidra-lite",
"args": [
"serve",
"--ghidra-dir", "/path/to/ghidra"
]
}
}
}仅限于特定路径
默认情况下,pyghidra lite可以从任何路径加载二进制文件(MCP客户端处理权限)。使用 --restrict-path 要锁定访问权限:
{
"mcpServers": {
"pyghidra-lite": {
"command": "pyghidra-lite",
"args": [
"serve",
"--restrict-path", "/home/user/binaries",
"--restrict-path", "/opt/targets"
]
}
}
}工具(8)
pyghidra lite提供了8个综合工具,可以自动检测格式(ELF/Mach-O/PE)和语言(Swift/ObjC/Hermes):
| 工具 | 目的 | 关键参数 |
|---|---|---|
load | 导入和分析二进制文件 | path, profile?, fresh?, bootstrap?, bootstrap_mode? |
delete | 删除二进制文件并取消作业 | name |
binaries | 列出二进制文件+作业状态 | jobs?, rank_sources? |
info | 二进制概述 | binary, detail? (摘要/全文/格式/章节/熵) |
functions | 列表/搜索功能 | binary, query?, type? (全部/swift/objc/进口/出口) |
code | 分解或拆卸 | binary, target, what? (反编译/痉挛), cfg? |
xrefs | 参考文献和调用图 | binary, target, direction?, depth?, diff? |
search | 查找字符串、字节、符号 | binary, query, type?, mode?, bg? |
示例
# Import and analyze
load("/path/to/binary", profile="fast")
# Version-track from a prior build, including synthetic IDs for unnamed code
load("/path/to/new.bin", profile="deep", bootstrap="old.bin", bootstrap_mode="all")
# Get overview with full triage
info("mybinary", detail="full")
# List Swift functions
functions("mybinary", type="swift")
# Decompile with CFG
code("mybinary", "main", cfg=True)
# Search strings in background
search("mybinary", ["password", "api_key"], bg=True)
# Get cross-references
xrefs("mybinary", "malloc", depth=2)自动检测
所有工具都会自动检测:
- 格式:ELF、Mach-O、PE
- 语言Swift、Objective-C、Hermes/RReact Native
- 运行时:Bun、Node.js、Electron、PyInstaller
使用 type 和 detail 访问格式/语言特定功能的参数。
引导模式
bootstrap_mode="named":仅传输有意义的源名称(默认)。bootstrap_mode="all":还为源代码分配稳定的合成标签FUN_*在传输过程中使用函数,这对于大型版本到版本引导工作流非常有用,在这些工作流中,唯一性比语义更重要。
分析配置文件
| 简介 | 用例 |
|---|---|
fast | 快速分流,禁用20个慢速分析器(默认) |
default | 平衡、全面的Ghidra分析 |
deep | 对混淆代码进行彻底分析 |
服务器默认为 fast 以保持在MCP超时限制内。使用 load(fresh=True) 在需要时进行更深入的分析:
# Default import uses fast profile
load("/path/to/binary")
# Re-analyze with deep profile
load("/path/to/binary", profile="deep", fresh=True)代币效率
pyghidra lite旨在实现最小的令牌使用量:
- 默认情况下输出紧凑 -
functions(binary, type="all")返回最小值{name, addr}对 - 选择详细信息 -使用
info(detail="full"),code(cfg=True),或更富有type/what仅在需要时使用模式 - 进度报告 -大型进口每10%或60秒报告一次进展
- 截断的字符串 -上限为500个字符的长字符串
建筑
默认情况下, pyghidra-lite 作为轻量级stdio代理(约10MB)运行,该代理转发到持久共享HTTP后端(约500MB JVM)。多个会话共享一个JVM,而不是每个会话都生成自己的JVM。
Claude Code session 1 ──stdio──> proxy ──┐
Claude Code session 2 ──stdio──> proxy ──┼──HTTP──> shared backend (1 JVM)
Claude Code session 3 ──stdio──> proxy ──┘ localhost:19101代理自动在首次使用时启动后端,后端自动在空闲30分钟后退出。文件锁可防止并发代理启动产生重复的后端。
| 命令 | 它的作用 |
|---|---|
pyghidra-lite | Stdio代理(默认)--自动启动后端 |
pyghidra-lite serve | 直接stdio服务器(每个会话1个JVM) |
pyghidra-lite serve -t streamable-http | 手动启动持久HTTP后端 |
pyghidra-lite stop | 停止共享后端 |
集 PYGHIDRA_LITE_NO_AUTOSTART=1 禁用自动启动(对systemd有用)。
多代理支持
每个二进制文件都有自己的Ghidra项目,可以实现:
- 不同二进制文件的并行分析
- 跨代理共享结果
- 持续分析(重启后仍能继续)
- 内容寻址存储(相同的二进制=相同的分析)
项目存储在 ~/.local/share/pyghidra-lite/projects/.
链接
许可证
麻省理工学院
