声明
本文章中所有内容仅供学习交流使用,不用于其他任何目的,抓包内容、敏感网址、数据接口等均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后果均与作者无关!
侵权通过头像私信或名字简介叫我删除博客谢谢。
部分python代码
def on_message(message, data):
if message["type"] == "send":
print(f"[Frida] {message['payload']}")
elif message["type"] == "error":
print(f"[Frida Error] {message['description']}")
def attach_and_get_rpc():
"""附加到目标进程,加载脚本,返回 rpc 对象"""
print(f"[*] 正在附加到 {PACKAGE_NAME} ...")
# 尝试通过 USB 连接
try:
device = frida.get_usb_device(timeout=5)
print(f"[*] 通过 USB 连接设备: {device.name}")
except Exception as e:
print(f"[*] USB 连接失败: {e}")
# 尝试通过 TCP 连接 (默认 127.0.0.1:27042)
try:
device = frida.get_device("127.0.0.1:27042")
print(f"[*] 通过 TCP 连接设备: {device.name}")
except Exception as e2:
print(f"[-] TCP 连接也失败: {e2}")
print("\n请确保:")
print("1. 设备已通过 USB 连接或 adb tcpip 5555 开启网络调试")
print("2. 已在设备上运行 frida-server")
print("3. 如果是网络调试,运行: adb forward tcp:27042 tcp:27042")
return None
# 尝试附加到进程
try:
# 先尝试 spawn 方式
pid = device.spawn([PACKAGE_NAME])
session = device.attach(pid)
device.resume(pid)
print(f"[*] Spawn 进程 PID={pid}")
except Exception as e:
print(f"[*] Spawn 失败: {e}")
# 尝试直接附加到已运行的进程
try:
session = device.attach(PACKAGE_NAME)
print(f"[*] 附加到已运行的进程")
except Exception as e2:
print(f"[-] 附加失败: {e2}")
print("\n请确保 APP 已启动并运行")
return None
time.sleep(1)
with open(SCRIPT_PATH, "r", encoding="utf-8") as f:
script_code = f.read()
script = session.create_script(script_code)
script.on("message", on_message)
script.load()
print(f"[*] 脚本加载成功")
# 等待 hooks 初始化
time.sleep(3)
print(f"[*] RPC 就绪")
return script
结果
