frida_hook.py #coding=utf-8 import os import time import sys import frida import requests import json
#打印javascript脚本返回消息 def on_message(message, data): print(message) if isinstance(message, dict): data = toburp(message["payload"].encode('utf-8')) script.post(data) else: if message.has_key("payload"): print(message["payload"]) #获取设备应用名 def get_application_name(device, identifier): for p in device.enumerate_applications(): if p.identifier == identifier: return p.name #获取设备进程pid def get_process_pid(device, application_name): for p in device.enumerate_processes(): if p.name == application_name: return p.pid return -1
def get_processes(device, process): processes = device.enumerate_processes(scope='full') ret = [] for proc in processes: print(proc.pid, proc.name) if proc.name == process: print(proc) ret.append(proc.pid) return ret
def main(): #连接设备 device = frida.get_device_manager().enumerate_devices()[-1] package_name = "cn.com.spdb.mobilebank.per" pid = device.spawn(package_name) '''pid = get_processes(device, package_name)[0] if pid != -1: print("[+] killing {0}".format(pid)) # device.kill(pid) time.sleep(0.3) while(1): pid = get_process_pid(device, package_name) print(pid) if pid == -1: print("[-] {0} is not found...".format(package_name)) time.sleep(2) else: break''' print("[+] Injecting script to {0}({1})".format(package_name, pid)) session = None try: #attach目标进程 session = frida.get_device_manager().enumerate_devices()[-1].attach(pid) #加载javaScript脚本 script_content = open("hook.js").read() global script script = session.create_script(script_content) script.on("message", on_message) script.load() device.resume(pid) sys.stdin.read() except KeyboardInterrupt as e: if session is not None: session.detach() device.kill(pid) sys.exit(0) if __name__ == "__main__": main()