Frida Tutorial 1
Reading time: 4 minutes
tip
AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाएँ देखें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमारे Twitter 🐦 @hacktricks_live** का पालन करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।
यह पोस्ट का सारांश है: https://medium.com/infosec-adventures/introduction-to-frida-5a3f51595ca1
APK: https://github.com/t0thkr1s/frida-demo/releases
स्रोत कोड: https://github.com/t0thkr1s/frida-demo
Python
Frida आपको JavaScript कोड को एक चल रहे एप्लिकेशन के फ़ंक्शनों के अंदर डालने की अनुमति देता है। लेकिन आप python का उपयोग hooks को call करने और यहां तक कि hooks के साथ interact करने के लिए कर सकते हैं।
यह एक आसान python स्क्रिप्ट है जिसे आप इस ट्यूटोरियल में सभी प्रस्तावित उदाहरणों के साथ उपयोग कर सकते हैं:
#hooking.py
import frida, sys
with open(sys.argv[1], 'r') as f:
jscode = f.read()
process = frida.get_usb_device().attach('infosecadventures.fridademo')
script = process.create_script(jscode)
print('[ * ] Running Frida Demo application')
script.load()
sys.stdin.read()
स्क्रिप्ट को कॉल करें:
python hooking.py <hookN.js>
यह जानना उपयोगी है कि फ्रिडा के साथ पायथन का उपयोग कैसे करें, लेकिन इन उदाहरणों के लिए आप सीधे कमांड लाइन फ्रिडा टूल्स का उपयोग करके भी फ्रिडा को कॉल कर सकते हैं:
frida -U --no-pause -l hookN.js -f infosecadventures.fridademo
Hook 1 - Boolean Bypass
यहाँ आप देख सकते हैं कि कैसे एक hook एक boolean विधि (checkPin) से क्लास: infosecadventures.fridademo.utils.PinUtil
//hook1.js
Java.perform(function () {
console.log("[ * ] Starting implementation override...")
var MainActivity = Java.use("infosecadventures.fridademo.utils.PinUtil")
MainActivity.checkPin.implementation = function (pin) {
console.log("[ + ] PIN check successfully bypassed!")
return true
}
})
python hooking.py hook1.js
देखें: फ़ंक्शन एक String को पैरामीटर के रूप में लेता है, क्या ओवरलोड करने की आवश्यकता नहीं है?
Hook 2 - फ़ंक्शन ब्रूटफोर्स
नॉन-स्टैटिक फ़ंक्शन
यदि आप किसी क्लास का नॉन-स्टैटिक फ़ंक्शन कॉल करना चाहते हैं, तो आपको पहले उस क्लास का एक उदाहरण चाहिए। फिर, आप उस उदाहरण का उपयोग करके फ़ंक्शन को कॉल कर सकते हैं।
इसके लिए, आप एक मौजूदा उदाहरण खोज सकते हैं और इसका उपयोग कर सकते हैं:
Java.perform(function () {
console.log("[ * ] Starting PIN Brute-force, please wait...")
Java.choose("infosecadventures.fridademo.utils.PinUtil", {
onMatch: function (instance) {
console.log("[ * ] Instance found in memory: " + instance)
for (var i = 1000; i < 9999; i++) {
if (instance.checkPin(i + "") == true) {
console.log("[ + ] Found correct PIN: " + i)
break
}
}
},
onComplete: function () {},
})
})
इस मामले में यह काम नहीं कर रहा है क्योंकि कोई उदाहरण नहीं है और फ़ंक्शन स्थिर है
स्थिर फ़ंक्शन
यदि फ़ंक्शन स्थिर है, तो आप बस इसे कॉल कर सकते हैं:
//hook2.js
Java.perform(function () {
console.log("[ * ] Starting PIN Brute-force, please wait...")
var PinUtil = Java.use("infosecadventures.fridademo.utils.PinUtil")
for (var i = 1000; i < 9999; i++) {
if (PinUtil.checkPin(i + "") == true) {
console.log("[ + ] Found correct PIN: " + i)
}
}
})
Hook 3 - तर्कों और लौटने वाले मान को पुनः प्राप्त करना
आप एक फ़ंक्शन को हुक कर सकते हैं और इसे प्रिंट करने के लिए बना सकते हैं पारित तर्कों का मान और लौटने वाले मान का मान:
//hook3.js
Java.perform(function () {
console.log("[ * ] Starting implementation override...")
var EncryptionUtil = Java.use(
"infosecadventures.fridademo.utils.EncryptionUtil"
)
EncryptionUtil.encrypt.implementation = function (key, value) {
console.log("Key: " + key)
console.log("Value: " + value)
var encrypted_ret = this.encrypt(key, value) //Call the original function
console.log("Encrypted value: " + encrypted_ret)
return encrypted_ret
}
})
महत्वपूर्ण
इस ट्यूटोरियल में आपने विधियों को विधि के नाम और .implementation का उपयोग करके हुक किया है। लेकिन यदि एक ही नाम वाली एक से अधिक विधियाँ थीं, तो आपको विधि को निर्दिष्ट करने की आवश्यकता होगी जिसे आप हुक करना चाहते हैं आर्गुमेंट्स के प्रकार को इंगित करते हुए।
आप इसे अगले ट्यूटोरियल में देख सकते हैं।
tip
AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाएँ देखें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमारे Twitter 🐦 @hacktricks_live** का पालन करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।