一、安装 frida
命令
pip install frida

pip install frida-tools

安装过程出现以下错误:
ValueError: check_hostname requires server_hostname
解决方法:
- 关闭抓包工具
二、安装 frida-server
2.1 下载
下载地址:https://github.com/frida/frida/releases
Android Tutorials地址:https://frida.re/docs/android/
查看cpu架构
adb shell getprop ro.product.cpu.abi
选择对应架构的server下载

gadget适用于当无法获取root权限时可以将gadget.so植入目标apk中重打包,通过修改应用,使得server以应用的权限启动;还有frida-gum、frida-gumjs、frida-inject、frida-devkit等
2.2 启动 firida-server
操作步骤:解压上面下载的文件,然后 push 到手机 /data/local/tmp,接着启动 firda-server 服务
$ adb root
$ adb push frida-server-14.2.18-android-arm /data/local/tmp
$ adb shell
$ su
$ cd /data/local/tmp
$ chmod 777 /data/local/tmp/frida-server-14.2.18-android-arm
$ ./frida-server-14.2.18-android-arm
端口映射
adb forward tcp:27042 tcp:27042
adb forward tcp:27043 tcp:27043
查看进程
frida-ps -U

三、hook进程
import frida
import sys
def on_message(message, data):
if message['type'] == 'send':
print("{0}".format(message['payload']))
else:
print(message)
jsHook = """
Java.perform(function () {
// hook Log.w(tag,msg) 方法
var log = Java.use('android.util.Log');
log.w.overload("java.lang.String","java.lang.String").implementation = function(tag,msg){
console.log("tag",tag)
console.log("msg",msg)
return this.w(tag,msg+"?") // msg 后面添加 ?
};
});
"""
process = frida.get_usb_device().attach("com.xxx.tool") // 目标包名
script = process.create_script(jsHook)
script.on('message', on_message)
print(' Running CTF')
script.load()
sys.stdin.read()
如果 logcat 打印日志包含 ?号,则操作成功

四、参考资料
frida - android : https://frida.re/docs/examples/android/
hook工具frida原理及使用 : https://www.jianshu.com/p/51e6aef175a2
Hook神器家族的Frida工具使用详解:http://www.520monkey.com/archives/1256
|