Frida and Dynamic Analysis
Frida is the central tool of dynamic mobile pentesting: an instrumentation toolkit that injects a JavaScript engine into a running app’s process, letting you intercept and modify function calls, read and change variables in memory, bypass checks (root/jailbreak detection, SSL pinning), and understand what the app does internally in real time. It’s what turns “reading the code” into “controlling the app while it runs.”
flowchart LR
PC["Host: frida CLI"] -->|USB| SRV["frida-server / gadget"]
SRV --> PROC["App process"]
PROC --> JAVA["Java/ART runtime"]
PROC --> NAT["Native .so libraries"]
PROC --> OBJC["Objective-C runtime"]
JAVA --> HOOK["Hooks: args, return, memory"]
NAT --> HOOK
OBJC --> HOOK
Threat model
Section titled “Threat model”Frida lives off the fact that the client is manipulable: anyone with the device (root/jailbreak or an injected gadget) can rewrite the app’s behaviour at runtime. That breaks any control that relies on the client alone:
- Bypass of local protections: SSL pinning, root/jailbreak detection, biometrics, or a PIN checked locally.
- Secret extraction in memory: encryption keys, decrypted data, and tokens that never touch disk.
- Logic manipulation: force
isPremium=true, skip validations, change amounts before the request is signed. - Discovery of the internal flow to build the real attack against the backend.
The defensive conclusion is direct: everything critical is validated on the server; the client is only a convenience.
What it enables
Section titled “What it enables”- Hooking: intercept any function (Java/ART, native, Objective-C/Swift) before and after it runs.
- Read and modify arguments, return values, and variables in memory.
- Call the app’s internal functions from outside.
- Bypass checks: root/jailbreak detection, SSL pinning, anti-debugging.
- Dump secrets: keys, decrypted data, and live tokens in memory.
Installation and startup
Section titled “Installation and startup”# on the hostpip install frida-tools# Android (root): push a frida-server matching the frida versionadb push frida-server /data/local/tmp/adb shell "chmod 755 /data/local/tmp/frida-server && /data/local/tmp/frida-server &"# iOS (jailbreak): install the Frida package from Sileo/Cydia# list device processes/apps (USB)frida-ps -U # processesfrida-ps -Uai # installed apps with their identifierWithout root/jailbreak you use the gadget (a Frida library injected into the re-signed app, e.g. with objection patchapk/patchipa).
Objection: Frida without writing scripts
Section titled “Objection: Frida without writing scripts”Objection wraps Frida with ready-made commands for the most common tasks:
objection -g com.target.app explore# inside the REPL:android hooking list classes # list loaded classesandroid hooking watch class com.target.Crypto --dump-args --dump-returnandroid sslpinning disable # bypass SSL pinningandroid root disable # bypass root detectionandroid keystore list # inspect the keystorememory search --string "password" # search memoryObjection is the starting point; for specific logic you write custom Frida scripts.
Frida scripts (custom hooking)
Section titled “Frida scripts (custom hooking)”Hook a Java method on Android, intercept it, and force its return value:
Java.perform(function () { const Login = Java.use("com.target.LoginManager"); Login.checkPassword.implementation = function (pw) { console.log("[+] entered password: " + pw); // intercept the argument return true; // force login OK };});Hook a native function (.so) and see its arguments:
const addr = Module.getExportByName("libnative.so", "verify_signature");Interceptor.attach(addr, { onEnter(args) { console.log("[*] verify_signature arg0=", args[0]); }, onLeave(ret) { console.log("[*] ret=", ret); ret.replace(ptr(1)); }});Hook an Objective-C method on iOS and force true:
const m = ObjC.classes.LoginManager["- isValidSession"];Interceptor.attach(m.implementation, { onLeave(ret) { ret.replace(ptr(0x1)); } // force a true return value});Run a script by spawning the app:
frida -U -f com.target.app -l script.js --no-pausePentest use cases
Section titled “Pentest use cases”Always against an app you own or have permission to test:
- Bypass client protections (which must never be the only security): SSL pinning (see SSL Pinning and Bypass), root/jailbreak detection, local biometrics/PIN.
- Extract secrets at runtime: encryption keys, decrypted data, tokens in memory.
- Understand and force logic: change return values (
isPremium -> true), skip validations. - Discover the internal flow and feed the backend attack (Web Methodology).
Detection and anti-Frida
Section titled “Detection and anti-Frida”Some apps detect Frida (default ports like 27042, thread names gum-js-loop/gmain, strings frida or LIBFRIDA in mapped memory) or use anti-debugging (ptrace). It can be evaded (anti-anti-Frida scripts, renaming frida-server, using a gadget on a non-standard port), but remember: these protections raise the cost, they don’t replace backend security.
Red Team
Section titled “Red Team”# typical flow of a dynamic sessionfrida-ps -Uai # identify the appobjection -g com.target.app explore # quick exploration + bypassfrida -U -f com.target.app -l unpin.js --no-pause # unpinning script on spawn# from there, intercept in Burp and attack the API like a web appBlue Team
Section titled “Blue Team”- Don’t trust client-side checks (pinning, root/jailbreak, local biometrics): a Frida-equipped attacker bypasses them. Real security lives in the backend.
- MASVS-RESILIENCE: instrumentation/Frida detection, anti-debugging, code integrity, and obfuscation as layers that raise the attack cost, not as an absolute barrier.
- Minimise sensitive data in memory/client; encrypt with non-extractable keys (hardware-backed Android Keystore / Secure Enclave).
- Assume a compromised device: always validate and authorize on the server.
Checklist
Section titled “Checklist”- frida-server/gadget running and app detected (
frida-ps) - Objection: explore, list classes, basic hooks
- Bypass SSL pinning (SSL Pinning and Bypass) and root/jailbreak
- Custom hooks: intercept key arguments and return values
- Extract secrets/keys/decrypted data in memory
- Force logic (isPremium, validations, login)
- Evade anti-Frida if the app implements it
- Use what you learned to attack the backend (Web Methodology)