Perform Android App reverse engineering analysis on $ARGUMENTS .
MCP Dependencies:
frida-mcp— Frida dynamic Hook (spawn/attach/script injection/message reading)adb-mcp— ADB device management (install/file transfer/screenshot/log/input simulation)android_proxy_mcp— Traffic capture (HTTP/HTTPS packet capture/API analysis)
Pre-checks
Confirm the environment before starting analysis:
1. list_devices → 检查 ADB 是否连接到设备
2. get_device_info → 确认设备信息(型号、Android 版本、root 状态)
3. check_frida_status → 检查 frida-server 是否运行
└── 未运行 → start_frida_server
4. proxy_status → 检查代理服务是否运行(如需抓包)
Analysis Workflow
Select stages flexibly based on the target; not all need to be executed:
Stage 1: Target Identification and Information Gathering
1. list_packages → 查找目标 App 包名
└── 未安装 → install_app(apk_path) 安装 APK
2. get_frontmost_application → 确认目标 App 在前台
3. pull_file → 提取 APK:
- /data/app/<package>/base.apk → 本地分析
4. 静态分析(本地执行,非 MCP):
- jadx / apktool 反编译
- 查看 AndroidManifest.xml(权限、组件、入口)
- 识别加固壳(360、腾讯、梆梆等)
- 定位网络请求相关类
Stage 2: Traffic Capture and API Discovery
Goal: Find the target API request, identify encrypted parameters
1. 配置代理:
- 手机 WiFi 设置代理 → 指向 android_proxy_mcp 的 IP:8288
- 需要 HTTPS → get_cert_info 获取 CA 证书安装指引
2. 驱动 App 操作:
- send_tap(x, y) / send_swipe(...) → 模拟用户操作触发请求
- send_text("搜索关键词") → 输入文本
- take_screenshot → 截屏确认当前界面
3. 分析流量:
- traffic_list → 列出捕获的请求(按域名/状态码筛选)
- traffic_search("sign") → 搜索包含加密参数的请求
- traffic_get_detail(reqid) → 查看请求头、响应头
- traffic_read_body(reqid) → 读取请求/响应体
4. 识别加密参数:
- 记录加密字段名、位置(header/body/query)
- 记录字段值的特征(长度、编码格式、是否时间相关)
- 对比多次相同请求,观察哪些字段变化
Stage 3: SSL Pinning Bypass
If HTTPS packet capture fails (certificate error), SSL Pinning needs to be bypassed:
方案 A: Frida 脚本 Hook(推荐)
spawn(package_name, script_file_path="ssl_bypass.js")
通用 SSL Pinning 绕过脚本思路:
- Hook TrustManager.checkServerTrusted → 置空
- Hook OkHttp CertificatePinner.check → 绕过
- Hook SSLContext.init → 替换为信任所有证书
- Hook WebViewClient.onReceivedSslError → proceed
方案 B: LSPosed + TrustMeAlready 模块(免 Frida)
参考 references/ssl-pinning-bypass.md
方案 C: 修改 APK(network-security-config)
解包 → 修改 res/xml/network_security_config.xml → 重打包签名
Stage 4: Dynamic Hook
Goal: Intercept the input and output of encryption functions, understand the encryption logic
4.1 Java-layer Hook
// spawn 或 attach 后注入 Frida 脚本
// Hook 加密方法,打印输入输出
Java.perform(function() {
var EncryptUtil = Java.use("com.target.utils.EncryptUtil");
EncryptUtil.encrypt.overload("java.lang.String").implementation = function(input) {
console.log("[encrypt] input: " + input);
var result = this.encrypt(input);
console.log("[encrypt] output: " + result);
return result;
};
});
Operation Flow:
1. spawn(package_name, initial_script=上述脚本)
或 attach(package_name, initial_script=上述脚本)
2. 操作 App 触发加密
3. get_messages(max_messages=200) → 读取 hook 输出
4. 分析输入输出关系
4.2 Native-layer Hook (.so files)
// Hook native 函数
Interceptor.attach(Module.findExportByName("libnative.so", "Java_com_target_NativeLib_sign"), {
onEnter: function(args) {
console.log("[native sign] arg0: " + args[0]);
console.log("[native sign] arg1: " + Memory.readUtf8String(args[1]));
},
onLeave: function(retval) {
console.log("[native sign] return: " + Memory.readUtf8String(retval));
}
});
4.3 Common Hook Targets
| Goal | Hook Location | Purpose |
|---|---|---|
| MD5/SHA | java.security.MessageDigest.digest |
Intercept standard Hash |
| HMAC | javax.crypto.Mac.doFinal |
Intercept HMAC signature |
| AES/DES | javax.crypto.Cipher.doFinal |
Intercept symmetric encryption |
| RSA | java.security.Signature.sign |
Intercept asymmetric signature |
| Base64 | android.util.Base64.encodeToString |
Intercept encoding |
| SharedPrefs | SharedPreferences.getString |
Read local configuration |
| OkHttp | okhttp3.OkHttpClient.newCall |
Intercept HTTP request construction |
Stage 5: Algorithm Recovery
Based on the Hook results from Stage 4, recover the encryption algorithm:
情况 A: 标准加密算法(MD5/SHA/AES/RSA/HMAC)
→ Hook 拿到 key/iv/salt 等参数
→ 直接用 Python 标准库实现
→ 验证:相同输入 → 相同输出
情况 B: 自定义算法(Java 层)
→ 反编译代码 + Hook 中间值
→ 逐步还原逻辑到 Python
→ 多组数据验证
情况 C: Native 层算法(.so 文件)
→ IDA/Ghidra 反编译 .so
→ Frida hook native 函数拿中间值
→ 还原到 Python 或直接调用 .so(ctypes/cffi)
情况 D: 第三方加固/保护
→ 先脱壳(Frida dump dex)
→ 再按 A/B/C 处理
Anti-patterns
- Do not attempt Frida on a non-rooted device — Non-root requires repackaging the APK to inject frida-gadget, and the workflow is completely different.
- Do not ignore ProGuard obfuscation — Class names/method names of most Apps are obfuscated, so you need to search for characteristic strings (such as "sign", "encrypt", "MD5") in the decompiled code to locate the target class.
- Do not hook only one layer — The signatures of many Apps are multi-step combinations (first MD5, then HMAC, then Base64), so the entire call chain needs to be hooked.
- Do not forget the timestamp — Most signatures include a time factor, and the timestamp needs to be updated when replaying.
- spawn vs attach — For hooking before the App starts (such as initialization logic in onCreate), use
spawn; for hooking the real-time behavior of an already running App, useattach。
Completion Criteria
分析结果:
- App:$ARGUMENTS
- 目标 API:https://api.example.com/v1/feed
- 加密参数:X-Sign(位于请求头)
- 算法类型:HMAC-SHA256
- 密钥来源:固定密钥,硬编码在 so 层
- Python 实现:output/sign.py(已验证)
- 验证结果:相同输入产生相同签名,HTTP 200 + 业务数据返回
References
Read on demand when encountering specific scenarios:
| File | When to Read |
|---|---|
references/frida-hooks.md |
When Frida hook templates are needed (Java layer/Native layer/common frameworks) |
references/ssl-pinning-bypass.md |
When HTTPS packet capture fails and SSL Pinning needs to be bypassed |
references/common-android-crypto.md |
When identifying common encryption implementation patterns in Android Apps |