Frida Tutorial 1

Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks

Bug bounty tip: sign up for Intigriti, a premium bug bounty platform created by hackers, for hackers! Join us at https://go.intigriti.com/hacktricks today, and start earning bounties up to $100,000!

This is a summary of the post: 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は、実行中のアプリケーションの関数内にJavaScriptコード挿入することを可能にします。しかし、pythonを使用してフック呼び出すことや、フック対話することもできます。

これは、このチュートリアルで提案されたすべての例で使用できる簡単な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>

PythonをFridaと一緒に使う方法を知っておくことは便利ですが、これらの例ではコマンドラインFridaツールを直接呼び出すこともできます:

frida -U --no-pause -l hookN.js -f infosecadventures.fridademo

Hook 1 - Boolean Bypass

ここでは、クラス infosecadventures.fridademo.utils.PinUtil から boolean メソッド (checkPin) を hook する方法を示します。

//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() { }
});
});

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");

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 を使用してメソッドをフックしました。しかし、同じ名前のメソッドが複数ある場合引数の型を指定してフックしたいメソッドを特定する必要があります

それについては次のチュートリアルで確認できます。

バグバウンティのヒント: Intigritiサインアップしてください。これはハッカーによって、ハッカーのために作られたプレミアムバグバウンティプラットフォームです!今日、https://go.intigriti.com/hacktricksに参加して、$100,000までのバウンティを獲得し始めましょう!

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE) GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE)

HackTricksをサポートする

Last updated