frida常见命令
---------------------------------------------------------------------------------
test.js源码:
Interceptor.attach(Module.findExportByName("libc.so" , "open"), {
onEnter: function(args) {
console.log("open() called!" )
},
onLeave:function(retval){
}
});
①启动时hook,CMD输入:
frida -U -f com.test.apk -l test.js --no-pause
将上诉 com.test.apk 换成你手机里安装好的任意apk包名
②启动apk后 hook
frida -U -f com.test.apk --no-pause
%load test.js
----------------------------------------------------------------------------------
1、编写python 和js hook函数
init.py源码:
import frida
import sys
device = frida.get_usb_device()
pid = device.spawn(["com.test.apk"])
session = device.attach(pid)
device.resume(pid)
src = """
var openPtr = Module.findExportByName("libc.so", "open");
Interceptor.attach(openPtr, {
onEnter : function(args){
var pathPtr = args[0];
//pathPtr.writeUtf8String("/sdcard/122");
send("open called ! path=" + pathPtr.readUtf8String());
},
onLeave : function(retval){
//send("open leave.....");
}
});
"""
def on_message(message, data):
print(message["payload"]) #message为map,取出key payload 的value
script = session.create_script(src)
#设置message 回调函数为 on_message。js 调用send 就会发到 on_message
script.on("message", on_message)
script.load()
sys.stdin.read()
2、cmd输入:
python init.py
frida js官方文档入口:https://www.frida.re/docs/javascript-api/#interceptor