如需使用受 Claude 启发的 Orchestrator 版本,请参阅 https://github.com/llnl/OGhidra/tree/orchestrator
OGhidra 将大型语言模型与 Ghidra 的逆向工程平台连接起来,通过自然语言实现 AI 驱动的二进制分析。您可以以对话方式分析二进制文件、自动化复杂工作流,并通过本地 AI 模型保持完全隐私。
YouTube 设置教程
OGhidra 为 Ghidra 增添 AI 能力,使您能够:
graph TD
A[User Query] --> B[Planning Phase]
B --> C{Execution Phase}
C -- Tool Calls --> D[Ghidra/LLM]
D --> C
C --> E[Review Phase]
E -- Agentic Loop --> B
E --> F[Final Response]
style E fill:#f9f,stroke:#333,stroke-width:2px
style B fill:#bbf,stroke:#333,stroke-width:2px
智能代理循环(Agentic Loop):OGhidra 采用自适应规划系统。每次执行周期结束后,都会对结果进行审查,AI 可以选择收集更多信息或优化分析,然后再给出最终响应。
python --versionjava -version# Clone repository
git clone https://github.com/LLNL/OGhidra.git
cd OGhidra
# Install dependencies (choose one)
uv sync # Using UV (recommended)
pip install -r requirements.txt # Using pip
# Configure environment
cp .env.example .env
# Edit .env with your settings
以下 OGhidraMCP 插件构建步骤面向 Ghidra 12.0.3(推荐)。 另附 YouTube 视频教程:https://www.youtube.com/watch?v=hBD92FUgR0Y
作为开发者,您需要先构建 GhidraMCP 扩展,然后才能将其安装到 Ghidra:
前置条件:
选项 1:使用自动化构建脚本:
Windows:
# Set the path to your Ghidra installation (will attempt to find last run copy of Ghidra if not set)
set GHIDRA_INSTALL_DIR=C:\path\to\ghidra_12.0.3_PUBLIC
# Run the build script
build_ghidra_plugin.bat
Unix/Linux/Mac:
# Set the path to your Ghidra installation (will attempt to find the last run copy of Ghidra if not set)
export GHIDRA_INSTALL_DIR=/path/to/ghidra_12.0.3_PUBLIC
# Run the build script (make it executable first if needed)
chmod +x build_ghidra_plugin.sh
./build_ghidra_plugin.sh
选项 2:手动构建流程:
在 OGhidraMCP/gradle.properties 中创建/更新您的 Ghidra 安装路径:
GHIDRA_INSTALL_DIR=/absolute/path/to/ghidra_12.0.3_PUBLIC
在 Unix/Linux/macOS 上:
cd OGhidraMCP
$GHIDRA_INSTALL_DIR/support/gradle/gradlew buildExtension --info
在 Windows 上:
cd OGhidraMCP
"%GHIDRA_INSTALL_DIR%\support\gradle\gradlew.bat" buildExtension --info
成功构建扩展后:
在 Ghidra 中安装:
OGhidraMCP/dist/ 目录ghidra_12.0.3_PUBLIC_YYYYMMDD_OGhidraMCP.zip)启用插件:
OGhidraMCP 插件http://localhost:8080/methods您需要保持代码浏览器(Code Browser)处于打开状态
# For Ollama (local models)
ollama pull gemma3:27b # Good balance (20GB RAM)
ollama pull nomic-embed-text # Embedding model for RAG
# Alternative models
ollama pull gpt-oss:120b # High quality (80GB RAM)
ollama pull devstral-2:123b # High quality (80GB RAM)
ollama pull devstral-2:123b-cloud # Cloud Model
# GUI Mode (recommended)
uv run main.py --ui
# Interactive CLI
uv run main.py --interactive
# In interactive CLI, test connection
health
如果您启动了 GUI 模式,请使用:
curl http://localhost:8080/methods
编辑 .env 以配置您的 AI 提供商:
LLM_PROVIDER=ollama
OLLAMA_BASE_URL=http://localhost:11434/
OLLAMA_MODEL=gemma3:27b
OLLAMA_EMBEDDING_MODEL=nomic-embed-text
LLM_PROVIDER=external
EXTERNAL_PROVIDER=google
EXTERNAL_API_KEY=your-api-key-here
EXTERNAL_MODEL=gemini-3.1-flash-lite-preview
EXTERNAL_EMBEDDING_MODEL=gemini-embedding-001
LLM_PROVIDER=custom_api
CUSTOM_API_URL=https://api.example.com/v1/chat/completions
CUSTOM_API_KEY=your-api-key-here
CUSTOM_API_MODEL=your-model-name
CUSTOM_API_EMBEDDING_MODEL=your-embedding-model
根据您模型的上下文窗口进行调整:
# Context budget in tokens (adjust to your model's limit)
CONTEXT_BUDGET=100000 # 100K tokens for mid-size models
# 200K+ for frontier models
# Execution settings
MAX_EXECUTION_STEPS=5 # Steps per planning cycle
MAX_AGENTIC_CYCLES=3 # How many plan-execute-review loops
AGENTIC_LOOP_ENABLED=true # Enable adaptive replanning
一键访问常见逆向工程任务:
设置专门的分析目标:
# In GUI: Use "Task Mode" dropdown
# In CLI: set task_mode <mode>
task_mode malware # Malware analysis with pattern detection
task_mode vuln # Vulnerability research focus
task_mode general # General reverse engineering
自动检测 12 种以上的恶意软件模式:
这些模式会在 AI 上下文中触发自动警报,并附带 MITRE ATT&CK 映射。
从二进制分析构建丰富、可查询的知识:
# Enumerate all functions with AI summaries
# Choose from:
- Rename Only: Only process generic function names
- Smart Enumeration: Focus on security-relevant functions
- Full Enumeration: Analyze every function in the binary
功能特性:
保存和恢复分析会话:
# Save progress
File → Save Session
# Load previous work
File → Load Session
# Auto-save after bulk operations
# Sessions include:
- Analyzed functions with summaries
- RAG vectors for semantic search
- Performance statistics
- UI state
OGhidra 支持两种后端类型:
使用以下命令行选项选择后端:
--ghidra-backend={http,pyghidra}
| 后端选项 | 描述 |
|---|---|
http | 使用 GhidraMCP 后端 |
pyghidra | 使用 PyGhidra 后端 |
启动 OGhidra 时指定 Ghidra 项目文件(.gpr):
--pyghidra-project=/path/to/project.gpr
PyGhidra 需要有效的 Ghidra 项目才能启动 OGhidra。
指定应分析 Ghidra 项目中的哪个二进制文件:
--pyghidra-program=<program_name>
在 Ghidra 项目中选择程序的示例调用:
uv run main.py --ui --ghidra-backend=pyghidra --pyghidra-project=/path/to/project.gpr --pyghidra-program=<program_name>
要求:
您也可以直接提供二进制文件路径:
--pyghidra-binary=/path/to/binary
使用此选项时,PyGhidra 会自动:
.gpr)直接启动二进制文件的示例调用:
uv run main.py --ui --ghidra-backend=pyghidra --pyghidra-binary=/path/to/binary
uv run main.py --ui# In GUI: Click "Generate Report" button
# Report includes:
- Executive Summary
- Function Inventory (renamed functions with behavior)
- Security Analysis (high-risk functions, patterns)
- Import Analysis
- String Analysis
- Recommendations
OGhidra 使用向量嵌入对已分析的函数进行语义搜索:
# Enable in .env
RESULT_CACHE_ENABLED=true
TIERED_CONTEXT_ENABLED=true
优势:
分层上下文压缩可保留相关信息:
CURRENT_LOOP_MAX_CHARS=2000 # Recent: full detail
PREV_LOOP_MAX_CHARS=400 # Previous: summaries
OLDER_LOOP_MAX_CHARS=100 # Older: references only
跟踪所有 AI 交互以用于调试:
LLM_LOGGING_ENABLED=true
LLM_LOG_FILE=logs/llm_interactions.log
LLM_LOG_FORMAT=json
# Verify plugin is loaded
# Open up codebrowser!
# Check server is running
curl http://localhost:8080/methods
# Verify Ollama is running
ollama list
# Check connectivity
curl http://localhost:11434/api/tags
# Restart Ollama service
ollama serve
# Reduce context budget
CONTEXT_BUDGET=50000
# Enable compaction
COMPACTION_ENABLED=true
COMPACTION_THRESHOLD=0.75
gemma3:9bmax_workers=2RESULT_CACHE_ENABLED=falseCUSTOM_API_REQUEST_DELAY=2.0┌─────────────────────────────────────────────────────────────┐
│ OGhidra UI │
│ (GUI / Interactive CLI) │
└────────────────────────┬────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Bridge (src/bridge.py) │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ • Agentic Loop: Plan → Execute → Review → Replan │ │
│ │ • Tool Router: Ghidra client, LLM client, CAG manager │ │
│ │ • Context Manager: Budget allocation, compression │ │
│ └────────────────────────────────────────────────────────┘ │
└───────────┬────────────────────────┬────────────────────────┘
│ │
▼ ▼
┌───────────────────────┐ ┌─────────────────────────┐
│ Ghidra Client │ │ LLM Clients │
│ • GhidraMCP Plugin │ │ • Ollama (local) │
│ • Binary operations │ │ • External APIs │
│ • Decompilation │ │ • Custom endpoints │
└───────────────────────┘ └─────────────────────────┘
│ │
└────────────┬───────────┘
▼
┌─────────────────────────────────────────────────────────────┐
│ CAG Manager (Knowledge System) │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ • Vector Store: Semantic search over functions │ │
│ │ • Pattern Detector: 12+ malware techniques │ │
│ │ • Metadata Extractor: Structured function analysis │ │
│ │ • Session Store: Persistent analysis state │ │
│ └────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
我们欢迎各种贡献!感兴趣的方向包括:
社区准则请参阅 CODE_OF_CONDUCT.md。
如果您在研究中使用 OGhidra,请按以下方式引用:
@software{oghidra2025,
title = {OGhidra: AI-Powered Reverse Engineering with Ghidra},
author = {Enoch Wang},
year = {2025},
url = {https://github.com/LLNL/OGhidra}
}
OGhidra 基于以下出色的开源项目构建:
OGhidra 依据 BSD 3-Clause 许可证条款分发,并提供商业许可证替代方案。
LLNL-CODE-2013290
查找构建好的扩展:
OGhidraMCP/dist/ 目录中ghidra_12.0.3_PUBLIC_YYYYMMDD_OGhidraMCP.zip| 工具 | 描述 |
|---|
| Analyze Current Function(分析当前函数) | 深入分析所选函数的行为 |
| Rename Current Function(重命名当前函数) | AI 根据分析建议有意义的名称 |
| Rename All Functions(重命名所有函数) | 批量重命名,提供智能/完整/仅重命名选项 |
| Analyze Imports(分析导入) | 识别库和外部依赖项 |
| Analyze Strings(分析字符串) | 查找 URL、凭据、配置数据 |
| Generate Report(生成报告) | 全面的安全评估 |