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 को रूट मोड में restart करे, उससे connect करे, frida-server upload करे, exec permissions दे और उसे background में चलाए:
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 version पर 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
- फ़ीचर्स: USB/स्थानीय devices का पता लगाता है, रिमोट सर्वर जोड़ें (
192.168.1.x:27042), और Attach, Spawn, तथा Spawn & Run को सपोर्ट करता है (शीघ्रonCreate()लॉजिक से पहले hook करने के लिए). - Scripting: एडिटर, drag & drop
.jsफ़ाइलें, CodeShare import करें, scripts और session logs डाउनलोड करें. - Remote servers:
./frida-server -l 0.0.0.0:27042 -Dइसे नेटवर्क पर एक्सपोज़ करता है ताकि frida-ui बिना ADB के कनेक्ट कर सके.
Frida server vs. Gadget (root vs. no-root)
Frida के साथ Android apps को instrument करने के दो सामान्य तरीके:
- Frida server (rooted devices): एक native daemon को push और run करें जो आपको किसी भी 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बनाएं और इसमें अपनी स्क्रिप्ट लोडिंग सेटिंग्स डालें
उदाहरण 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 जोड़ें, या पहले से मौजूद 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 कुछ सुरक्षा उपायों द्वारा डिटेक्ट हो सकता है; नाम/paths को stealthy रखें और आवश्यकता होने पर देर से/शर्तीय रूप से लोड करें।
- hardened apps पर, प्राथमिकता rooted testing दें जिसमें server + late attach शामिल हो, या इसे Magisk/Zygisk hiding के साथ मिलाएँ।
JDWP-based Frida injection without root/repackaging (frida-jdwp-loader)
यदि APK debuggable है (android:debuggable=“true”), तो आप JDWP के जरिए attach कर सकते हैं और Java breakpoint पर native library inject कर सकते हैं। No root और no APK repackaging।
- Repo: https://github.com/frankheat/frida-jdwp-loader
- Requirements: 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 (break at Application.onCreate) or attach (break at Activity.onStart). Use
-bto set a specific Java method,-gto select Gadget version/path,-pto choose JDWP port. - Listen mode: 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+; Objection के साथ स्वचालित)
Frida 17 ने GumJS से built-in Java/ObjC bridges हटा दिए। यदि आपका agent Java को hook करता है, तो आपको 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
Minimal 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
- अपने script को स्वचालित रूप से लोड करने के लिए 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
What patchapk does (high level):
- डिवाइस ABI (उदा., arm64-v8a) का पता लगाता है और अनुरूप Gadget प्राप्त करता है
- आवश्यकता होने पर android.permission.INTERNET जोड़ता है
- launch activity में एक static class initializer इंजेक्ट करता है जो System.loadLibrary(“frida-gadget”) को कॉल करता है
- निम्नलिखित
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
Expected changes:
- AndroidManifest.xml में हो सकता है कि
<uses-permission android:name="android.permission.INTERNET"/>शामिल हो - ऊपर बताए अनुसार
lib/<abi>/के अंतर्गत नई native लाइब्रेरीज़ - Launchable activity के smali में एक static
<clinit>होता है जो System.loadLibrary(“frida-gadget”) को कॉल करता है
- स्प्लिट APKs
- base APK को patch करें (वह जो MAIN/LAUNCHER activity घोषित करता है)
- शेष स्प्लिट्स को उसी key से पुनः साइन करें:
objection signapk split1.apk split2.apk ...
- splits को एक साथ इंस्टॉल करें:
adb install-multiple split1.apk split2.apk ...
- वितरण के लिए, आप splits को APKEditor से एक single APK में merge कर सकते हैं, फिर align/sign करें
डायनामिक विश्लेषण के दौरान FLAG_SECURE हटाना
ऐप्स जो getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE) कॉल करते हैं, वे स्क्रीनशॉट्स, रिमोट डिस्प्ले और यहां तक कि Android के recent-task snapshots को भी रोकते हैं। जब Freedom Chat ने इस flag को लागू किया था तो leaks को document करने का एकमात्र तरीका runtime पर window में छेड़छाड़ करना था। एक विश्वसनीय पैटर्न है:
- हर
Windowoverload को hook करें जो flag को फिर से लागू कर सकता है (setFlags,addFlags,setAttributes) और bit0x00002000(WindowManager.LayoutParams.FLAG_SECURE) को mask out करें। - हर 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 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 थ्रेड पर होता है, इसलिए कोई झिलमिलाहट नहीं होगी, और आप hook को अभी भी HTTP Toolkit/Burp के साथ मिलाकर उस ट्रैफ़िक को कैप्चर कर सकते हैं जिसने `/channel` PIN leak को उजागर किया।
## Tutorials
### [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)
**इसे पढ़ने के लिए [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)
**इसे पढ़ने के लिए [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)
**इसे पढ़ने के लिए [link to read it](owaspuncrackable-1.md) का अनुसरण करें।**
**आप यहां और Awesome Frida scripts पा सकते हैं:** [**https://codeshare.frida.re/**](https://codeshare.frida.re)
## Quick Examples
### कमांड लाइन से 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 बिना पैरामीटर के
क्लास sg.vantagepoint.a.c की function a() को Hook करें
Java.perform(function () {
rootcheck1.a.overload().implementation = function () {
return false;
};
});
java exit() को Hook करें
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 :)")
}
MainActivity .onStart() और .onCreate() को Hook करें
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)
}
android .onCreate() को Hook करें
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 और value प्राप्त करना
Hooking a decryption function। इनपुट को प्रिंट करें, original function को कॉल करके इनपुट को decrypt करें और अंत में plain data प्रिंट करें:
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 a 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 के पहले से बनाए गए object को प्राप्त करना
यदि आप किसी बनाए गए object का कोई attribute निकालना चाहते हैं तो आप इसे उपयोग कर सकते हैं।
इस उदाहरण में आप देखेंगे कि कैसे class my_activity का object प्राप्त करें और कैसे .secret() function को कॉल करें जो ऑब्जेक्ट के एक 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
- Advanced Frida Usage ब्लॉग श्रृंखला का भाग 1: iOS Encryption Libraries
संदर्भ
- एक दोहराने योग्य Android Bug Bounty Lab बनाएं: Emulator बनाम Magisk, Burp, Frida, और Medusa
- Frida Gadget documentation
- Frida releases (server binaries)
- Objection (SensePost)
- Frida के साथ मोबाइल ऐप्स का मॉडिंग और वितरण
- frida-jdwp-loader
- डिबग करने योग्य Android ऐप्स के लिए लाइब्रेरी इंजेक्शन (ब्लॉग)
- 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 का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।


