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
डाउनलोड और इंस्टॉल करें android पर frida server (Download the latest release).
एक-लाइन कमांड जो adb को root मोड में रीस्टार्ट करे, उससे कनेक्ट करे, frida-server अपलोड करे, exec अनुमतियाँ दे और इसे बैकग्राउंड में चलाए:
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 server vs. Gadget (root vs. no-root)
Android ऐप्स को Frida के साथ इंस्ट्रूमेंट करने के दो सामान्य तरीके:
- Frida server (rooted devices): Push करें और एक 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>/में रखें (e.g., 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" }
}
- गैजेट का संदर्भ/लोड करें ताकि यह जल्दी इनिशियलाइज़ हो:
- सबसे आसान: छोटा Java stub जोड़ें System.loadLibrary(“frida-gadget”) को Application.onCreate() में कॉल करने के लिए, या पहले से मौजूद 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
Notes
- Gadget कुछ सुरक्षा उपायों द्वारा डिटेक्ट हो सकता है; आवश्यकता होने पर names/paths को छुपाकर रखें और इसे देर से/शर्तिया लोड करें।
- कठोर सुरक्षा वाले ऐप्स पर, 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 लाइब्रेरी inject कर सकते हैं। कोई root या APK repackaging आवश्यक नहीं।
- Repo: https://github.com/frankheat/frida-jdwp-loader
- Requirements: ADB, Python 3, USB/Wireless debugging. App must be debuggable (emulator with
ro.debuggable=1, rooted device withresetprop, or rebuild 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 (break at Application.onCreate) या attach (break at Activity.onStart). विशिष्ट Java method सेट करने के लिए
-bका उपयोग करें, Gadget version/path चुनने के लिए-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 debugging का उपयोग करता है। जोखिम है debuggable builds शिप करने या JDWP को एक्सपोज़ करने का।
Self-contained agent + Gadget embedding (Frida 17+; automated with Objection)
Frida 17 ने GumJS से built-in Java/ObjC bridges हटा दिए हैं। यदि आपका agent Java को hook करता है, तो आपको अपने bundle के अंदर 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 को कॉन्फ़िगर करें ताकि यह आपके script को auto-load करे 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 का पता लगाता है (उदा., arm64-v8a) और मेल खाने वाला Gadget प्राप्त करता है
- आवश्यकता होने पर वैकल्पिक रूप से android.permission.INTERNET जोड़ता है
- launch 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"/>शामिल हो सकता है - नई native libs
lib/<abi>/के अंतर्गत होंगी, जैसा ऊपर - Launchable activity smali में एक static
<clinit>होगा जो System.loadLibrary(“frida-gadget”) को कॉल करता है
- Split APKs
- base APK को patch करें (वही जो MAIN/LAUNCHER activity घोषित करता है)
- बाकी splits को उसी key से re-sign करें:
objection signapk split1.apk split2.apk ...
- एक साथ splits इंस्टॉल करें:
adb install-multiple split1.apk split2.apk ...
- वितरण के लिए, आप splits को APKEditor के साथ एक single APK में merge कर सकते हैं, फिर align/sign करें
Clearing FLAG_SECURE during dynamic analysis
ऐप्स जो getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE) कॉल करते हैं, वे screenshots, remote displays और यहां तक कि Android के recent-task snapshots को रोकते हैं। जब Freedom Chat ने इस flag को लागू किया तो leaks को document करने का एकमात्र तरीका runtime पर window को tamper करना था। एक भरोसेमंद पैटर्न यह है:
- हर उस
Windowoverload को hook करें जो flag को फिर से लागू कर सकता है (setFlags,addFlags,setAttributes) और bit0x00002000(WindowManager.LayoutParams.FLAG_SECURE) को mask आउट करें। - प्रत्येक activity के resume होने के बाद, UI-thread पर
clearFlags(FLAG_SECURE)कॉल शेड्यूल करें ताकि बाद में बनाए गए Dialogs/Fragments अनलॉक्ड स्थिति inherit कर सकें। - React Native / Flutter से बने ऐप्स अक्सर nested windows बनाते हैं;
android.app.Dialog/android.view.Viewhelpers को hook करें या अगर अभी भी black frames दिखाई देते हैं तोgetWindow().peekDecorView()को walk करें।
Frida hook — 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 थ्रेड पर होता है इसलिए कोई झिलमिलाहट नहीं होगी, और आप अभी भी इस hook को 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)
**Follow the [link to read it](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 and Source code**: [https://github.com/11x256/frida-android-examples](https://github.com/11x256/frida-android-examples)
**Follow the [link to read it.](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)
**Follow the [link to read it](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 Script
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 functions without parameters
क्लास sg.vantagepoint.a.c के फ़ंक्शन a() को Hook करें
Java.perform(function () {
rootcheck1.a.overload().implementation = function() {
send("sg.vantagepoint.a.c.a()Z Root check 1 HIT! su.exists()")
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 functions with parameters और वैल्यू प्राप्त करना
एक decryption function को Hook करना। इनपुट को प्रिंट करें, मूल फ़ंक्शन को कॉल करके इनपुट को decrypt करें, और अंत में plain data प्रिंट करें:
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 functions और उन्हें हमारे इनपुट के साथ कॉल करना
एक function को Hook करें जो एक string प्राप्त करता है और उसे किसी अन्य string के साथ कॉल करें (यहाँ से [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
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 सबमिट करें।
HackTricks

