README
🚀 Apktool MCP Server
Apktool MCP Server 是一个强大的 模型上下文协议(MCP)服务器,它通过暴露 Apktool 的功能,实现对 Android APK 的分析和逆向工程。该服务器能够与 Gemini CLI 无缝集成,借助自然语言命令,提供由人工智能驱动的 APK 安全分析、隐私审计以及逆向工程指导。
🚀 快速开始
本项目需要 Java JDK 8+、Apktool 和 Python 3.10+ 作为前置依赖。你可以按照以下步骤完成安装和配置:
- 安装 Java JDK 8+(Apktool 所需)
# Ubuntu/Debian
sudo apt update && sudo apt install default-jdk
# macOS (Homebrew)
brew install openjdk
# 验证安装
java -version
- 安装 Apktool(核心依赖)
# 选项 1: 包管理器(推荐)
# Ubuntu/Debian
sudo apt install apktool
# macOS
brew install apktool
# 选项 2: 手动安装
# 从 https://ibotpeaches.github.io/Apktool/install/ 下载
# 验证安装
apktool --version
- 确保 Python 版本为 3.10 或更高
python3 --version # 应显示 3.10 或更高版本
- 克隆仓库
git clone https://github.com/SecFathy/APktool-MCP.git
cd APktool-MCP
- 创建虚拟环境
python3 -m venv venv
source venv/bin/activate # Linux/macOS
# 或者
venv\Scripts\activate # Windows
- 安装依赖
pip install -r requirements.txt
- 测试安装
python3 apktool_server.py
# 应成功启动 MCP 服务器
✨ 主要特性
🔍 全面的 APK 分析
- 反编译 APK:提取资源、清单文件和 Smali 代码。
- 分析权限:对应用组件进行安全评估。
- 提取字符串资源:检测硬编码的机密信息。
- 搜索 Smali 代码:查找特定模式和安全漏洞。
- 重新编译修改后的 APK:在完成修改后重新打包。
🤖 人工智能驱动的工作流程
- 自然语言命令:支持使用自然语言完成复杂的 APK 分析任务。
- 自动化安全审计:借助人工智能生成洞察报告。
- 隐私合规性检查:进行 GDPR/CCPA 分析。
- 逐步逆向工程指导:提供详细的逆向工程步骤。
- 智能漏洞检测:进行风险评估。
🛠 8 个核心工具
| 工具 | 描述 |
|------|-------------|
| decode_apk | 反编译 APK 文件以提取所有组件 |
| build_apk | 从修改后的源目录重新编译 APK |
| install_framework | 安装系统框架以进行系统应用分析 |
| analyze_manifest | 解析 AndroidManifest.xml 文件,获取权限和组件信息 |
| extract_strings | 提取支持多语言的字符串资源 |
| list_permissions | 列举所有请求的权限 |
| find_smali_references | 在反编译的 Smali 代码中搜索特定模式 |
| get_apk_info | 获取 APK 的基本元数据和信息 |
📋 专业分析提示
- 安全分析:进行全面的漏洞评估。
- 隐私审计:分析数据收集和合规性。
- 逆向工程指南:提供逐步分析工作流程。
📦 安装指南
前提条件
- Java JDK 8+:Apktool 运行所需。
- Apktool:核心依赖。
- Python 3.10+:确保版本符合要求。
安装步骤
请参考上面“快速开始”部分的安装步骤进行操作。
💻 使用示例
自然语言命令
# 启动 Gemini CLI
gemini
# 安全分析
> "Analyze the APK at ./suspicious_app.apk for security vulnerabilities"
# 权限分析
> "What permissions does ./myapp.apk request and are any of them dangerous?"
# 代码分析
> "Find any hardcoded API keys or secrets in ./social_app.apk"
# 隐私审计
> "Generate a privacy compliance report for ./messenger_app.apk"
# 逆向工程
> "Help me understand how the authentication works in ./banking_app.apk"
直接使用工具
# 反编译 APK
> Use decode_apk to decompile ./sample.apk
# 分析权限
> Use list_permissions on the decompiled directory ./sample
# 搜索模式
> Use find_smali_references to search for "crypto" in ./sample
# 提取字符串
> Use extract_strings from ./sample for locale "en"
# 重新构建 APK
> Use build_apk to recompile ./sample into ./sample_modified.apk
引导式工作流程
# 运行自动化安全分析
> Run the security analysis prompt on ./target_app.apk
# 执行隐私审计
> Execute privacy audit workflow for ./social_media_app.apk
# 获取逆向工程指导
> Use the reverse engineering guide for analyzing login functionality in ./app.apk
📚 详细文档
配置说明
Gemini CLI 集成
- 安装 Gemini CLI
# 请按照 https://github.com/google-gemini/gemini-cli 中的说明进行操作
- 配置 MCP 服务器 编辑你的 Gemini CLI 配置文件:
- Linux/macOS:
~/.config/gemini-cli/config.json - Windows:
%APPDATA%\gemini-cli\config.json
{
"mcpServers": {
"apktool": {
"command": "python3",
"args": ["/absolute/path/to/apktool_server.py"],
"env": {
"APKTOOL_WORK_DIR": "/path/to/workspace"
}
}
}
}
Claude Desktop 集成(可选)
编辑 Claude Desktop 配置文件:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"apktool": {
"command": "python3",
"args": ["/absolute/path/to/apktool_server.py"],
"env": {
"APKTOOL_WORK_DIR": "/path/to/workspace"
}
}
}
}
项目结构
apktool-mcp-server/
├── apktool_server.py # 主 MCP 服务器实现
├── requirements.txt # Python 依赖
├── config.json # 示例 Gemini CLI 配置
├── README.md # 当前文件
├── GEMINI.md # 人工智能助手上下文文件
├── LICENSE # MIT 许可证
├── examples/ # 使用示例和样本
│ ├── sample_analysis.py # 示例分析脚本
│ └── workflows/ # 常见工作流示例
├── tests/ # 单元测试
│ ├── test_server.py # 服务器功能测试
│ └── test_tools.py # 单个工具测试
└── docs/ # 附加文档
├── SECURITY.md # 安全指南
├── CONTRIBUTING.md # 贡献指南
└── TROUBLESHOOTING.md # 常见问题及解决方案
🔧 技术细节
🔒 安全注意事项
⚠️ 重要安全提示
- 法律合规:仅分析你拥有或获得明确授权的 APK。
- 恶意软件风险:未知的 APK 可能包含恶意代码,请在隔离环境中使用。
- 数据隐私:反编译的 APK 可能包含敏感的用户信息。
- 工作区隔离:配置具有受限权限的专用工作区。
- 进程限制:服务器包含超时机制,以防止资源耗尽。
最佳实践
# 使用专用工作区
export APKTOOL_WORK_DIR="/secure/isolated/workspace"
# 设置适当的权限
chmod 750 /secure/isolated/workspace
# 监控资源使用情况
htop # 在分析过程中监控内存和 CPU 使用情况
# 分析完成后清理
rm -rf /secure/isolated/workspace/*
🧪 测试
运行单元测试
# 安装测试依赖
pip install pytest pytest-asyncio
# 运行所有测试
pytest tests/
# 运行带覆盖率的测试
pytest --cov=apktool_server tests/
手动测试
# 测试服务器启动
python3 apktool_server.py
# 使用样本 APK 进行测试
# 下载一个样本 APK 并测试基本功能
集成测试
# 测试 Gemini CLI 集成
gemini
> /tools # 应列出 Apktool 工具
> Use decode_apk to analyze sample.apk
🤝 贡献说明
我们欢迎大家贡献代码!具体细节请参考 CONTRIBUTING.md。
开发环境设置
# 克隆并设置开发环境
git clone https://github.com/SecFathy/APktool-MCP.git
cd APktool-MCP
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
# 运行测试
pytest
# 格式化代码
black apktool_server.py
📄 许可证
本项目采用 MIT 许可证。
Scan to join WeChat group