Frida安装与使用

安装

# 指定版本安装
pip install frida==16.2.1
pip install frida-tools==12.0.0

# server安装
# 查看cpu架构 选择对应版本server下载
adb shell getprop ro.product.cpu.abi
# arm64-v8a

# 2 下载frida-server
https://github.com/frida/frida/releases

# 3 解压,上传到手机 /data/local/tmp/ 目录下
	-解压得到文件,把文件上传到手机
 adb push frida-server/frida-server-16.2.1-android-arm64  /data/local/tmp/

# 4 赋予可执行权限
adb shell  # 进入手机命令行
su        # 切换为超级用户
cd /data/local/tmp/
chmod 766 frida-server-16.2.1-android-arm64  # 加入执行权限
ls -al   # 查看权限
./frida-server-16.2.1-android-arm64  # 默认启动端口27042(可能会被检测)
./frida-server-16.2.1-android-arm64 -l 12345 # 指定端口启动

# 注意:frida,frida-tools,frida-server 版本要一致

简单运行

  • 启动手机server 第一次运行的话要给fs权限 chmod 766 (出现问题:方案一:重启手机 方案二:问下ai)

  • PC设置端口转发
# 方式一:命令行中敲
adb forward tcp:27042 tcp:27042
adb forward tcp:27043 tcp:27043

# 方式二:使用python执行
import subprocess

subprocess.getoutput("adb forward tcp:27042 tcp:27042")
subprocess.getoutput("adb forward tcp:27043 tcp:27043")

简单使用frida

import frida

# 连接到设备
device = frida.get_usb_device() # 连接usb设备
# device = frida.get_remote_device() # 连接远程设备 特定IP或端口frida.get_device_manager().add_remote_device("IP:PORT")
print(f"设备信息:{device}")
# 列出所有运行中的进程

# 列出所有运行中的进程
processes = device.enumerate_processes()
for process in processes:
    print(f"PID: {process.pid}, Name: {process.name}")

""" 运行结果:
设备信息:Device(id="3142def", name="Redmi K30 Pro Zoom Edition", type='usb')
PID: 1, Name: init
PID: 580, Name: init
PID: 583, Name: ueventd
PID: 625, Name: logd
PID: 627, Name: servicemanager
...
"""

front_app = device.get_frontmost_application() #  可以获得前台运行的应用程序app包名,应用名,pid
bus = device.get_bus() #  内部消息总线对象,用于处理与设备或进程相关的消息通信
print(bus)
print(front_app)

"""运行结果: 
<frida.core.Bus object at 0x000001F153BCCF40>
Application(identifier="com.eg.android.AlipayGphone", name="支付宝", pid=30617, parameters={})
"""

小试牛刀 - 某APP密码加密

# 目标请求
POST https://dealercloudapi.che168.com/tradercloud/sealed/login/login.ashx HTTP/1.1
Accept-Encoding: gzip
Cache-Control: public, max-age=0
Connection: Keep-Alive
Content-Length: 269
Content-Type: application/x-www-form-urlencoded
Host: dealercloudapi.che168.com
User-Agent: okhttp/3.14.9
traceid: atc.android_0adb59e6-905b-4010-b6f1-a64fe980c619

_appid=atc.android&_sign=87EC875A84B7BABD07F7C845AF396F5B&appversion=3.71.0&channelid=csy&pwd=e10adc3949ba59abbe56e057f20f883e&signkey=&type=&udid=rwtj9XIE5TmYsQGbg2ePq4iyj7%2B%2Fg65nkVAAV7qYiQBGvmDxxfMixazHCJP3%20W0xPP%2FUao77UwzePxk5M9L3l2w%3D%3D&username=186XXXXX555


# 使用jadx反编译搜索一下关键字 url 和 参数名都行  "pwd" 或 login.ashx



Java.perform(function () {
    let SecurityUtil = Java.use("com.autohome.ahkit.utils.SecurityUtil");
    SecurityUtil["encodeMD5"].implementation = function (str) {
        console.log(`SecurityUtil.encodeMD5 is called: str=${str}`);
        let result = this["encodeMD5"](str);
        console.log(`SecurityUtil.encodeMD5 result=${result}`);
        return result;
    };
});

// frida -U -f com.che168.autotradercloud -l hook.js

# 就是走的我分析的方法进行的加密

# 使用python hook
import frida
import sys
# 连接手机设备
device = frida.get_usb_device()
session = device.attach("车智赢+")

js_code = """
Java.perform(function () {
    //找到类 反编译的首行+类名:com.autohome.ahkit.utils下的
    var SecurityUtil = Java.use("com.autohome.ahkit.utils.SecurityUtil");

    //替换类中的方法
    SecurityUtil.encodeMD5.implementation = function(str){
        console.log("参数:",str);
        var res = this.encodeMD5(str); //调用原来的函数
        console.log("返回值:",res);
        return str;
    }
});
"""

script = session.create_script(js_code)

def on_message(message, data):
    print(message, data)

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

补充知识

# Spawn 方式适应场景:会在目标应用程序启动时注入 Frida 的 Agent 代码。即使目标应用已经运行,使用 Spawn 模式时也会重新启动应用。
# frida -U -f <包名> -l hook.js 
需要在应用程序启动的早期阶段进行 Hook。
需要访问和修改应用程序的内部状态,例如应用程序的全局变量、静态变量等。
需要 Hook 应用程序的初始化过程,以实现对应用程序的自定义初始化逻辑。
需要在应用程序的上下文中执行代码,并与其他模块或库进行交互。
"""
device = frida.get_remote_device()
pid = device.spawn(["com.che168.autotradercloud"])
session = device.attach(pid)
"""

# Attach 方式适应场景:Attach 模式是在目标应用已经运行的情况下,动态地连接并注入 Frida 的 Agent 代码
# frida -UF -l hook.js
需要对已经运行的应用程序进行 Hook,即动态地连接到正在运行的进程。
需要在应用程序运行时拦截和修改特定的方法调用。
需要实时监视和修改应用程序的行为,例如参数修改、返回值篡改等。
需要对应用程序进行调试和分析,以查找潜在的问题和漏洞。
"""
device = frida.get_remote_device()
session = device.attach("应用名")
"""
posted @   郭楷丰  阅读(145)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
Live2D
欢迎阅读『Frida安装与使用』

点击右上角即可分享
微信分享提示
♡✭
♡✭
♡✭
♡✭
♡✭