Phase flow: Environment preparation → APK static analysis → Dynamic analysis (Frida) → Component security testing → Data storage security → Network communication security → Protection mechanism bypass
In-depth reference
- Detailed APK static analysis commands and Manifest audit points → references/android-static-analysis.md
- Frida Hook scripts and SSL Pinning bypass in practice → references/android-frida-dynamic.md
- React Native / Flutter / native so / RMS / Appium runtime analysis → references/android-frameworks-and-runtime.md
Phase 0: Environment preparation
Device/emulator selection
测试设备选择?
├─ 真机(推荐 Pixel 系列)
│ ├─ Magisk 刷入 → systemless root
│ ├─ 启用 Zygisk + DenyList → Root 隐藏
│ └─ 保留原始 boot.img → OTA 恢复
├─ Android Studio 模拟器
│ ├─ x86 镜像 + ARM 翻译层(速度优先)
│ └─ Google APIs 镜像(需 Play Store 测试时)
└─ Genymotion(免费个人版 + VirtualBox)
└─ Bridge 网络模式 → 方便从其他 VM 连接
Core toolchain
| Tool | Purpose | Installation |
|---|---|---|
| adb | Device communication/installation/debugging | Android SDK Platform Tools |
| jadx / jadx-gui | APK decompilation to Java | brew install jadx |
| apktool | Decompilation to Smali / resource extraction | brew install apktool |
| Frida + frida-tools | Dynamic Hook / runtime analysis | pip install frida-tools |
| objection | Frida automation wrapper | pip install objection |
| Drozer | Component security testing | GitHub Release |
| Burp Suite | Traffic interception | PortSwigger |
| MobSF | Automated static + dynamic analysis | Docker deployment |
| APKiD | Identify compiler/packer/obfuscation | pip install apkid |
APK acquisition
# 从设备提取
adb shell pm list packages | grep target
adb shell pm path com.target.app
adb pull /data/app/com.target.app-.../base.apk
# 多 Split APK 合并
mkdir splits
adb shell pm path com.target.app | cut -d ':' -f 2 | xargs -n1 -I{} adb pull {} splits/
java -jar APKEditor.jar m -i splits/ -o merged.apk
java -jar uber-apk-signer.jar -a merged.apk --allowResign -o merged_signed
# 在线下载
# APKPure / APKMirror / APKCombo / apkd (GitHub)
# justapk: pip install justapk
justapk download com.target.app
justapk convert app.xapk -o output/
Phase 1: APK static analysis
Decompilation and code audit
反编译路径选择?
├─ 需要 Java 源码审计 → jadx -d output/ target.apk
├─ 需要修改并重打包 → apktool d target.apk -o decoded/
├─ React Native 应用 → 解压 assets/index.android.bundle
├─ Xamarin 应用 → 解压 assemblies/ → dnSpy / ILSpy
└─ 加壳应用 → APKiD 识别壳类型 → 对应脱壳方案
# jadx 反编译
jadx -d jadx_output/ target.apk
# 搜索敏感信息
grep -rn "password\|api_key\|secret\|token\|firebase" jadx_output/
# apktool 反编译(Smali 级别)
apktool d target.apk -o apktool_output/
# APKiD 识别保护方案
apkid target.apk
Manifest.xml audit points
# 提取 Manifest
aapt dump xmltree target.apk AndroidManifest.xml
Key check items:
| Attribute | Risk | Impact |
|---|---|---|
android:debuggable="true" |
High | Debugger can be attached/application data can be read |
android:allowBackup="true" |
Medium | adb backup can extract application data |
android:exported="true" |
High | Component can be invoked externally |
android:usesCleartextTraffic="true" |
Medium | Allows cleartext HTTP |
targetSdkVersion < 24 |
Low | Trusts user-installed CAs by default; for >=24, by default only trusts system CAs, need to check Network Security Config |
String and key search
# APK 中的 URL
apkurlgrep -a target.apk
# 泄露的密钥/凭据
apkleaks -f target.apk
# Firebase 数据库检测
grep -rn "firebaseio.com" jadx_output/
# 尝试访问: curl https://xxx.firebaseio.com/.json
Automated static analysis
# MobSF 静态分析
docker run -it -p 8000:8000 opensecurity/mobile-security-framework-mobsf:latest
# 上传 APK → 自动生成报告
# mariana-trench (Facebook)
# 基于 source-sink 规则的漏洞扫描
mariana-trench --apk-path target.apk --output results/
Phase 2: Dynamic analysis (Frida)
Frida basic operations
# 查看运行中的应用
frida-ps -Uai
# 附加到进程
frida -U -f com.target.app
# 使用脚本注入
frida -U -f com.target.app -l hook.js
Common Hook scenarios
动态分析目标?
├─ SSL Pinning 绕过 → Phase 6 详述
├─ Root 检测绕过 → Phase 7 详述
├─ 加密算法监控 → Hook javax.crypto.Cipher
├─ 敏感 API 监控 → Hook 文件/网络/短信/位置 API
├─ 生物认证绕过 → Hook BiometricPrompt
└─ 内存中搜索敏感数据 → Fridump
Memory Dump and search
# Fridump 内存提取
python3 fridump3.py -u com.target.app
# 搜索敏感数据
strings dump/* | grep -E "password|token|Bearer"
# 搜索助记词
strings dump/* | grep -E "^[a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+$"
Keystore audit
# Hook Keystore 操作
frida -U -f com.target.app -l tracer-cipher.js
# 脚本来源: github.com/WithSecureLabs/android-keystore-audit
Phase 3: Component security testing
Component exposure surface enumeration
# Drozer 枚举
dz> run app.package.attacksurface com.target.app
# 输出: X activities exported, Y services exported, ...
Activity security
Exported Activity 测试?
├─ 直接启动 → adb shell am start -n com.target.app/.SensitiveActivity
├─ 是否绕过认证直接访问敏感页面?
│ ├─ 是 → 认证绕过漏洞
│ └─ 否 → 检查 Intent 参数注入
├─ Activity 是否返回敏感数据? → setResult() 泄露
└─ Tapjacking 测试 → filterTouchesWhenObscured / onFilterTouchEventForSecurity / overlay 遮挡触摸处理
Content Provider security
# 枚举 Provider
dz> run app.provider.info -a com.target.app
# SQL 注入测试
dz> run app.provider.query content://com.target.app.provider/users --projection "* FROM sqlite_master--"
# 路径穿越测试
dz> run app.provider.read content://com.target.app.provider/../../../../etc/hosts
# 文件 Provider 检查
dz> run scanner.provider.traversal -a com.target.app
Service / Broadcast Receiver
# Service 枚举与交互
dz> run app.service.info -a com.target.app
dz> run app.service.start --action com.target.app.ACTION --component com.target.app/.MyService
# Broadcast 测试
dz> run app.broadcast.info -a com.target.app
dz> run app.broadcast.send --action com.target.app.CUSTOM_ACTION --extra string data "test"
Deep Link / URL Scheme
# 枚举 scheme
grep -rn "android:scheme" apktool_output/AndroidManifest.xml
# 触发 deep link
adb shell am start -a android.intent.action.VIEW -d "scheme://hostname/path?param=value"
# 检查点:
# 1. 参数是否接受路径穿越 → ../../unwanted-endpoint
# 2. 是否传递敏感数据(密码/token)通过 URL 参数
# 3. 是否存在 Open Redirect
Phase 4: Data storage security
Checklist
数据存储位置?
├─ SharedPreferences → /data/data/pkg/shared_prefs/*.xml
│ └─ 是否存储明文密码/token?
├─ SQLite 数据库 → /data/data/pkg/databases/*.db
│ └─ 是否加密? 密钥是否硬编码?
├─ 内部存储 → /data/data/pkg/files/
│ └─ MODE_WORLD_READABLE/WRITABLE?
├─ 外部存储 → /sdcard/ (全局可读写)
│ └─ 是否存储敏感数据?
├─ Keystore → Android Keystore System
│ └─ 密钥是否绑定设备? 是否需要认证?
└─ 后台截图 → /data/system_ce/0/snapshots/
└─ FLAG_SECURE 是否设置?
# 检查 SharedPreferences
adb shell run-as com.target.app cat /data/data/com.target.app/shared_prefs/*.xml
# 检查数据库
adb shell run-as com.target.app ls /data/data/com.target.app/databases/
# 拉取并用 sqlite3 检查
adb pull /data/data/com.target.app/databases/app.db
sqlite3 app.db ".tables"
sqlite3 app.db ".schema users"
sqlite3 app.db "SELECT * FROM users;"
# 检查文件权限
adb shell run-as com.target.app ls -la /data/data/com.target.app/files/
Phase 5: Network communication security
Traffic capture configuration
流量抓取方案?
├─ 应用 targetSdkVersion < 24 → 默认信任用户安装的 CA,可直接设置 WiFi 代理到 Burp
├─ 应用 targetSdkVersion >= 24 → 默认不信任用户 CA,需检查/修改 Network Security Config
│ ├─ 修改 network_security_config.xml 信任 user certificates
│ └─ 重打包签名安装,或把 Burp CA 装入系统证书区(需 root)
├─ Flutter 应用 → 可能使用独立 TLS/CA 逻辑,需额外处理
│ └─ 参考 flutter SSL pinning bypass
└─ 非 HTTP 流量 → tcpdump / iptables 转发
# 安装 Burp CA 到系统(需 root)
# 导出 Burp CA → DER 格式 → 转 PEM
openssl x509 -inform DER -in cacert.der -out cacert.pem
# 计算 hash
HASH=$(openssl x509 -inform PEM -subject_hash_old -in cacert.pem | head -1)
cp cacert.pem /system/etc/security/cacerts/${HASH}.0
chmod 644 /system/etc/security/cacerts/${HASH}.0
# 修改 network_security_config.xml(targetSdkVersion >= 24 时常见)
# 在 res/xml/network_security_config.xml 中添加:
# <trust-anchors><certificates src="user" /></trust-anchors>
SSL Pinning detection and bypass
SSL Pinning 类型?
├─ OkHttp CertificatePinner → Frida Hook
├─ 自定义 TrustManager → Frida Hook
├─ Network Security Config → 修改 XML 重打包
├─ WebView SSL 处理 → Hook WebViewClient
└─ 未知实现 → SSLPinDetect 静态扫描定位
# 静态检测 Pinning 实现
python sslpindetect.py -f target.apk -a apktool.jar
# apk-mitm 自动绕过(无需 root)
npx apk-mitm target.apk
# objection 绕过
objection --gadget com.target.app explore --startup-command "android sslpinning disable"
# Frida 绕过(通用脚本)
frida -U -f com.target.app -l ssl-pinning-bypass.js
Phase 6: Protection mechanism bypass
Root detection bypass
Root 检测机制?
├─ 文件检查 (/su, /system/xbin/su, Cydia 等)
│ └─ Magisk DenyList 隐藏
├─ SafetyNet / Play Integrity
│ └─ 硬件级别 attestation 难以绕过
│ └─ 基本 attestation → Play Integrity Fix (Zygisk 模块)
├─ RootBeer / 自定义检测库
│ └─ Frida Hook 返回值
└─ 系统属性检查 (ro.debuggable, ro.secure)
└─ MagiskHide Props Config
# objection 绕过 root 检测
objection --gadget com.target.app explore --startup-command "android root disable"
# Frida Hook 通用 root 检测绕过
frida -U -f com.target.app -l anti-root.js
Emulator detection bypass
# 检测点: Build.FINGERPRINT, Build.MODEL, CPU_ABI, /dev/qemu_pipe
# Frida Hook Build 类属性
Anti-debugging/anti-Frida bypass
反 Frida 检测方式?
├─ 检查 frida-server 端口 (27042)
│ └─ 更改监听端口: frida-server -l 0.0.0.0:1234
├─ 检查 /proc/self/maps 中的 frida 库
│ └─ 使用 linjector 注入(无 ptrace)
├─ 检查 D-Bus 协议特征
│ └─ 使用自编译 Frida gadget
└─ 自杀式 kill(getpid()) 反分析
└─ Hook Process.killProcess / exit
Screenshot/screen recording protection bypass
# 关闭 FLAG_SECURE,便于截图、录屏和动态分析记录
objection --gadget com.target.app explore -s "android ui FLAG_SECURE false"
Biometric authentication bypass
# Frida 绕过指纹
frida --codeshare krapgras/android-biometric-bypass-update-android-11 -U -f com.target.app
Phase 7: Client-side injection vulnerabilities
WebView security
WebView 配置检查?
├─ JavaScript 启用 → setJavaScriptEnabled(true) → XSS 风险
├─ File 协议访问 → setAllowFileAccess(true) → LFI 风险
├─ addJavascriptInterface → RCE(API < 17)
└─ WebViewClient 证书处理 → 忽略 SSL 错误?
SQL injection
- Content Provider's query/insert/update/delete methods
- Whether custom database operations are parameterized
Intent injection
- Proxy Activity/Service directly calls after receiving Intent
startActivity() - WebView URL via
Intent.parseUri()Analysis → Malicious Intent Construction
Automated Analysis Tools Quick Reference
| Tool | Type | Usage |
|---|---|---|
| MobSF | Static+Dynamic | Docker deployment, Web UI |
| Qark | Static | qark --apk target.apk |
| AndroBugs | Static | python androbugs.py -f target.apk |
| SUPER | Static | super-analyzer target.apk |
| Androwarn | Static (behavior) | python androwarn.py -i target.apk -r html |
| mariana-trench | Static (data flow) | mariana-trench --apk-path target.apk |
| ReverseAPK | Static | reverse-apk target.apk |
Malware Analysis Key Points
When analyzing suspicious APKs rather than penetration testing, additionally focus on:
- Native so library loading chain:
System.loadLibrary→ Decrypt second-layer ELF →InMemoryDexClassLoaderFileless DEX InMemoryDexClassLoaderUse → In-memory DEX loading (Frida Hook dump)AccessibilityServiceAbuse → Overlay attack / ACTION_SET_TEXT hijacking- FCM as C2 channel → Check Firebase message trigger conditions
- Foreground Service + MediaPlayer persistence → Process keep-alive