Android 应用程序的逆向工程与渗透测试

Androguard 5 是一个用于 Android 逆向工程的 Python 工具包:打开 APK、检查清单文件和 DEX、反汇编或反编译代码、查找引用和漏洞,并可选地修补或分析原生 ARM —— 可通过 CLI、高层 Application API、Claude Code 技能,或面向 LLM 宿主的 MCP 服务器使用。
apkparser-ag、dexparser-ag、axml)androguard[disasm] 进行方法级字节码分析androguard[decompile] 反编译方法、类或整个包findrefs、漏洞扫描器、方法模拟androguard[arm] 反汇编 / 反编译 .so 代码androguard[patch] 解码 / 重建项目树androguard-mcp)scan_vulns 的对比状态,见 docs/mastg-coverage.md你认为你的手机已被入侵了吗?请查看 IsMyPhonePwned。
Androguard 5 就是本仓库。它不是当前发布在 PyPI 上的包(androguard 4.1.4)。请从代码检出目录安装本地代码树。直接运行 pip install androguard 或 pip install 'androguard[full]' 会下载 4.1.4 并卸载 5.0.0。
# from this repo (Rust toolchain required for the optional extras)
# Python 3.14+ needs the PyO3 forward-compat flag (bindings use PyO3 0.23, max 3.13)
export PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1
# Rust apk-parser + dex-parser (siblings under ../)
pip install -e ../apk-parser
pip install -e ../dex-parser
pip install -e .
pip install -e '.[full]'
在 5.0.0 发布后,相同的 extras 可从 PyPI 安装:
pip install androguard
pip install 'androguard[full]'
[!IMPORTANT] 版本 >= 4.0.0 是时隔许久后的新发布版本,该项目与 2019 年的上一个稳定版本 3.3.5 相比有重大差异。这意味着某些功能已被移除。如果您在使用最新版本时发现项目存在问题,请提交 issue。
Androguard v5 构建于专用库之上:
| 层级 | 库 | 作用 |
|---|---|---|
| APK 归档 | apk-parser (apkparser-ag) | ZIP 结构、签名、manifest 钩子 |
| DEX 结构 | dex-parser (dexparser-ag) | Rust 核心 + Python 绑定:类、方法、字段、字节码 |
| 二进制 XML / ARSC | axml / axml-parser (Rust) | AndroidManifest.xml、resources.arsc |
| 字节码(可选) | dex-bytecode | 通过 androguard[disasm] 进行 Dalvik 反汇编 / CFG / 补丁 |
| 反编译器(可选) | dex-decompiler | 通过 androguard[decompile] 实现 DEX → Java、ASC getclass/findrefs、漏洞检测 |
| ARM64(可选) | arm_disassembler / arm_decompiler | 通过 androguard[arm] 处理原生代码 |
| APK 补丁(可选) | apk-patch | 通过 androguard[patch] 进行内存中解码/构建 |
可运行的演示位于 examples/,并且也会由测试套件(tests/test_examples.py)执行:
python -m examples.application_summary
python -m examples.disassemble # androguard[disasm]
python -m examples.decompile # androguard[decompile]
python -m examples.arm # androguard[arm]
python -m examples.patch_decode # androguard[patch]
python -m examples.run_all
本仓库提供 Claude Code 项目支持(理念上类似于 areclaw,但由 Androguard 本身驱动):
| 路径 | 作用 |
|---|---|
CLAUDE.md | 面向智能体的项目说明 |
.claude/agents/androguard-analyst.md | 分析智能体 |
.claude/skills/ | /analyze-apk、/decompile-apk、/find-refs、/scan-vulns |
workspace/ | 样本、反编译输出、报告 |
claude /agent androguard-analyst
claude /analyze-apk path/to/app.apk
claude /decompile-apk path/to/app.apk com.example.app
Androguard 可以作为 MCP 服务器运行,这样 LLM 宿主(Claude Code、Cursor 等)就能调用类型化的分析工具,而无需通过 shell 调用 CLI。
pip install -e '.[mcp,decompile]' # add [disasm] for disassembly tools
androguard-mcp # or: python -m androguard.mcp
示例客户端配置:
{
"mcpServers": {
"androguard": {
"command": "androguard-mcp",
"env": {
"ANDROGUARD_MCP_ROOTS": "/path/to/androguard"
}
}
}
}
典型流程:open_apk → session_id → list_classes / find_refs / decompile_method / scan_vulns。
启动时,服务器会向 stderr 打印横幅(版本、工具、路径根目录、附加组件)。使用 --log-tools 记录每次工具调用,使用 --log-level DEBUG 获取更多细节。
完整工具列表、环境变量和安全说明:docs/mcp-server.md。设计背景:docs/mcp-server-plan.md。
# Summary: package, main activity, dex count, classes, methods
androguard -i my.apk
# List classes or methods
androguard -i my.apk --list-classes
androguard -i my.apk --list-methods
# Disassemble methods matching regex (requires androguard[disasm])
androguard -i my.apk --disasm --class 'TestActivity' --method 'onCreate'
androguard -i my.apk --disasm --class 'Ltests/androguard/.*' --method '<init>'
androguard -i my.apk --disasm --method 'onCreate' --limit 10
androguard -i my.apk --disasm --class TestActivity --method onCreate --cfg
# Decompile to Java (requires androguard[decompile])
androguard -i my.apk --decompile-method 'tests.androguard.TestActivity#onCreate'
androguard -i my.apk --decompile --class TestActivity --method onCreate
androguard -i my.apk --decompile -o out.java
androguard -i my.apk -d decompiled/ --only-package tests.androguard
androguard -i my.apk --getclass tests.androguard.TestActivity
androguard -i my.apk --findrefs string --findrefs-value password
androguard -i my.apk --scan-vulns
androguard -i my.apk --emulate 'tests.androguard.TestActivity#onCreate'
# Decode project tree (requires androguard[patch])
androguard -i my.apk --decode-project
执行 pip install -e '.[full]' 后,使用仓库中的示例 APK(tests/data/APK/TestActivity.apk)测试主要 CLI 功能:
# from the androguard repo root
APK=tests/data/APK/TestActivity.apk
CLS=tests.androguard.TestActivity
METH="$CLS#onCreate"
androguard -i "$APK" # summary
androguard -i "$APK" --list-classes | head
androguard -i "$APK" --list-methods | head
# disasm (androguard[disasm])
androguard -i "$APK" --disasm --class TestActivity --method onCreate
androguard -i "$APK" --disasm --class TestActivity --method onCreate --cfg
# decompile / ASC / vulns / emulate (androguard[decompile])
androguard -i "$APK" --decompile-method "$METH"
androguard -i "$APK" --getclass "$CLS"
androguard -i "$APK" -d /tmp/androguard-decompiled/ --only-package tests.androguard
androguard -i "$APK" --findrefs string --findrefs-value "this is a test"
androguard -i "$APK" --scan-vulns # MASWE / MASVS / MASTG ids
androguard -i "$APK" --emulate "$METH"
# patch (androguard[patch])
androguard -i "$APK" --decode-project
或运行 Python 演示(覆盖范围相同,包括可选的 ARM):
python -m examples.run_all