Frida ํํ ๋ฆฌ์ผ
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
์ค์น
frida tools ์ค์น:
pip install frida-tools
pip install frida
๋ค์ด๋ก๋ํ๊ณ ์ค์นํ์ธ์ android์ frida server (Download the latest release).
adb๋ฅผ root ๋ชจ๋๋ก ์ฌ์์ํ๊ณ ์ฐ๊ฒฐํ ๋ค frida-server๋ฅผ ์
๋ก๋ํ๊ณ ์คํ ๊ถํ์ ๋ถ์ฌํ์ฌ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์คํํ๋ ํ ์ค ๋ช
๋ น:
adb root; adb connect localhost:6000; sleep 1; adb push frida-server /data/local/tmp/; adb shell "chmod 755 /data/local/tmp/frida-server"; adb shell "/data/local/tmp/frida-server &"
ํ์ธ ๊ทธ๊ฒ์ด ์๋ํ๋์ง:
frida-ps -U #List packages and processes
frida-ps -U | grep -i <part_of_the_package_name> #Get all the package name
frida-ui (๋ธ๋ผ์ฐ์ ๊ธฐ๋ฐ Frida ์ปจํธ๋กค๋ฌ)
frida-ui๋ http://127.0.0.1:8000์์ devices/apps๋ฅผ ๋์ดํ๊ณ scripts๋ก targets์ attachํ๊ฑฐ๋ spawnํ ์ ์๋ ์น UI๋ฅผ ์ ๊ณตํฉ๋๋ค (CLI ๋ถํ์).
- ์ค์น (device server ๋ฒ์ ์ ๋ง๊ฒ
frida๋ฅผ ๊ณ ์ ):
uv tool install frida-ui --with frida==16.7.19
# pipx install frida-ui
# pip install frida-ui
- ์คํ:
frida-ui
frida-ui --host 127.0.0.1 --port 8000 --reload
- ๊ธฐ๋ฅ: USB/๋ก์ปฌ ์ฅ์น ๊ฒ์, ์๊ฒฉ ์๋ฒ ์ถ๊ฐ (
192.168.1.x:27042), ๊ทธ๋ฆฌ๊ณ Attach, Spawn, Spawn & Run (์ด๊ธฐonCreate()๋ก์ง ์ด์ ์ ํ ์ ๊ฑธ๊ธฐ ์ํด)์ ์ง์ํฉ๋๋ค. - ์คํฌ๋ฆฝํ
: ํธ์ง๊ธฐ,
.js๋๋๊ทธ ์ค ๋๋กญ, CodeShare ๊ฐ์ ธ์ค๊ธฐ, ์คํฌ๋ฆฝํธ ๋ฐ ์ธ์ ๋ก๊ทธ ๋ค์ด๋ก๋. - ์๊ฒฉ ์๋ฒ:
./frida-server -l 0.0.0.0:27042 -D๋ ๋คํธ์ํฌ์ ๋ ธ์ถ์์ผ frida-ui๊ฐ ADB ์์ด ์ฐ๊ฒฐํ ์ ์๊ฒ ํฉ๋๋ค.
Frida server vs. Gadget (root vs. no-root)
Frida๋ก Android ์ฑ์ ๊ณ์ธกํ๋ ๋ ๊ฐ์ง ์ผ๋ฐ์ ์ธ ๋ฐฉ๋ฒ:
- Frida server (rooted devices): ๋ค์ดํฐ๋ธ ๋ฐ๋ชฌ์ ํธ์ํ๊ณ ์คํํ์ฌ ์ด๋ค ํ๋ก์ธ์ค์๋ attachํ ์ ์๊ฒ ํฉ๋๋ค.
- Frida Gadget (no root): Frida๋ฅผ APK ๋ด๋ถ์ ๊ณต์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก ๋ฒ๋คํ๊ณ ๋์ ํ๋ก์ธ์ค์์ ์๋์ผ๋ก ๋ก๋ํฉ๋๋ค.
Frida server (rooted)
# Download the matching frida-server binary for your device's arch
# https://github.com/frida/frida/releases
adb root
adb push frida-server-<ver>-android-<arch> /data/local/tmp/frida-server
adb shell chmod 755 /data/local/tmp/frida-server
adb shell /data/local/tmp/frida-server & # run at boot via init/magisk if desired
# From host, list processes and attach
frida-ps -Uai
frida -U -n com.example.app
Frida Gadget (no-root)
- APK์ ์์ถ์ ํ๊ณ gadget .so์ ์ค์ ์ ์ถ๊ฐ:
- libfrida-gadget.so๋ฅผ
lib/<abi>/(e.g., lib/arm64-v8a/)์ ๋ฃ์ต๋๋ค - assets/frida-gadget.config๋ฅผ ์คํฌ๋ฆฝํธ ๋ก๋ฉ ์ค์ ์ผ๋ก ์์ฑํฉ๋๋ค
Example frida-gadget.config
{
"interaction": { "type": "script", "path": "/sdcard/ssl-bypass.js" },
"runtime": { "logFile": "/sdcard/frida-gadget.log" }
}
- gadget๋ฅผ ์ฐธ์กฐ/๋ก๋ํ์ฌ ์กฐ๊ธฐ์ ์ด๊ธฐํ๋๋๋ก ํจ:
- ๊ฐ์ฅ ์ฌ์ด ๋ฐฉ๋ฒ: Application.onCreate()์ System.loadLibrary(โfrida-gadgetโ)๋ฅผ ํธ์ถํ๋ ์์ Java ์คํ ์ ์ถ๊ฐํ๊ฑฐ๋, ์ด๋ฏธ ์กด์ฌํ๋ ๋ค์ดํฐ๋ธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ก๋ฉ์ ์ฌ์ฉํ์ธ์.
- APK๋ฅผ ์ฌํจํค์งํ๊ณ ์๋ช ํ ๋ค์ ์ค์น:
apktool d app.apk -o app_m
# ... add gadget .so and config ...
apktool b app_m -o app_gadget.apk
uber-apk-signer -a app_gadget.apk -o out_signed
adb install -r out_signed/app_gadget-aligned-debugSigned.apk
- host์์ gadget ํ๋ก์ธ์ค์ Attach:
frida-ps -Uai
frida -U -n com.example.app
Notes
- Gadget๋ ์ผ๋ถ ๋ณดํธ ๋ฉ์ปค๋์ฆ์ ์ํด ํ์ง๋ฉ๋๋ค; ํ์ ์ ์ด๋ฆ/๊ฒฝ๋ก๋ฅผ ์๋ฐํ๊ฒ ํ๊ณ ๋ฆ๊ฒ/์กฐ๊ฑด๋ถ๋ก ๋ก๋ํ์ธ์.
- ํ๋๋๋ ์ฑ์์๋ rooted ํ ์คํธ๋ฅผ server + late attach๋ก ์ํํ๋ ๊ฒ์ ๊ถ์ฅํ๊ฑฐ๋ Magisk/Zygisk ์จ๊น๊ณผ ๊ฒฐํฉํ์ธ์.
JDWP ๊ธฐ๋ฐ Frida ์ฃผ์ (root/repackaging ๋ถํ์) (frida-jdwp-loader)
APK๊ฐ debuggable(android:debuggable=โtrueโ)์ด๋ฉด, JDWP๋ก attachํ์ฌ Java breakpoint์์ native library๋ฅผ injectํ ์ ์์ต๋๋ค. No root ๋ฐ APK repackaging์ด ํ์ ์์ต๋๋ค.
- Repo: https://github.com/frankheat/frida-jdwp-loader
- Requirements: ADB, Python 3, USB/Wireless debugging. App๋ debuggable์ด์ด์ผ ํฉ๋๋ค (emulator์์
ro.debuggable=1, rooted device์์resetprop์ฌ์ฉ, ๋๋ manifest ์ฌ๋น๋).
Quick start:
git clone https://github.com/frankheat/frida-jdwp-loader.git
cd frida-jdwp-loader
# Inject frida-gadget.so into a debuggable target
python frida-jdwp-loader.py frida -n com.example.myapplication
# Keep the breakpoint thread suspended for early hooks
python frida-jdwp-loader.py frida -n com.example.myapplication -s
# Networkless: run a local agent script via Gadget "script" mode
python frida-jdwp-loader.py frida -n com.example.myapplication -i script -l script.js
์ฐธ๊ณ
- ๋ชจ๋: spawn (Application.onCreate์์ ์ค๋จ) ๋๋ attach (Activity.onStart์์ ์ค๋จ). ํน์ Java ๋ฉ์๋๋ฅผ ์ค์ ํ๋ ค๋ฉด
-b๋ฅผ ์ฌ์ฉํ๊ณ , Gadget ๋ฒ์ /๊ฒฝ๋ก๋ฅผ ์ ํํ๋ ค๋ฉด-g, JDWP ํฌํธ๋ฅผ ์ ํํ๋ ค๋ฉด-p๋ฅผ ์ฌ์ฉํฉ๋๋ค. - Listen ๋ชจ๋: ํ์ ์ Gadget์ ํฌ์๋ฉ(๊ธฐ๋ณธ 127.0.0.1:27042):
adb forward tcp:27042 tcp:27042; ๊ทธ๋ฐ ๋ค์frida-ps -H 127.0.0.1:27042. - ์ด ๋ฐฉ๋ฒ์ JDWP ๋๋ฒ๊น ์ ํ์ฉํฉ๋๋ค. ์ํ์ debuggable builds๋ฅผ ๋ฐฐํฌํ๊ฑฐ๋ JDWP๋ฅผ ๋ ธ์ถ์ํค๋ ๊ฒ์ ๋๋ค.
Self-contained agent + Gadget embedding (Frida 17+; automated with Objection)
Frida 17๋ GumJS์์ ๋ด์ฅ๋ Java/ObjC ๋ธ๋ฆฌ์ง๋ฅผ ์ ๊ฑฐํ์ต๋๋ค. ์์ด์ ํธ๊ฐ Java๋ฅผ ํํนํ๋ค๋ฉด, Java bridge๋ฅผ ๋ฒ๋ค์ ํฌํจํด์ผ ํฉ๋๋ค.
- Frida agent (TypeScript)๋ฅผ ์์ฑํ๊ณ Java bridge๋ฅผ ํฌํจํ์ธ์
# Scaffolding
frida-create -t agent -o mod
cd mod && npm install
# Install the Java bridge for Frida 17+
npm install frida-java-bridge
# Dev loop (optional live-reload via REPL)
npm run watch
์ต์ํ์ Java hook (์ฃผ์ฌ์ ๊ตด๋ฆผ์ 1๋ก ๊ฐ์ ):
import Java from "frida-java-bridge";
Java.perform(function () {
var dicer = Java.use("org.secuso.privacyfriendlydicer.dicer.Dicer");
dicer.rollDice.implementation = function (numDice: number, numFaces: number) {
return Array(numDice).fill(1);
};
});
์๋ฒ ๋ฉ์ ์ํ ๋จ์ผ ๋ฒ๋ค ๋น๋:
npm run build # produces _agent.js via frida-compile
๊ฐ๋จํ USB ํ ์คํธ (์ ํ ์ฌํญ):
frida -U -f org.secuso.privacyfriendlydicer -l _agent.js
- Gadget๊ฐ ์คํฌ๋ฆฝํธ๋ฅผ ์๋์ผ๋ก ๋ก๋ํ๋๋ก ๊ตฌ์ฑ Objection์ patcher๋ Gadget config๋ฅผ ๊ธฐ๋ํฉ๋๋ค; script mode๋ฅผ ์ฌ์ฉํ ๋๋ APK lib dir ๋ด๋ถ์ ๋์คํฌ์์ ๊ฒฝ๋ก๋ฅผ ์ง์ ํ์ธ์:
{
"interaction": {
"type": "script",
"path": "libfrida-gadget.script.so"
}
}
- Objection์ผ๋ก APK patching ์๋ํ
# Embed Gadget, config, and your compiled agent into the APK; rebuild and sign
objection patchapk -s org.secuso.privacyfriendlydicer.apk \
-c gadget-config.json \
-l mod/_agent.js \
--use-aapt2
patchapk๊ฐ ํ๋ ์ผ (๊ฐ์):
- ์ฅ์น ABI(์: arm64-v8a)๋ฅผ ๊ฐ์งํ๊ณ ์ผ์นํ๋ Gadget์ ๊ฐ์ ธ์ต๋๋ค
- ํ์ํ ๊ฒฝ์ฐ android.permission.INTERNET ๊ถํ์ ์ ํ์ ์ผ๋ก ์ถ๊ฐํฉ๋๋ค
- launch activity์ System.loadLibrary(โfrida-gadgetโ)๋ฅผ ํธ์ถํ๋ static class initializer๋ฅผ ์ฃผ์ ํฉ๋๋ค
- ๋ค์ ํ์ผ๋ค์
lib/<abi>/์๋์ ๋ฐฐ์นํฉ๋๋ค: - libfrida-gadget.so
- libfrida-gadget.config.so (์ง๋ ฌํ๋ ์ค์ )
- libfrida-gadget.script.so (์ฌ์ฉ์์ _agent.js)
์ฃผ์ ๋ smali ์์ (์ ์ ์ด๊ธฐํ์):
.method static constructor <clinit>()V
.locals 1
const-string v0, "frida-gadget"
invoke-static {v0}, Ljava/lang/System;->loadLibrary(Ljava/lang/String;)V
return-void
.end method
- repack์ ๊ฒ์ฆ
apktool d org.secuso.privacyfriendlydicer.apk
apktool d org.secuso.privacyfriendlydicer.objection.apk
# Inspect differences
diff -r org.secuso.privacyfriendlydicer org.secuso.privacyfriendlydicer.objection
์์ ๋ณ๊ฒฝ ์ฌํญ:
- AndroidManifest.xml์
<uses-permission android:name="android.permission.INTERNET"/>๊ฐ ํฌํจ๋ ์ ์์ - ์์ ๊ฐ์ด
lib/<abi>/์๋์ ์๋ก์ด ๋ค์ดํฐ๋ธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ถ๊ฐ๋จ - Launchable activity์ smali์๋ static
<clinit>๊ฐ ํฌํจ๋์ด ์์ผ๋ฉฐ System.loadLibrary(โfrida-gadgetโ)๋ฅผ ํธ์ถํจ
- Split APKs
- ๊ธฐ๋ณธ APK( the one that declares MAIN/LAUNCHER activity)๋ฅผ ํจ์น
- ๋๋จธ์ง splits๋ฅผ ๋์ผํ ํค๋ก ์ฌ์๋ช :
objection signapk split1.apk split2.apk ...
- splits์ ํจ๊ป ์ค์น:
adb install-multiple split1.apk split2.apk ...
- ๋ฐฐํฌ๋ฅผ ์ํด, splits๋ฅผ APKEditor๋ก ๋จ์ผ APK๋ก ๋ณํฉํ ๋ค์ align/signํ ์ ์์ต๋๋ค
๋์ ๋ถ์ ์ค FLAG_SECURE ์ ๊ฑฐ
getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE)๋ฅผ ํธ์ถํ๋ ์ฑ์ ์คํฌ๋ฆฐ์ท, ์๊ฒฉ ๋์คํ๋ ์ด ๋ฐ ์ฌ์ง์ด Android์ ์ต๊ทผ ์์
์ค๋
์ท์ ์ฐจ๋จํฉ๋๋ค. Freedom Chat๊ฐ ์ด ํ๋๊ทธ๋ฅผ ์ ์ฉํ์ ๋ leaks๋ฅผ ๋ฌธ์ํํ๋ ์ ์ผํ ๋ฐฉ๋ฒ์ ๋ฐํ์์ ์๋์ฐ๋ฅผ ์กฐ์ํ๋ ๊ฒ์ด์์ต๋๋ค. ์ ๋ขฐํ ์ ์๋ ํจํด์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
- ํ๋๊ทธ๋ฅผ ๋ค์ ์ ์ฉํ ์ ์๋ ๋ชจ๋
Window์ค๋ฒ๋ก๋(setFlags,addFlags,setAttributes)๋ฅผ Hookํ๊ณ ๋นํธ0x00002000(WindowManager.LayoutParams.FLAG_SECURE)์ ๋ง์คํฌํฉ๋๋ค. - ๊ฐ activity๊ฐ resume๋ ํ, UI ์ค๋ ๋์์
clearFlags(FLAG_SECURE)๋ฅผ ํธ์ถํ๋๋ก ์์ฝํ์ฌ ์ดํ ์์ฑ๋๋ Dialogs/Fragments๊ฐ ์ ๊ธ ํด์ ๋ ์ํ๋ฅผ ์์๋ฐ๊ฒ ํฉ๋๋ค. - React Native / Flutter๋ก ๋น๋๋ ์ฑ์ ์ข
์ข
์ค์ฒฉ๋ ์๋์ฐ๋ฅผ ์์ฑํฉ๋๋ค; ์ฌ์ ํ black frames๊ฐ ๋ณด์ด๋ฉด
android.app.Dialog/android.view.Viewํฌํผ๋ฅผ hookํ๊ฑฐ๋getWindow().peekDecorView()๋ฅผ ์ํํ์ธ์.
Frida hook clearing Window.FLAG_SECURE
```javascript Java.perform(function () { var LayoutParams = Java.use("android.view.WindowManager$LayoutParams"); var FLAG_SECURE = LayoutParams.FLAG_SECURE.value; var Window = Java.use("android.view.Window"); var Activity = Java.use("android.app.Activity");function strip(value) { var masked = value & (~FLAG_SECURE); if (masked !== value) { console.log(โ[-] Stripped FLAG_SECURE from 0xโ + value.toString(16)); } return masked; }
Window.setFlags.overload(โintโ, โintโ).implementation = function (flags, mask) { return this.setFlags.call(this, strip(flags), strip(mask)); };
Window.addFlags.implementation = function (flags) { return this.addFlags.call(this, strip(flags)); };
Window.setAttributes.implementation = function (attrs) { attrs.flags.value = strip(attrs.flags.value); return this.setAttributes.call(this, attrs); };
Activity.onResume.implementation = function () { this.onResume(); var self = this; Java.scheduleOnMainThread(function () { try { self.getWindow().clearFlags(FLAG_SECURE); console.log(โ[+] Cleared FLAG_SECURE on โ + self.getClass().getName()); } catch (err) { console.log(โ[!] clearFlags failed: โ + err); } }); }; });
</details>
Run the script with `frida -U -f <package> -l disable-flag-secure.js --no-pause`, interact with the UI, and screenshots/recordings will work again. Because everything happens on the UI thread there is no flicker, and you can still combine the hook with HTTP Toolkit/Burp to capture the traffic that revealed the `/channel` PIN leak.
## clsdumper(Frida)๋ฅผ ์ด์ฉํ Dynamic DEX ๋คํ/์ธํจํน
`clsdumper`๋ Frida ๊ธฐ๋ฐ์ ๋์ **DEX/class dumper**๋ก, anti-Frida pre-stage์ native ๋ฐ Java discovery strategies๋ฅผ ๊ฒฐํฉํด ํ๋๋๋ ์ฑ์ ์ฐํํฉ๋๋ค(์ฌ์ง์ด `Java.perform()`์ด ์ฃฝ์ด๋ ๋์). ์๊ตฌ์ฌํญ: Python 3.10+, ๋ฃจํ
๋ ๋๋ฐ์ด์ค์์ `frida-server`๊ฐ ์คํ ์ค์ด์ด์ผ ํ๋ฉฐ, USB ๋๋ `--host` TCP ์ฐ๊ฒฐ์ด ํ์ํฉ๋๋ค.
**์ค์น ๋ฐ ๋น ๋ฅธ ์ฌ์ฉ๋ฒ**
```bash
pip install clsdumper
# Attach to a running app
clsdumper com.example.app
# Spawn first (hooks before early loaders)
clsdumper com.example.app --spawn
# Select strategies
clsdumper com.example.app --strategies fart_dump,oat_extract
CLI ์ต์ (๊ฐ์ฅ ์ ์ฉํ)
target: ํจํค์ง ์ด๋ฆ ๋๋ PID.--spawn: attach ๋์ spawn.--host <ip>: ์๊ฒฉ frida-server์ ์ฐ๊ฒฐ.--strategies <comma>: ์ถ์ถ๊ธฐ ์ ํ/์ ํ; ๊ธฐ๋ณธ๊ฐ์mmap_hook(๋น์ฉ์ด ํผ)์ ์ ์ธํ ๋ชจ๋.--no-scan/--deep-scan: deep ๋ฉ๋ชจ๋ฆฌ ์ค์บ ๋นํ์ฑํ ๋๋ ๋๋ฆฌ๊ฒ ์คํ (CDEX ์ค์บ ์ถ๊ฐ).--extract-classes: androguard๋ฅผ ์ฌ์ฉํด ๋คํ๋ฅผ.smali๋ก ํ์ฒ๋ฆฌ.--no-anti-frida: pre-hook bypass ๋จ๊ณ๋ฅผ ๊ฑด๋๋.--list/--list-apps: ์คํ ์ค์ธ ํ๋ก์ธ์ค ๋๋ ์ค์น๋ ํจํค์ง ๋์ด.
Anti-instrumentation bypass (๋จ๊ณ 0)
sigaction/signal์ ํํฌํ์ฌ crash/anti-debug ํธ๋ค๋ฌ ๋ฑ๋ก์ ์ฐจ๋จ.memfd_create๋ฅผ ํตํด ํํฐ๋ง๋/proc/self/maps๋ฅผ ์ ๊ณตํ์ฌ Frida ์์ญ์ ์จ๊น.pthread_create๋ฅผ ๋ชจ๋ํฐ๋งํ์ฌ Frida๋ฅผ ํ์งํ๋ ์์น๋ ์ค๋ ๋๋ฅผ ํฌ์ฐฉ/๋ฌด๋ ฅํ.
DEX discovery (๋จ๊ณ 1โ2) โ ๋ค์ค ๋ณด์ ์ ๋ต๊ณผ ๊ฐ ์ ์ค์ ๋ํ ๋ฉํ๋ฐ์ดํฐ + ์ค๋ณต ์ ๊ฑฐ(์์ด์ ํธ ์ธก djb2, ํธ์คํธ ์ธก SHA-256):
- Native (Java bridge ๋ถํ์):
art_walk(ART RuntimeโClassLinkerโDexFile ์ํ),open_common_hook(ํํฌDexFile::OpenCommon),memory_scan(์ฝ๊ธฐ ๊ฐ๋ฅํ ๋งต์์ DEX magic),oat_extract(.vdex/.oat ๋งคํ ํ์ฑ),fart_dump(ํํฌDefineClass+class_table_์ํ),dexfile_constructor(ํํฌOatDexFile์์ฑ์),mmap_hook(mmap/mmap64๊ฐ์, ๊ธฐ๋ณธ์ ์ผ๋ก ์ฑ๋ฅ ๋๋ฌธ์ ๋นํ์ฑํ). - Java (๊ฐ๋ฅํ ๊ฒฝ์ฐ):
cookie(ClassLoaders์์mCookie์ฝ๊ธฐ),classloader_hook(loadClass,DexClassLoader,InMemoryDexClassLoader๋ชจ๋ํฐ๋ง).
Output layout
dump_<target>/
dex/classes_001.dex ...
classes/ # only when --extract-classes
metadata.json # strategy per hit + hashes
ํ: ๋ณดํธ๋ ์ฑ์ ์ข
์ข
์ฌ๋ฌ ์์ค์์ ์ฝ๋๋ฅผ ๋ก๋ํฉ๋๋ค (in-memory payload, vdex/oat, custom loaders). ๊ธฐ๋ณธ multi-strategy ์ธํธ์ --spawn์ ํจ๊ป ์ฌ์ฉํ๋ฉด ์ปค๋ฒ๋ฆฌ์ง๋ฅผ ์ต๋ํํฉ๋๋ค; ์ฑ๋ฅ ์ ํ๋ฅผ ํผํ๋ ค๋ฉด ํ์ํ ๋๋ง --deep-scan์ ํ์ฑํํ์ธ์.
ํํ ๋ฆฌ์ผ
Tutorial 1
์ถ์ฒ: https://medium.com/infosec-adventures/introduction-to-frida-5a3f51595ca1
APK: https://github.com/t0thkr1s/frida-demo/releases
์์ค ์ฝ๋: https://github.com/t0thkr1s/frida-demo
์ฝ์ผ๋ ค๋ฉด link to read it.
Tutorial 2
์ถ์ฒ: https://11x256.github.io/Frida-hooking-android-part-2/ (Parts 2, 3 & 4)
APKs and Source code: https://github.com/11x256/frida-android-examples
์ฝ์ผ๋ ค๋ฉด link to read it.
Tutorial 3
์ถ์ฒ: https://joshspicer.com/android-frida-1
APK: https://github.com/OWASP/owasp-mstg/blob/master/Crackmes/Android/Level_01/UnCrackable-Level1.apk
์ฝ์ผ๋ ค๋ฉด link to read it.
๋ ๋ง์ Frida ์คํฌ๋ฆฝํธ๋ ์ฌ๊ธฐ์์ ์ฐพ์ ์ ์์ต๋๋ค: https://codeshare.frida.re/
๋น ๋ฅธ ์์
Calling Frida from command line
frida-ps -U
#Basic frida hooking
frida -l disableRoot.js -f owasp.mstg.uncrackable1
#Hooking before starting the app
frida -U --no-pause -l disableRoot.js -f owasp.mstg.uncrackable1
#The --no-pause and -f options allow the app to be spawned automatically,
#frozen so that the instrumentation can occur, and the automatically
#continue execution with our modified code.
๊ธฐ๋ณธ Python ์คํฌ๋ฆฝํธ
import frida, sys
jscode = open(sys.argv[0]).read()
process = frida.get_usb_device().attach('infosecadventures.fridademo')
script = process.create_script(jscode)
print('[ * ] Running Frida Demo application')
script.load()
sys.stdin.read()
Hooking: ๋งค๊ฐ๋ณ์๊ฐ ์๋ ํจ์
ํด๋์ค sg.vantagepoint.a.c์ ํจ์ a()๋ฅผ Hookํ์ธ์.
Java.perform(function () {
rootcheck1.a.overload().implementation = function () {
return false;
};
});
Hook java exit()
var sysexit = Java.use("java.lang.System")
sysexit.exit.overload("int").implementation = function (var_0) {
send("java.lang.System.exit(I)V // We avoid exiting the application :)")
}
Hook MainActivity .onStart() & .onCreate()
var mainactivity = Java.use("sg.vantagepoint.uncrackable1.MainActivity")
mainactivity.onStart.overload().implementation = function () {
send("MainActivity.onStart() HIT!!!")
var ret = this.onStart.overload().call(this)
}
mainactivity.onCreate.overload("android.os.Bundle").implementation = function (
var_0
) {
send("MainActivity.onCreate() HIT!!!")
var ret = this.onCreate.overload("android.os.Bundle").call(this, var_0)
}
Hook android .onCreate()
var activity = Java.use("android.app.Activity")
activity.onCreate.overload("android.os.Bundle").implementation = function (
var_0
) {
send("Activity HIT!!!")
var ret = this.onCreate.overload("android.os.Bundle").call(this, var_0)
}
Hooking ํจ์๋ค โ ๋งค๊ฐ๋ณ์์ ๋ฐํ๊ฐ ๊ฐ์ ธ์ค๊ธฐ
decryption function์ Hookingํฉ๋๋ค. ์ ๋ ฅ์ ์ถ๋ ฅํ๊ณ , ์๋ณธ ํจ์๋ฅผ ํธ์ถํด ์ ๋ ฅ์ decryptํ ๋ค์, ์ต์ข ์ ์ผ๋ก ํ๋ฌธ ๋ฐ์ดํฐ๋ฅผ ์ถ๋ ฅํฉ๋๋ค:
Hooking a decryption function (Java) โ print inputs/outputs
```javascript function getString(data) { var ret = "" for (var i = 0; i < data.length; i++) { ret += data[i].toString() } return ret } var aes_decrypt = Java.use("sg.vantagepoint.a.a") aes_decrypt.a.overload("[B", "[B").implementation = function (var_0, var_1) { send("sg.vantagepoint.a.a.a([B[B)[B doFinal(enc) // AES/ECB/PKCS7Padding") send("Key : " + getString(var_0)) send("Encrypted : " + getString(var_1)) var ret = this.a.overload("[B", "[B").call(this, var_0, var_1) send("Decrypted : " + ret)var flag = โโ for (var i = 0; i < ret.length; i++) { flag += String.fromCharCode(ret[i]) } send(โDecrypted flag: โ + flag) return ret //[B }
</details>
### Hooking ํจ์๋ค์ ์ฐ๋ฆฌ ์
๋ ฅ์ผ๋ก ํธ์ถํ๊ธฐ
string์ ๋ฐ๋ ํจ์๋ฅผ Hookํ๊ณ ๋ค๋ฅธ string์ผ๋ก ํธ์ถํ์ธ์ (from [here](https://11x256.github.io/Frida-hooking-android-part-2/))
```javascript
var string_class = Java.use("java.lang.String") // get a JS wrapper for java's String class
my_class.fun.overload("java.lang.String").implementation = function (x) {
//hooking the new function
var my_string = string_class.$new("My TeSt String#####") //creating a new String by using `new` operator
console.log("Original arg: " + x)
var ret = this.fun(my_string) // calling the original function with the new String, and putting its return value in ret variable
console.log("Return value: " + ret)
return ret
}
์ด๋ฏธ ์์ฑ๋ ํด๋์ค ๊ฐ์ฒด ๊ฐ์ ธ์ค๊ธฐ
์ด๋ฏธ ์์ฑ๋ ๊ฐ์ฒด์์ ์ด๋ค ์์ฑ์ ์ถ์ถํ๋ ค๋ฉด ๋ค์์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
์ด ์์ ์์๋ ํด๋์ค my_activity์ ๊ฐ์ฒด๋ฅผ ๊ฐ์ ธ์ค๊ณ ๊ฐ์ฒด์ ๋น๊ณต๊ฐ ์์ฑ์ ์ถ๋ ฅํ๋ .secret() ํจ์๋ฅผ ํธ์ถํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค:
Java.choose("com.example.a11x256.frida_test.my_activity", {
onMatch: function (instance) {
//This function will be called for every instance found by frida
console.log("Found instance: " + instance)
console.log("Result of secret func: " + instance.secret())
},
onComplete: function () {},
})
๊ธฐํ Frida ํํ ๋ฆฌ์ผ
- https://github.com/DERE-ad2001/Frida-Labs
- Part 1 of Advanced Frida Usage blog series: IOS Encryption Libraries
์ฐธ๊ณ ์๋ฃ
- Build a Repeatable Android Bug Bounty Lab: Emulator vs Magisk, Burp, Frida, and Medusa
- Frida Gadget documentation
- Frida releases (server binaries)
- Objection (SensePost)
- Modding And Distributing Mobile Apps with Frida
- frida-jdwp-loader
- Library injection for debuggable Android apps (blog)
- jdwp-lib-injector (original idea/tool)
- jdwp-shellifier
- โSuper secureโ MAGA-themed messaging app leaks everyoneโs phone number
- Android Frida Hooking: Disabling FLAG_SECURE
- frida-ui
- clsdumper โ Android Dynamic Class Dumper
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


