mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
182 lines
8.4 KiB
Markdown
182 lines
8.4 KiB
Markdown
# Frida Tutorial
|
|
|
|
{{#include ../../../banners/hacktricks-training.md}}
|
|
|
|
|
|
## Installation
|
|
|
|
**frida tools** स्थापित करें:
|
|
```bash
|
|
pip install frida-tools
|
|
pip install frida
|
|
```
|
|
**एंड्रॉइड में डाउनलोड और इंस्टॉल करें** **फ्रिडा सर्वर** ([नवीनतम रिलीज़ डाउनलोड करें](https://github.com/frida/frida/releases)).\
|
|
रूट मोड में adb को पुनः प्रारंभ करने, इससे कनेक्ट करने, frida-server अपलोड करने, कार्यान्वयन अनुमतियाँ देने और इसे बैकग्राउंड में चलाने के लिए एक-लाइनर:
|
|
```bash
|
|
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 &"
|
|
```
|
|
**जांचें** कि यह **काम कर रहा है**:
|
|
```bash
|
|
frida-ps -U #List packages and processes
|
|
frida-ps -U | grep -i <part_of_the_package_name> #Get all the package name
|
|
```
|
|
## Tutorials
|
|
|
|
### [Tutorial 1](frida-tutorial-1.md)
|
|
|
|
**From**: [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)\
|
|
**Source Code**: [https://github.com/t0thkr1s/frida-demo](https://github.com/t0thkr1s/frida-demo)
|
|
|
|
**[लिंक पर पढ़ें](frida-tutorial-1.md)।**
|
|
|
|
### [Tutorial 2](frida-tutorial-2.md)
|
|
|
|
**From**: [https://11x256.github.io/Frida-hooking-android-part-2/](https://11x256.github.io/Frida-hooking-android-part-2/) (Parts 2, 3 & 4)\
|
|
**APKs और Source code**: [https://github.com/11x256/frida-android-examples](https://github.com/11x256/frida-android-examples)
|
|
|
|
**[लिंक पर पढ़ें।](frida-tutorial-2.md)**
|
|
|
|
### [Tutorial 3](owaspuncrackable-1.md)
|
|
|
|
**From**: [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)।**
|
|
|
|
**आप यहाँ और शानदार Frida स्क्रिप्ट्स पा सकते हैं:** [**https://codeshare.frida.re/**](https://codeshare.frida.re)
|
|
|
|
## Quick Examples
|
|
|
|
### Calling Frida from command line
|
|
```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()
|
|
```
|
|
### बिना पैरामीटर के फ़ंक्शन को हुक करना
|
|
|
|
क्लास `sg.vantagepoint.a.c` के फ़ंक्शन `a()` को हुक करें
|
|
```javascript
|
|
Java.perform(function () {
|
|
; rootcheck1.a.overload().implementation = function() {
|
|
rootcheck1.a.overload().implementation = function() {
|
|
send("sg.vantagepoint.a.c.a()Z Root check 1 HIT! su.exists()");
|
|
return false;
|
|
};
|
|
});
|
|
```
|
|
जावा `exit()` को हुक करें
|
|
```javascript
|
|
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()` को हुक करें
|
|
```javascript
|
|
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)
|
|
}
|
|
```
|
|
एंड्रॉइड `.onCreate()` को हुक करें
|
|
```javascript
|
|
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)
|
|
}
|
|
```
|
|
### पैरामीटर के साथ फ़ंक्शन को हुक करना और मान प्राप्त करना
|
|
|
|
एक डिक्रिप्शन फ़ंक्शन को हुक करना। इनपुट प्रिंट करें, मूल फ़ंक्शन को कॉल करें, इनपुट को डिक्रिप्ट करें और अंत में, प्लेन डेटा प्रिंट करें:
|
|
```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
|
|
}
|
|
```
|
|
### फ़ंक्शंस को हुक करना और उन्हें हमारे इनपुट के साथ कॉल करना
|
|
|
|
एक फ़ंक्शन को हुक करें जो एक स्ट्रिंग प्राप्त करता है और इसे अन्य स्ट्रिंग के साथ कॉल करें (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() फ़ंक्शन को कॉल करें जो ऑब्जेक्ट के एक निजी गुण को प्रिंट करेगा:
|
|
```javascript
|
|
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](https://github.com/DERE-ad2001/Frida-Labs)
|
|
- [Advanced Frida Usage ब्लॉग श्रृंखला का भाग 1: IOS एन्क्रिप्शन पुस्तकालय](https://8ksec.io/advanced-frida-usage-part-1-ios-encryption-libraries-8ksec-blogs/)
|
|
|
|
|
|
{{#include ../../../banners/hacktricks-training.md}}
|