--- name: android-native-lib-analysis description: Reverse Android native libraries (.so/JNI) and DEX/smali internals — extract libs, locate JNI entry points, find secrets/crypto/root-and-pinning logic moved to native, reverse in Ghidra/radare2, and hook exports with Frida. Tier 1 (detection) / Tier 2 for exploitation. Use when logic or secrets live in native code. Aligns to OWASP MASTG. --- # Android Native Library (.so) & DEX/Smali Analysis Secrets and security checks pushed into C/C++ are still recoverable. Extract, reverse, and hook the native layer. ## Trigger phrases `native lib, .so, jni, libnative, ghidra, radare2, r2, native pinning, native root check, ndk, frida native hook` ## Method 1. **Extract libs:** `unzip -o app.apk 'lib/*' -d libs` (per-ABI: `arm64-v8a`, `armeabi-v7a`, `x86_64`). 2. **Quick triage:** - `strings libs/arm64-v8a/libnative.so | grep -iE "key|http|/data/|secret|su|frida|magisk"` - `nm -D libs/arm64-v8a/libnative.so` — exported symbols; look for `Java_*` (JNI entry points). 3. **Static reverse:** load in Ghidra (headless or GUI) or `r2 -A libs/arm64-v8a/libnative.so`; find JNI functions, crypto routines, root/emulator/pinning checks implemented natively, and embedded secrets. 4. **Dynamic hook** (confirm/bypass behavior): ``` frida -U -n -e 'Interceptor.attach(Module.findExportByName("libnative.so","target"),{onEnter(a){console.log(a[0])},onLeave(r){console.log(r)}})' ``` Hook JNI args/returns, force return values for native root/pinning checks. ## Modern / rare techniques - **[RARE] Native root/pinning/anti-debug logic** — many apps move `isRooted()`/cert pinning into `.so` to defeat objection; hook the specific native export or patch the branch (chains to `android-root-antidebug-bypass`, `android-ssl-pinning-bypass`). - **BoringSSL `SSL_CTX_set_custom_verify`** hook for native TLS (also the Flutter path — `android-crossplatform-flutter-rn-xamarin`). - **JNI `RegisterNatives`** — functions registered dynamically have no `Java_*` symbol; find them by hooking `RegisterNatives` with Frida to recover the native method table. ## Bypass / evasion For stripped/obfuscated libs, resolve functions by offset (`Module.getBaseAddress` + offset) instead of name; use Frida stalker/`Interceptor` on the computed address. ## Escalation / chaining Native secrets → `android-secrets-hardcoded`; native pinning → `android-ssl-pinning-bypass`; native crypto → `android-crypto-keystore`; drives `android-frida-objection-instrumentation`. ## Backend & tooling Preferred Kali path (native Kali / WSL+Kali / Kali-SSH / Kali-MCP / HexStrike). Needs the user's device/emulator (Frida-server matching device arch) + Kali tooling (Ghidra/radare2/objdump/nm/Frida). Windows-local last resort. See `zazy-orchestrator`. ## Verification (background, before reporting) Confirm a native-recovered secret/check independently — a Frida hook demonstrating the altered behavior, or the extracted key authenticating to its service — before marking CONFIRMED. ## Evidence The disassembly/decompilation of the relevant native function, extracted secret or check logic, and the Frida hook output confirming behavior. Remediation: don't treat native as a secret store; combine with attestation; obfuscate but assume reversible.