# Android Anti-Instrumentation & SSL Pinning Bypass (Frida/Objection) {{#include ../../banners/hacktricks-training.md}} Ova stranica daje praktičan workflow za povraćaj dinamičke analize nad Android aplikacijama koje detektuju/sprečavaju instrumentation zbog root-a ili nameću TLS pinning. Fokusira se na brzu trijažu, uobičajene detekcije i kopiraj‑zalepi hookove/taktike za zaobilaženje bez repackovanja kad je to moguće. ## Detection Surface (what apps check) - Root checks: su binary, Magisk paths, getprop values, common root packages - Frida/debugger checks (Java): Debug.isDebuggerConnected(), ActivityManager.getRunningAppProcesses(), getRunningServices(), scanning /proc, classpath, loaded libs - Native anti‑debug: ptrace(), syscalls, anti‑attach, breakpoints, inline hooks - Early init checks: Application.onCreate() or process start hooks that crash if instrumentation is present - TLS pinning: custom TrustManager/HostnameVerifier, OkHttp CertificatePinner, Conscrypt pinning, native pins ## Step 1 — Quick win: hide root with Magisk DenyList - Enable Zygisk in Magisk - Enable DenyList, add the target package - Reboot and retest Mnoge aplikacije traže samo očigledne indikatore (su/Magisk paths/getprop). DenyList često neutralizuje naivne provere. References: - Magisk (Zygisk & DenyList): https://github.com/topjohnwu/Magisk ## Step 2 — 30‑second Frida Codeshare tests Probaj uobičajene drop‑in skripte pre nego što kreneš u dublju analizu: - anti-root-bypass.js - anti-frida-detection.js - hide_frida_gum.js Example: ```bash frida -U -f com.example.app -l anti-frida-detection.js ``` Oni obično stubuju Java root/debug checks, process/service scans i native ptrace(). Korisno za slabo zaštićene apps; hardened targets mogu zahtevati tailored hooks. - Codeshare: https://codeshare.frida.re/ ## Korak 3 — Zaobiđite detektore pri inicijalizaciji priključivanjem kasnije Mnoga detekcija se izvršavaju samo tokom process spawn/onCreate(). Spawn‑time injection (-f) ili gadgets bivaju otkriveni; priključivanje nakon učitavanja UI‑a može promaći. ```bash # Launch the app normally (launcher/adb), wait for UI, then attach frida -U -n com.example.app # Or with Objection to attach to running process aobjection --gadget com.example.app explore # if using gadget ``` Ako ovo radi, održi sesiju stabilnom i nastavi sa mapiranjem i stub proverama. ## Korak 4 — Mapiraj logiku detekcije preko Jadx i pretragom stringova Ključne reči za statičku trijažu u Jadx: - "frida", "gum", "root", "magisk", "ptrace", "su", "getprop", "debugger" Tipični Java obrasci: ```java public boolean isFridaDetected() { return getRunningServices().contains("frida"); } ``` Uobičajeni API-jevi za review/hook: - android.os.Debug.isDebuggerConnected - android.app.ActivityManager.getRunningAppProcesses / getRunningServices - java.lang.System.loadLibrary / System.load (native bridge) - java.lang.Runtime.exec / ProcessBuilder (probing commands) - android.os.SystemProperties.get (root/emulator heuristics) ## Korak 5 — Runtime stubbing with Frida (Java) Override custom guards da vraćaju sigurne vrednosti bez repacking-a: ```js Java.perform(() => { const Checks = Java.use('com.example.security.Checks'); Checks.isFridaDetected.implementation = function () { return false; }; // Neutralize debugger checks const Debug = Java.use('android.os.Debug'); Debug.isDebuggerConnected.implementation = function () { return false; }; // Example: kill ActivityManager scans const AM = Java.use('android.app.ActivityManager'); AM.getRunningAppProcesses.implementation = function () { return java.util.Collections.emptyList(); }; }); ``` Trijaža ranih padova? Dump-ujte klase neposredno pre nego što aplikacija padne da biste uočili verovatne detection namespaces: ```js Java.perform(() => { Java.enumerateLoadedClasses({ onMatch: n => console.log(n), onComplete: () => console.log('Done') }); }); ``` Zabeležite i onesposobite sumnjive metode da potvrdite tok izvršavanja: ```js Java.perform(() => { const Det = Java.use('com.example.security.DetectionManager'); Det.checkFrida.implementation = function () { console.log('checkFrida() called'); return false; }; }); ``` ## Korak 6 — Pratite JNI/native trag kada Java hooks zakažu Pratite JNI ulazne tačke da biste pronašli native loaders i detection init: ```bash frida-trace -n com.example.app -i "JNI_OnLoad" ``` Brza nativna trijaža priloženih .so datoteka: ```bash # List exported symbols & JNI nm -D libfoo.so | head objdump -T libfoo.so | grep Java_ strings -n 6 libfoo.so | egrep -i 'frida|ptrace|gum|magisk|su|root' ``` Interaktivno / native reversing: - Ghidra: https://ghidra-sre.org/ - r2frida: https://github.com/nowsecure/r2frida Primer: onesposobiti ptrace da bi se zaobišao jednostavan anti‑debug u libc: ```js const ptrace = Module.findExportByName(null, 'ptrace'); if (ptrace) { Interceptor.replace(ptrace, new NativeCallback(function () { return -1; // pretend failure }, 'int', ['int', 'int', 'pointer', 'pointer'])); } ``` Vidi takođe: {{#ref}} reversing-native-libraries.md {{#endref}} ## Korak 7 — Objection patching (embed gadget / strip basics) Ako više volite repacking umesto runtime hooks, pokušajte: ```bash objection patchapk --source app.apk ``` Napomene: - Zahteva apktool; obezbedite aktuelnu verziju iz zvaničnog vodiča da biste izbegli probleme pri buildovanju: https://apktool.org/docs/install - Gadget injection omogućava instrumentation bez root-a, ali može biti otkrivena jačim init‑time checks. References: - Objection: https://github.com/sensepost/objection ## Korak 8 — Plan B: Uklonite TLS pinning radi vidljivosti mreže Ako je instrumentation blokirana, i dalje možete da pregledate saobraćaj tako što ćete statički ukloniti pinning: ```bash apk-mitm app.apk # Then install the patched APK and proxy via Burp/mitmproxy ``` - Alat: https://github.com/shroudedcode/apk-mitm - Za trikove vezane za network config CA‑trust (i Android 7+ user CA trust), vidi: {{#ref}} make-apk-accept-ca-certificate.md {{#endref}} {{#ref}} install-burp-certificate.md {{#endref}} ## Koristan spisak komandi ```bash # List processes and attach frida-ps -Uai frida -U -n com.example.app # Spawn with a script (may trigger detectors) frida -U -f com.example.app -l anti-frida-detection.js # Trace native init frida-trace -n com.example.app -i "JNI_OnLoad" # Objection runtime objection --gadget com.example.app explore # Static TLS pinning removal apk-mitm app.apk ``` ## Saveti i napomene - Preferirajte attach kasnije umesto spawn-ovanja kada apps crash-uju pri launch-u - Neki detections se ponovo pokreću u kritičnim flow-ovima (npr. payment, auth) — držite hooks aktivnim tokom navigacije - Mešajte static i dynamic: string hunt u Jadx da suzite listu klasa; zatim hook-ujte metode da verifikujete u runtime-u - Hardened apps mogu koristiti packers i native TLS pinning — očekujte da reverse-ujete native code ## Reference - [Reversing Android Apps: Bypassing Detection Like a Pro](https://www.kayssel.com/newsletter/issue-12/) - [Frida Codeshare](https://codeshare.frida.re/) - [Objection](https://github.com/sensepost/objection) - [apk-mitm](https://github.com/shroudedcode/apk-mitm) - [Jadx](https://github.com/skylot/jadx) - [Ghidra](https://ghidra-sre.org/) - [r2frida](https://github.com/nowsecure/r2frida) - [Apktool install guide](https://apktool.org/docs/install) - [Magisk](https://github.com/topjohnwu/Magisk) {{#include ../../banners/hacktricks-training.md}}