0
点赞
收藏
分享

微信扫一扫

一、Lamdba 表达式与函数式接口

seuleyang 2024-01-25 阅读 16

文章目录

一、前言

frida是一款基于python + javascript 的hook框架,可运行在android ios linux winosx等各平台,主要使用动态二进制插桩技术

官方网站:https://frida.re/docs/home/
api地址:https://frida.re/docs/javascript-api/

二、安装

需要准备的

  • 一台root好的安卓手机
  • frida-server:运行在手机上,安卓6使用frida-server-12.8.10,安卓8以上新版本
  • frida-tools:python模块 提供cli工具命令跟frida-server交互pip install frida-tools
  • frida:python模块 pip install frida

frida配置
下载地址:https://github.com/frida/frida/releases,需要查看手机架构下载对应的frida-server安装包

查看手机架构命令如下

adb shell getprop ro.product.cpu.abi

效果
在这里插入图片描述
对应的frida-server
在这里插入图片描述
下载好后frida-server解压push到手机,增加执行权限并且运行起来

adb push frida-server /data/local/tmp/
adb shell
su
cd /data/local/tmp
## 确定手机当前目录是root权限
chmod 777 frida-server
./frida-server&

检测frida是否运行成功

frida-ps -U

如果连接不上可以尝试端口转发到电脑

adb forward tcp:27043 tcp:27043
adb forward tcp:27042 tcp:27042

三、hook调试,hook java类

app已经启动了,访问成员变量,固定写法如下:

jscode = '''
	Java.perform(
		function(){
			console.log('hook住了')
			var MainActivity = Java.use('类名')
			MainActivity.onClick.implementation = function(参数){
				# 执行原有逻辑
				this.onClick(v)
				# 实现自己的逻辑
				console.log('打印' + this.m.value)
			}
		}
	)
'''
# app已经启动了
process = frida.get_usb_device(-1).attach('这里写软件的包名/进程名')
script = process.create_script(jscode)
script.on('message', on_message)
print('[*] Hook Start Running')
script.load()
# 守护进程
sys.stdin.read()

app启动阶段,访问成员变量,固定写法如下:

jscode = '''
	Java.perform(
		function(){
			console.log('hook住了')
			var MainActivity = Java.use('类名')
			MainActivity.onClick.implementation = function(参数){
				# 执行原有逻辑
				this.onClick(v)
				# 实现自己的逻辑
				console.log('打印' + this.m.value)
			}
		}
	)
'''
# app启动阶段
device = frida.get_usb_device(-1)
pid = device.spawn(["这里写软件的包名/进程名"])
process = device.attach(pid)
script = process.create_script(jscode)
script.on('message', on_message)
print('[*] Hook Start Running')
script.load()
device.resume(pid)
sys.stdin.read()

匿名类,内部类访问外部类,固定写法如下:

jscode = '''
	Java.perform(
		function(){
			console.log('hook住了')
			# 匿名类 类名$xxx
			var MainActivity = Java.use('类名$xxx')
			MainActivity.onClick.implementation = function(参数){
				# 内部类访问外部类
				console.log(this.this$0.value.m.value)
				# 执行原有逻辑
				this.onClick(v)
				# 实现自己的逻辑
				console.log('打印' + this.m.value)
			}
		}
	)
'''
# app已经启动了
process = frida.get_usb_device(-1).attach('这里写软件的包名/进程名')
script = process.create_script(jscode)
script.on('message', on_message)
print('[*] Hook Start Running')
script.load()
# 守护进程
sys.stdin.read()
举报

相关推荐

0 条评论