Apktool MCP Server 是一个强大的 模型上下文协议(MCP)服务器,它通过暴露 Apktool 的功能,实现对 Android APK 的分析和逆向工程。该服务器能够与 Gemini CLI 无缝集成,借助自然语言命令,提供由人工智能驱动的 APK 安全分析、隐私审计以及逆向工程指导。
本项目需要 Java JDK 8+、Apktool 和 Python 3.10+ 作为前置依赖。你可以按照以下步骤完成安装和配置:
# Ubuntu/Debian
sudo apt update && sudo apt install default-jdk
# macOS (Homebrew)
brew install openjdk
# 验证安装
java -version
# 选项 1: 包管理器(推荐)
# Ubuntu/Debian
sudo apt install apktool
# macOS
brew install apktool
# 选项 2: 手动安装
# 从 https://ibotpeaches.github.io/Apktool/install/ 下载
# 验证安装
apktool --version
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 服务器
| 工具 | 描述 |
|---|---|
decode_apk |
反编译 APK 文件以提取所有组件 |
build_apk |
从修改后的源目录重新编译 APK |
install_framework |
安装系统框架以进行系统应用分析 |
analyze_manifest |
解析 AndroidManifest.xml 文件,获取权限和组件信息 |
extract_strings |
提取支持多语言的字符串资源 |
list_permissions |
列举所有请求的权限 |
find_smali_references |
在反编译的 Smali 代码中搜索特定模式 |
get_apk_info |
获取 APK 的基本元数据和信息 |
请参考上面“快速开始”部分的安装步骤进行操作。
# 启动 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
# 请按照 https://github.com/google-gemini/gemini-cli 中的说明进行操作
~/.config/gemini-cli/config.json%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 配置文件:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.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 # 常见问题及解决方案
# 使用专用工作区
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 许可证。