Frida使用教程

7,171 阅读1分钟

一、安装 frida

命令

pip install frida

image-20210531000139300

pip install frida-tools

image-20210531214812220

安装过程出现以下错误:

ValueError: check_hostname requires server_hostname

解决方法:

  1. 关闭翻墙软件
  2. 关闭抓包工具

二、安装 frida-server

2.1 下载

下载地址:github.com/frida/frida…

Android Tutorials地址:frida.re/docs/androi…

查看cpu架构

adb shell getprop ro.product.cpu.abi 

选择对应架构的server下载

image-20210531000738397

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

image-20210531215140118

三、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 打印日志包含 ?号,则操作成功

image-20210602002229461

四、参考资料

frida - android : frida.re/docs/exampl…

hook工具frida原理及使用 : www.jianshu.com/p/51e6aef17…

Hook神器家族的Frida工具使用详解:www.520monkey.com/archives/12…