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์์ ์ฅ์น/์ฑ์ ๋์ดํ๊ณ ์คํฌ๋ฆฝํธ๋ก ๋์์ 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>/(์: 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" }
}
- ๊ฐ์ ฏ์ ์ฐธ์กฐ/๋ก๋ํ์ฌ ์กฐ๊ธฐ์ ์ด๊ธฐํ๋๋๋ก:
- ๊ฐ์ฅ ์ฌ์ด ๋ฐฉ๋ฒ: Application.onCreate()์ System.loadLibrary(โfrida-gadgetโ)๋ฅผ ํธ์ถํ๋ ์์ Java stub์ ์ถ๊ฐํ๊ฑฐ๋, ์ด๋ฏธ ์กด์ฌํ๋ ๋ค์ดํฐ๋ธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ก๋ฉ์ ์ฌ์ฉํ์ธ์.
- Repackํ๊ณ 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 process์ Attach:
frida-ps -Uai
frida -U -n com.example.app
์ฐธ๊ณ
- ์ผ๋ถ ๋ณดํธ ๋ฉ์ปค๋์ฆ์ Gadget์ ๊ฐ์งํ๋ฏ๋ก, ํ์ํ๋ฉด ์ด๋ฆ/๊ฒฝ๋ก๋ฅผ ์ํํ๊ณ ๋ฆ๊ฒ ๋๋ ์กฐ๊ฑด๋ถ๋ก ๋ก๋ํ์ธ์.
- ๊ฐํ๋ ์ฑ์ ๊ฒฝ์ฐ ๋ฃจํ ๋ ์ํ์์ server + late attach๋ก ํ ์คํธํ๋ ๊ฒ์ ๊ถ์ฅํ๊ฑฐ๋ Magisk/Zygisk ์ํ์ ๊ฒฐํฉํ์ธ์.
JDWP ๊ธฐ๋ฐ Frida injection without root/repackaging (frida-jdwp-loader)
APK๊ฐ ๋๋ฒ๊น ๊ฐ๋ฅ(android:debuggable=โtrueโ)ํ๋ฉด, JDWP๋ก ์ฐ๊ฒฐํด Java breakpoint์์ ๋ค์ดํฐ๋ธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฃผ์ ํ ์ ์์ต๋๋ค. ๋ฃจํธ๋ APK ์ฌํจํค์ง ๋ถํ์.
- Repo: https://github.com/frankheat/frida-jdwp-loader
- ์๊ตฌ์ฌํญ: ADB, Python 3, USB/๋ฌด์ ๋๋ฒ๊น
. ์ฑ์ ๋๋ฒ๊ทธ ๊ฐ๋ฅํด์ผ ํฉ๋๋ค (์๋ฎฌ๋ ์ดํฐ์์
ro.debuggable=1, ๋ฃจํ ๋ ๊ธฐ๊ธฐ์์resetprop, ๋๋ ๋งค๋ํ์คํธ ์ฌ๋น๋).
๋น ๋ฅธ ์์
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 (break at Application.onCreate) or attach (break at Activity.onStart). ํน์ Java ๋ฉ์๋๋ฅผ ์ค์ ํ๋ ค๋ฉด
-b๋ฅผ ์ฌ์ฉํ๊ณ , Gadget ๋ฒ์ /๊ฒฝ๋ก๋ฅผ ์ ํํ๋ ค๋ฉด-g, JDWP ํฌํธ๋ฅผ ์ ํํ๋ ค๋ฉด-p๋ฅผ ์ฌ์ฉํ์ธ์. - ๋ฆฌ์ค๋ ๋ชจ๋: ํ์ํ ๊ฒฝ์ฐ Gadget(๊ธฐ๋ณธ๊ฐ 127.0.0.1:27042)๋ฅผ ํฌ์๋ํ์ธ์:
adb forward tcp:27042 tcp:27042; ๊ทธ๋ฐ ๋ค์frida-ps -H 127.0.0.1:27042. - ์ด๋ JDWP ๋๋ฒ๊น ์ ํ์ฉํฉ๋๋ค. ์ํ: debuggable ๋น๋๋ฅผ ๋ฐฐํฌํ๊ฑฐ๋ JDWP๋ฅผ ๋ ธ์ถ์ํค๋ ๊ฒ์ ๋๋ค.
๋ ๋ฆฝํ ์์ด์ ํธ + Gadget ์๋ฒ ๋ฉ (Frida 17+; Objection์ผ๋ก ์๋ํ๋จ)
Frida 17์ GumJS์์ ๋ด์ฅ๋ Java/ObjC bridges๋ฅผ ์ ๊ฑฐํ์ต๋๋ค. ์์ด์ ํธ๊ฐ Java๋ฅผ ํ (hook)ํ๋ค๋ฉด, Java bridge๋ฅผ ๋ฒ๋ค์ ํฌํจํด์ผ ํฉ๋๋ค.
- Frida ์์ด์ ํธ(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 ๋ด๋ถ์ on-disk path๋ฅผ ์ง์ ํ์ธ์:
{
"interaction": {
"type": "script",
"path": "libfrida-gadget.script.so"
}
}
- Objection์ผ๋ก APK ํจ์น ์๋ํ
# 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
What patchapk does (high level):
- patchapk๊ฐ ์ํํ๋ ์์ (๊ฐ์):
- Detects device ABI (e.g., arm64-v8a) and fetches matching Gadget
- ๋๋ฐ์ด์ค ABI(์: arm64-v8a)๋ฅผ ๊ฐ์งํ๊ณ ์ผ์นํ๋ Gadget์ ๊ฐ์ ธ์ต๋๋ค
- Optionally adds android.permission.INTERNET when needed
- ํ์ํ ๊ฒฝ์ฐ android.permission.INTERNET์ ์ ํ์ ์ผ๋ก ์ถ๊ฐํฉ๋๋ค
- Injects a static class initializer calling System.loadLibrary(โfrida-gadgetโ) into the launch activity
- launch activity์ System.loadLibrary(โfrida-gadgetโ)๋ฅผ ํธ์ถํ๋ ์ ์ ํด๋์ค ์ด๊ธฐํ์(static class initializer)๋ฅผ ์ฝ์ ํฉ๋๋ค
- Places the following under
lib/<abi>/: lib/<abi>/์๋์ ๋ค์์ ๋ฐฐ์นํฉ๋๋ค:- libfrida-gadget.so
- libfrida-gadget.config.so (serialized config)
- libfrida-gadget.config.so (์ง๋ ฌํ๋ config)
- libfrida-gadget.script.so (your _agent.js)
- libfrida-gadget.script.so (์ฌ์ฉ์์ _agent.js)
Example injected smali (static initializer): ์ฝ์ ๋ 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์๋ System.loadLibrary(โfrida-gadgetโ)๋ฅผ ํธ์ถํ๋ ์ ์
<clinit>๊ฐ ํฌํจ๋์ด ์์ต๋๋ค
- Split APKs
- ๊ธฐ๋ณธ APK(MAIN/LAUNCHER activity๋ฅผ ์ ์ธํ ๊ฒ)๋ฅผ ํจ์นํฉ๋๋ค
- ๋๋จธ์ง split๋ค์ ๋์ผํ ํค๋ก ์ฌ์๋ช ํฉ๋๋ค:
objection signapk split1.apk split2.apk ...
- splits๋ฅผ ํจ๊ป ์ค์น:
adb install-multiple split1.apk split2.apk ...
- ๋ฐฐํฌ๋ฅผ ์ํด, APKEditor๋ก split APK๋ค์ ํ๋์ APK๋ก ๋ณํฉํ ๋ค์ align/sign ํ์ธ์
๋์ ๋ถ์ ์ค FLAG_SECURE ํด์
getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE)๋ฅผ ํธ์ถํ๋ ์ฑ์ ์คํฌ๋ฆฐ์ท, ์๊ฒฉ ๋์คํ๋ ์ด, ์ฌ์ง์ด Android์ ์ต๊ทผ ์์
์ค๋
์ท๊น์ง ์ฐจ๋จํฉ๋๋ค. Freedom Chat์ด ์ด ํ๋๊ทธ๋ฅผ ๊ฐ์ ํ์ ๋ leaks๋ฅผ ๋ฌธ์ํํ๋ ์ ์ผํ ๋ฐฉ๋ฒ์ ๋ฐํ์์ ์๋์ฐ๋ฅผ ๋ณ์กฐํ๋ ๊ฒ์ด์์ต๋๋ค. ์ ๋ขฐํ ์ ์๋ ํจํด์:
- ํ๋๊ทธ๋ฅผ ๋ค์ ์ ์ฉํ ์ ์๋ ๋ชจ๋
Window์ค๋ฒ๋ก๋(setFlags,addFlags,setAttributes)๋ฅผ ํ ํ๊ณ ๋นํธ0x00002000(WindowManager.LayoutParams.FLAG_SECURE)๋ฅผ ๋ง์คํนํ์ธ์. - ๊ฐ activity๊ฐ resume๋ ํ์๋ UI ์ค๋ ๋์์
clearFlags(FLAG_SECURE)๋ฅผ ํธ์ถํ๋๋ก ์์ฝํ์ฌ ์ดํ ์์ฑ๋๋ Dialogs/Fragments๊ฐ ํด์ ๋ ์ํ๋ฅผ ์์๋ฐ๋๋ก ํ์ธ์. - React Native / Flutter๋ก ๋น๋๋ ์ฑ์ ์ค์ฒฉ๋ ์๋์ฐ๋ฅผ ์์ฃผ ์์ฑํฉ๋๋ค; ์ค์ฒฉ ์๋์ฐ๊ฐ ๊ณ์ ๊ฒ์ ํ๋ฉด์ผ๋ก ๋ณด์ด๋ฉด
android.app.Dialog/android.view.Viewํฌํผ๋ฅผ ํ ํ๊ฑฐ๋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>
`frida -U -f <package> -l disable-flag-secure.js --no-pause`๋ก ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ๊ณ UI์ ์ํธ์์ฉํ๋ฉด ์คํฌ๋ฆฐ์ท/๋
นํ๊ฐ ๋ค์ ์๋ํฉ๋๋ค. ๋ชจ๋ ๊ฒ์ด UI ์ค๋ ๋์์ ๋ฐ์ํ๋ฏ๋ก ๊น๋นก์์ด ์๊ณ , HTTP Toolkit/Burp์ ํ
์ ๊ฒฐํฉํด `/channel` PIN leak๋ฅผ ์ ๋ฐํ ํธ๋ํฝ์ ์บก์ฒํ ์ ์์ต๋๋ค.
## ํํ ๋ฆฌ์ผ
### [Tutorial 1](frida-tutorial-1.md)
**์ถ์ฒ**: [https://medium.com/infosec-adventures/introduction-to-frida-5a3f51595ca1](https://medium.com/infosec-adventures/introduction-to-frida-5a3f51595ca1)\
**APK**: [https://github.com/t0thkr1s/frida-demo/releases](https://github.com/t0thkr1s/frida-demo/releases)\
**์์ค ์ฝ๋**: [https://github.com/t0thkr1s/frida-demo](https://github.com/t0thkr1s/frida-demo)
**์ฝ์ผ๋ ค๋ฉด [์ด ๋งํฌ](frida-tutorial-1.md)๋ฅผ ๋ฐ๋ฅด์ธ์.**
### [Tutorial 2](frida-tutorial-2.md)
**์ถ์ฒ**: [https://11x256.github.io/Frida-hooking-android-part-2/](https://11x256.github.io/Frida-hooking-android-part-2/) (Parts 2, 3 & 4)\
**APKs ๋ฐ ์์ค ์ฝ๋**: [https://github.com/11x256/frida-android-examples](https://github.com/11x256/frida-android-examples)
**์ฝ์ผ๋ ค๋ฉด [์ด ๋งํฌ](frida-tutorial-2.md)๋ฅผ ๋ฐ๋ฅด์ธ์.**
### [Tutorial 3](owaspuncrackable-1.md)
**์ถ์ฒ**: [https://joshspicer.com/android-frida-1](https://joshspicer.com/android-frida-1)\
**APK**: [https://github.com/OWASP/owasp-mstg/blob/master/Crackmes/Android/Level_01/UnCrackable-Level1.apk](https://github.com/OWASP/owasp-mstg/blob/master/Crackmes/Android/Level_01/UnCrackable-Level1.apk)
**์ฝ์ผ๋ ค๋ฉด [์ด ๋งํฌ](owaspuncrackable-1.md)๋ฅผ ๋ฐ๋ฅด์ธ์.**
**๋ ๋ง์ Awesome Frida ์คํฌ๋ฆฝํธ๋ ์ฌ๊ธฐ์์ ์ฐพ์ ์ ์์ต๋๋ค:** [**https://codeshare.frida.re/**](https://codeshare.frida.re)
## ๋น ๋ฅธ ์์
### ๋ช
๋ น์ค์์ Frida ํธ์ถํ๊ธฐ
```bash
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;
};
});
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ํ ๋ค, ์ต์ข ์ ์ผ๋ก ํ๋ฌธ ๋ฐ์ดํฐ๋ฅผ ์ถ๋ ฅํฉ๋๋ค:
decryption function (Java) โ ์ ๋ ฅ/์ถ๋ ฅ ๋ณด๊ธฐ
```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 functions ๋ฐ ์ฐ๋ฆฌ ์
๋ ฅ์ผ๋ก ํธ์ถํ๊ธฐ
string์ ๋ฐ๋ function์ 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
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์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


