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 का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।
इंस्टॉलेशन
इंस्टॉल करें frida tools:
pip install frida-tools
pip install frida
डाउनलोड और इंस्टॉल करें एंड्रॉइड में frida server (Download the latest release).
adb को root मोड में restart करने, उससे connect करने, frida-server अपलोड करने, exec permissions देने और इसे बैकग्राउंड में चलाने के लिए एक वन-लाइनर:
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 पर एक वेब UI प्रदान करता है जो devices/apps को सूचीबद्ध करने और scripts के साथ targets को attach या spawn करने की सुविधा देता है (CLI की आवश्यकता नहीं)।
- इंस्टॉल करें (
fridaको device server के संस्करण के साथ pin करें):
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
- Features: USB/लोकल डिवाइसों का पता लगाता है, रिमोट सर्वर्स जोड़ें (
192.168.1.x:27042), और Attach, Spawn, और Spawn & Run को सपोर्ट करता है (प्रारंभिकonCreate()लॉजिक से पहले hook करने के लिए)। - Scripting: editor, drag & drop
.js, import CodeShare, स्क्रिप्ट्स और session logs डाउनलोड करें। - Remote servers:
./frida-server -l 0.0.0.0:27042 -Dइसे नेटवर्क पर एक्सपोज़ करता है ताकि frida-ui बिना ADB के connect कर सके।
Frida server vs. Gadget (root vs. no-root)
Frida के साथ Android apps को instrument करने के दो सामान्य तरीके:
- Frida server (rooted devices): पुश कर के और एक native daemon चलाएँ जो आपको किसी भी process को attach करने की अनुमति देता है।
- Frida Gadget (no root): Frida को APK के अंदर shared library के रूप में bundle करें और target process के अंदर इसे auto-load करें।
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 और config जोड़ें:
- libfrida-gadget.so को
lib/<abi>/में रखें (उदा., lib/arm64-v8a/) - assets/frida-gadget.config बनाएँ और उसमें अपने script loading settings रखें
frida-gadget.config का उदाहरण
{
"interaction": { "type": "script", "path": "/sdcard/ssl-bypass.js" },
"runtime": { "logFile": "/sdcard/frida-gadget.log" }
}
- गैजेट को संदर्भित/लोड करें ताकि यह जल्दी प्रारंभ हो:
- सबसे आसान: Application.onCreate() में System.loadLibrary(“frida-gadget”) कॉल करने वाला एक छोटा Java स्टब जोड़ें, या पहले से मौजूद native lib loading का उपयोग करें।
- 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 कुछ सुरक्षा उपायों द्वारा detect हो सकता है; names/paths stealthy रखें और ज़रूरत पड़ने पर late/conditionally लोड करें।
- कठोर सुरक्षा वाले apps पर, rooted testing server + late attach के साथ प्राथमिकता दें, या Magisk/Zygisk hiding के साथ combine करें।
JDWP-based Frida injection without root/repackaging (frida-jdwp-loader)
यदि APK debuggable है (android:debuggable=“true”), तो आप JDWP के माध्यम से attach करके Java breakpoint पर एक native library inject कर सकते हैं। No root and no APK repackaging।
- Repo: https://github.com/frankheat/frida-jdwp-loader
- आवश्यकताएँ: ADB, Python 3, USB/Wireless debugging. App को debuggable होना चाहिए (emulator with
ro.debuggable=1, rooted device withresetprop, or rebuild manifest).
शीघ्र आरंभ:
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
Notes
- Modes: spawn (Application.onCreate पर ब्रेक) या attach (Activity.onStart पर ब्रेक).
-bकिसी विशिष्ट Java method को सेट करने के लिए इस्तेमाल करें,-gGadget version/path चुनने के लिए, और-pJDWP port चुनने के लिए। - Listen mode: आवश्यक होने पर Gadget को फॉरवर्ड करें (default 127.0.0.1:27042):
adb forward tcp:27042 tcp:27042; फिरfrida-ps -H 127.0.0.1:27042। - यह JDWP debugging का उपयोग करता है। जोखिम है debuggable builds शिप करना या JDWP को एक्सपोज़ करना।
Self-contained agent + Gadget embedding (Frida 17+; automated with Objection)
Frida 17 ने GumJS से built-in Java/ObjC bridges हटा दिए। यदि आपका एजेंट Java को hook करता है, तो आपको अपने bundle के अंदर 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 को कॉन्फ़िगर करें ताकि यह आपका script स्वचालित रूप से लोड करे Objection’s patcher एक Gadget config की अपेक्षा करता है; script mode का उपयोग करते समय, APK lib dir के अंदर on-disk path निर्दिष्ट करें:
{
"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 का पता लगाता है (e.g., arm64-v8a) और मिलान करने वाला Gadget प्राप्त करता है
- आवश्यक होने पर android.permission.INTERNET जोड़ता है
- लॉन्च activity में System.loadLibrary(“frida-gadget”) कॉल करने वाला एक static class initializer इंजेक्ट करता है
- निम्न को
lib/<abi>/के अंतर्गत रखता है: - libfrida-gadget.so
- libfrida-gadget.config.so (सीरियलाइज़्ड config)
- libfrida-gadget.script.so (आपका _agent.js)
Example injected smali (static initializer):
.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>/के अंतर्गत नए native libs - Launchable activity smali में एक static
<clinit>होता है जो System.loadLibrary(“frida-gadget”) को कॉल करता है
- Split APKs
- बेस APK को patch करें (वह जो MAIN/LAUNCHER activity घोषित करता है)
- Re-sign remaining splits with the same key:
objection signapk split1.apk split2.apk ...
- splits को एक साथ इंस्टॉल करें:
adb install-multiple split1.apk split2.apk ...
- डिस्ट्रीब्यूशन के लिए, आप splits को APKEditor के साथ एक single APK में मर्ज कर सकते हैं, फिर align/sign करें
डायनामिक विश्लेषण के दौरान FLAG_SECURE को क्लियर करना
ऐप्स जो getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE) कॉल करते हैं वो screenshots, remote displays और यहाँ तक कि Android के recent-task snapshots को रोक देते हैं। जब Freedom Chat ने इस flag को लागू किया तो leaks को document करने का एकमात्र तरीका runtime पर window को टेम्पर करना था। एक भरोसेमंद पैटर्न है:
- Hook every
Windowoverload that can re-apply the flag (setFlags,addFlags,setAttributes) and mask out bit0x00002000(WindowManager.LayoutParams.FLAG_SECURE). - हर activity resume होने के बाद, UI-thread पर
clearFlags(FLAG_SECURE)कॉल शेड्यूल करें ताकि बाद में बनाए गए Dialogs/Fragments अनलॉक्ड state inherit करें। - React Native / Flutter से बनी ऐप्स अक्सर nested windows बनाती हैं; यदि आप अभी भी ब्लैक फ़्रेम देखते हैं तो
android.app.Dialog/android.view.Viewhelpers को hook करें याgetWindow().peekDecorView()को walk करें।
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 thread पर होता है इसलिए कोई झिलमिलाहट नहीं होगी, और आप अभी भी hook को HTTP Toolkit/Burp के साथ combine करके उस ट्रैफ़िक को capture कर सकते हैं जिसने `/channel` PIN leak को उजागर किया।
## Dynamic DEX dumping / unpacking with clsdumper (Frida)
`clsdumper` एक Frida-based डायनामिक **DEX/class dumper** है जो hardened apps में भी काम कर जाता है क्योंकि यह एक anti-Frida pre-stage को native और Java discovery strategies के साथ जोड़ता है (यह तब भी काम करता है जब `Java.perform()` बंद हो जाए)। आवश्यकताएँ: Python 3.10+, rooted device जिस पर `frida-server` चल रहा हो, USB या `--host` TCP connection।
**इंस्टॉल & त्वरित उपयोग**
```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>: remote frida-server से कनेक्ट करें.--strategies <comma>: extractors को सीमित/चुनें; डिफ़ॉल्ट सभी हैं सिवायmmap_hookके (expensive).--no-scan/--deep-scan: गहरा memory scan अक्षम या धीमा करें (adds CDEX scanning).--extract-classes: dumps को androguard के जरिए.smaliमें post-process करें.--no-anti-frida: pre-hook bypass चरण छोड़ें.--list/--list-apps: चल रहे processes या installed packages को सूचीबद्ध करें.
Anti-instrumentation bypass (phase 0)
- Hooks
sigaction/signalताकि crash/anti-debug handlers के registration को ब्लॉक किया जा सके. memfd_createके जरिए filtered/proc/self/mapsसर्व करके Frida regions छिपाता है.pthread_createकी निगरानी करके Frida खोजने वाली watchdog threads को पकड़/निष्क्रिय करता है.
DEX discovery (phases 1–2) — कई पूरक रणनीतियाँ, प्रति-हिट मेटाडेटा और डुप्लीकेशन हटाने के साथ (agent-side djb2, host-side SHA-256):
- Native (कोई Java bridge आवश्यक नहीं):
art_walk(walk ART Runtime→ClassLinker→DexFile),open_common_hook(hookDexFile::OpenCommon),memory_scan(DEX magic in readable maps),oat_extract(parse mapped .vdex/.oat),fart_dump(hookDefineClass+ walkclass_table_),dexfile_constructor(hookOatDexFileconstructors),mmap_hook(watchmmap/mmap64, off by default for perf). - Java (when available):
cookie(mCookieको ClassLoaders से पढ़ता है),classloader_hook(monitorloadClass,DexClassLoader,InMemoryDexClassLoader).
आउटपुट लेआउट
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/ (भाग 2, 3 & 4)
APKs और सोर्स कोड: 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।
You can find more Awesome Frida scripts here: https://codeshare.frida.re/
त्वरित उदाहरण
कमांड लाइन से Frida कॉल करना
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()
पैरामीटर-रहित फ़ंक्शन को हुक करना
क्लास sg.vantagepoint.a.c के फ़ंक्शन a() को हुक करें
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 फ़ंक्शन्स को पैरामीटर के साथ हुक करना और मान प्राप्त करना
Hooking a decryption function. इनपुट को प्रिंट करें, मूल फ़ंक्शन को कॉल करके इनपुट को decrypt करें और अंत में plain डेटा प्रिंट करें:
Hooking a 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 और उन्हें हमारे इनपुट के साथ कॉल करना
Hook उस function को जो एक string प्राप्त करता है और इसे किसी अन्य 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
}
किसी class के पहले से बनाए गए ऑब्जेक्ट को प्राप्त करना
यदि आप किसी बनाए गए ऑब्जेक्ट के किसी attribute को निकालना चाहते हैं तो आप यह तरीका उपयोग कर सकते हैं।
इस उदाहरण में आप देखेंगे कि class my_activity का object कैसे प्राप्त करें और .secret() फंक्शन को कैसे कॉल करें, जो उस ऑब्जेक्ट का एक private attribute प्रिंट करेगा:
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 का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।


