2、frida入门教程-hook

当前第二篇。第一篇为:frida入门教程-安装

 

frida常见命令

---------------------------------------------------------------------------------

方式一、frida直接关联 js脚本hook

1、编写js hook函数

test.js源码:

Interceptor.attach(Module.findExportByName("libc.so" , "open"), {
    onEnter: function(args) {
        console.log("open() called!" )
    },
    onLeave:function(retval){
    
    }
});

2、执行hook(以下二选1即可)

①启动时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

----------------------------------------------------------------------------------

方式二、python命令注入 js脚本hook

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江西省遂川县常驻深圳大使

喜欢本文,打赏下作者吧~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值