Frida Tutorial 1 - HackTricks
Frida Tutorial 1 - HackTricks
Frida Tutorial 1
If you are interested in hacking carer and hack the unhackable - we are hiring! (fluent polish written
and spoken required).
From: https://medium.com/infosec-adventures/introduction-to-frida-5a3f51595ca1
APK: https://github.com/t0thkr1s/frida-demo/releases
Source Code: https://github.com/t0thkr1s/frida-demo
Python
Frida allows you to insert JavaScript code inside functions of a running application. But you can use
python to call the hooks and even to interact with the hooks.
This is a easy python script that you can use with all the proposed examples in this tutorial:
#hooking.py
import frida, sys
sys.stdin.read()
It is useful to know how to use python with frida, but for this examples you could also call directly
Frida using command line frida tools:
//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;
}
});
Non-Static Function
If you want to call a non-static function of a class, you first need a instance of that class. Then, you
can use that instance to call the function.
To do so, you could find and existing instance and use it:
https://book.hacktricks.xyz/mobile-pentesting/android-app-pentesting/frida-tutorial/frida-tutorial-1 2/5
11/26/22, 8:18 AM Frida Tutorial 1 - HackTricks
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() { }
});
});
In this case this is not working as there isn't any instance and the function is Static
Static Function
//hook2.js
Java.perform(function () {
console.log("[ * ] Starting PIN Brute-force, please wait...")
var PinUtil = Java.use("infosecadventures.fridademo.utils.PinUtil");
https://book.hacktricks.xyz/mobile-pentesting/android-app-pentesting/frida-tutorial/frida-tutorial-1 3/5
11/26/22, 8:18 AM Frida Tutorial 1 - HackTricks
//hook3.js
Java.perform(function() {
console.log("[ * ] Starting implementation override...")
Important
In this tutorial you have hooked methods using the name of the mathod and .implementation. But if
there were more than one method with the same name, you will need to specify the method that
you want to hook indicating the type of the arguments.
If you are interested in hacking carer and hack the unhackable - we are hiring! (fluent polish written
and spoken required).
Previous
https://book.hacktricks.xyz/mobile-pentesting/android-app-pentesting/frida-tutorial/frida-tutorial-1 4/5
11/26/22, 8:18 AM Frida Tutorial 1 - HackTricks
Frida Tutorial
Next
Frida Tutorial 2
https://book.hacktricks.xyz/mobile-pentesting/android-app-pentesting/frida-tutorial/frida-tutorial-1 5/5