Android逆向Frida的python调用和调用js在切换默认端口情况下的两种启动模式--frida16.0.19

准备工作

  1. frida-sever端口更改启动
./frida-server-16.0.2-android-arm64  -l 0.0.0.0:8888

在这里插入图片描述

  1. frida-sever的端口转发(另外启动一个cmd)
adb forward tcp:8888 tcp:8888

在这里插入图片描述

一、Python调用

新版的frida已经支持名字启动了,可以看启动方法一

import frida
import sys

host = "127.0.0.1:8888"
def on_message(message, data):
    if message['type'] == 'send':
        print("[*] {0}".format(message['payload']))
    else:
        print(message)

test_signature = '''
    Java.perform(function () {
    你的hook代码
})
'''
# 启动方式1,适用于已经启动了的APP 可以hook APP运行阶段
manager = frida.get_device_manager()
# process =  manager.add_remote_device(host).get_frontmost_application() #可以查看当前启动的APP名称是什么,新版的Frida可以使用名字启动了。
process = manager.add_remote_device(host).attach("MySecondApplication")
script = process.create_script(test_signature)

script.on('message', on_message)
script.load()
sys.stdin.read()

# 启动方式2 spawn 重启APP 可以hook APP启动阶段
manager = frida.get_device_manager()
device = manager.add_remote_device(host)
pid = device.spawn(['com.dta.mysecondapplication'])
process = device.attach(pid)
script = process.create_script(test_signature)
script.on('message', on_message)
print('[*] Running')
script.load()

device.resume(pid)

sys.stdin.read()

如果担心这种注释写法会js代码不能够及时检查可以创建一个js文件,然后这样调用,js文件就放之前test_signature写的代码就可以了,不需要修改。

import frida
import sys

host = "127.0.0.1:8888"
def on_message(message, data):
    if message['type'] == 'send':
        print("[*] {0}".format(message['payload']))
    else:
        print(message)

with open('./agent.js') as f:
    test_js = f.read()
 
# 启动方式1
manager = frida.get_device_manager()
# process =  manager.add_remote_device(host).get_frontmost_application()
process = manager.add_remote_device(host).attach("MySecondApplication")
script = process.create_script(test_js)
script.on('message', on_message)
script.load()
print(script.exports_sync.add(3, 2))
sys.stdin.read()

# # # 启动方式2 spawn 重启APP 可以hook APP启动阶段
# manager = frida.get_device_manager()
# device = manager.add_remote_device(host)
# pid = device.spawn(['com.dta.mysecondapplication'])
# process = device.attach(pid)
# script = process.create_script(test_js)
# script.on('message', on_message)
# print('[*] Running')
# script.load()
# device.resume(pid)
# sys.stdin.read()

二、本地CMD调用JS(run.js)

run.js文件内容

function main() {
    
    
    Java.perform(function () {
    
    
    你的hook代码
    })
}

setImmediate(main)

这个和python的启动方式1是一样的效果,不过这里要写包名,适用于已经启动了的APP,可以hook APP运行阶段

frida -H 127.0.0.1:8888 -F com.dta.mysecondapplication -l run.js

这个和python的启动方式2是一样的效果,重启APP,可以hook APP启动阶段

frida -H 127.0.0.1:8888 -f com.dta.mysecondapplication -l run.js

更多参数使用frida --help查看

frida --help

三、问题

如果遇到连接不上的情况,查看frida-sever是否断开连接,如果连接正常,将frida-sever的端口转发再做一次。
在这里插入图片描述
在这里插入图片描述

四、 借鉴

猿人学
r0ysue的大数据安全技术学习

猜你喜欢

转载自blog.csdn.net/qq_41866988/article/details/130667502