htARTE(HackTricks AWS Red Team Expert) を通じて、ゼロからヒーローまでAWSハッキングを学びましょう !
サイバーセキュリティ企業 で働いていますか? HackTricks で会社を宣伝 してみたいですか?または、最新バージョンの PEASS を入手したり、HackTricks を PDF でダウンロード したいですか?SUBSCRIPTION PLANS をチェックしてください!
バグバウンティのヒント : ハッカーによって作成されたプレミアムバグバウンティプラットフォームである Intigriti にサインアップ してください!https://go.intigriti.com/hacktricks で今すぐ参加し、最大 $100,000 のバウンティを獲得しましょう!
この投稿の要約 : https://11x256.github.io/Frida-hooking-android-part-2/ (パート 2、3、4)
APK およびソースコード : https://github.com/11x256/frida-android-examples
パート 1 は非常に簡単です。
オリジナルコードの一部は機能せず、ここで修正されています。
パート 2
ここでは、同じ名前の関数をフックする例 と、異なるパラメータを持つ関数をフックする方法を示します。
また、独自のパラメータで関数を呼び出す方法 を学びます。
最後に、クラスのインスタンスを見つけ、その関数を呼び出す方法 の例があります。
Copy //s2.js
console .log ( "Script loaded successfully " );
Java .perform ( function x () {
console .log ( "Inside java perform function" );
var my_class = Java .use ( "com.example.a11x256.frida_test.my_activity" );
//Hook "fun" with parameters (int, int)
my_class . fun .overload ( "int" , "int" ). implementation = function (x , y) { //hooking the old function
console .log ( "original call: fun(" + x + ", " + y + ")" );
var ret_value = this .fun ( 2 , 5 );
return ret_value;
};
//Hook "fun" with paramater(String)
var string_class = Java .use ( "java.lang.String" );
my_class . fun .overload ( "java.lang.String" ). implementation = function (x) { //hooking the new function
console .log ( "*" )
//Create a new String and call the function with your input.
var my_string = string_class .$new ( "My TeSt String#####" );
console .log ( "Original arg: " + x);
var ret = this .fun (my_string);
console .log ( "Return value: " + ret);
console .log ( "*" )
return ret;
};
//Find an instance of the class and call "secret" function.
Java .choose ( "com.example.a11x256.frida_test.my_activity" , {
onMatch : function (instance) {
console .log (tring , and the it has "Found instance: " + instance);
console .log ( "Result of secret func: " + instance .secret ());
} ,
onComplete : function () { }
});
});
あなたは、Stringを作成するためにまず_java.lang.String_クラスを参照し、そのクラスのStringを内容とする_$new_オブジェクトを作成していることがわかります。これはクラスの新しいオブジェクトを作成する正しい方法です。しかし、この場合、this.fun("hey there!")
のように任意のStringをthis.fun()
に渡すことができます。
Python
Copy // loader . py
import frida
import time
device = frida . get_usb_device ()
pid = device . spawn ([ "com.example.a11x256.frida_test" ])
device . resume (pid)
time . sleep ( 1 ) #Without it Java.perform silently fails
session = device . attach (pid)
script = session . create_script ( open ( "s2.js" ). read ())
script . load ()
#prevent the python script from terminating
raw_input ()
パート3
Python
次に、Pythonを使用してフックされたアプリにコマンドを送信して関数を呼び出す方法を見ていきます:
Copy // loader . py
import time
import frida
def my_message_handler ( message , payload ):
print message
print payload
device = frida . get_usb_device ()
pid = device . spawn ([ "com.example.a11x256.frida_test" ])
device . resume (pid)
time . sleep ( 1 ) # Without it Java.perform silently fails
session = device . attach (pid)
with open ( "s3.js" ) as f :
script = session . create_script (f. read ())
script . on ( "message" , my_message_handler)
script . load ()
command = ""
while 1 == 1 :
command = raw_input ( "Enter command:\n1: Exit\n2: Call secret function\n3: Hook Secret\nchoice:" )
if command == "1" :
break
elif command == "2" :
script . exports . callsecretfunction ()
elif command == "3" :
script . exports . hooksecretfunction ()
コマンド "1 " は終了 します、コマンド "2 " はクラスのインスタンスを見つけてプライベート関数 secret() を呼び出し 、コマンド "3 " は関数 secret() をフック して異なる文字列 を返す ようにします。
したがって、"2 " を呼び出すと実際の秘密 が表示されますが、"3 " を呼び出してから "2 " を呼び出すと偽の秘密 が表示されます。
JS
Copy console .log ( "Script loaded successfully " );
var instances_array = [];
function callSecretFun () {
Java .perform ( function () {
if ( instances_array . length == 0 ) { // if array is empty
Java .choose ( "com.example.a11x256.frida_test.my_activity" , {
onMatch : function (instance) {
console .log ( "Found instance: " + instance);
instances_array .push (instance)
console .log ( "Result of secret func: " + instance .secret ());
} ,
onComplete : function () { }
});
}
else { //else if the array has some values
console .log ( "Result of secret func: " + instances_array[ 0 ] .secret ());
}
});
}
function hookSecret () {
Java .perform ( function () {
var my_class = Java .use ( "com.example.a11x256.frida_test.my_activity" );
var string_class = Java .use ( "java.lang.String" );
my_class . secret .overload (). implementation = function (){
var my_string = string_class .$new ( "TE ENGANNNNEEE" );
return my_string;
}
});
}
rpc .exports = {
callsecretfunction : callSecretFun ,
hooksecretfunction : hookSecret
};
パート4
ここでは、JSONオブジェクトを使用してPythonとJSが相互作用する方法 を示します。JSはsend()
関数を使用してデータをPythonクライアントに送信し、Pythonはpost()
関数を使用してデータをJSスクリプトに送信します。JSはPythonからの応答を受信するまで実行をブロックします 。
Python
Copy // loader . py
import time
import frida
def my_message_handler ( message , payload ):
print message
print payload
if message [ "type" ] == "send" :
print message [ "payload" ]
data = message [ "payload" ]. split ( ":" ) [ 1 ] . strip ()
print 'message:' , message
data = data . decode ( "base64" )
user , pw = data . split ( ":" )
data = ( "admin" + ":" + pw) . encode ( "base64" )
print "encoded data:" , data
script . post ({ "my_data" : data}) # send JSON object
print "Modified data sent"
device = frida . get_usb_device ()
pid = device . spawn ([ "com.example.a11x256.frida_test" ])
device . resume (pid)
time . sleep ( 1 )
session = device . attach (pid)
with open ( "s4.js" ) as f :
script = session . create_script (f. read ())
script . on ( "message" , my_message_handler) # register the message handler
script . load ()
raw_input ()
JS
JS
Copy console .log ( "Script loaded successfully " );
Java .perform ( function () {
var tv_class = Java .use ( "android.widget.TextView" );
tv_class . setText .overload ( 'java.lang.CharSequence' ). implementation = function (x) {
var string_to_send = x .toString ();
var string_to_recv = "" ;
send (string_to_send); // send data to python code
recv ( function (received_json_object) {
string_to_recv = received_json_object .my_data;
}) .wait (); //block execution till the message is received
console .log ( "Final string_to_recv: " + string_to_recv)
return this .setText (string_to_recv);
}
});
第5部分は新しい情報がないため、説明はしません。しかし、読みたい場合はこちらから読むことができます: https://11x256.github.io/Frida-hooking-android-part-5/
バグバウンティのヒント : Intigriti にサインアップ してください。これは、ハッカーによって作成されたプレミアムバグバウンティプラットフォーム です!https://go.intigriti.com/hacktricks で参加し、最大**$100,000**のバウンティを獲得しましょう!
htARTE(HackTricks AWS Red Team Expert) で**ゼロからヒーローまでのAWSハッキングを学びましょう**!
サイバーセキュリティ企業 で働いていますか?HackTricksで会社を宣伝 したいですか?または、PEASSの最新バージョンにアクセス したいですか、またはHackTricksをPDFでダウンロード したいですか?SUBSCRIPTION PLANS をチェックしてください!
Last updated 2 months ago