墨锋
Published on 2025-03-29 / 4 Visits
0
0

[翻译]FRIDA官方文档-示例-macOS

macOS

Frida 环境配置说明

在 macOS 上配置 Frida 时,需要授权 Frida 使用 task_for_pid 权限来访问目标进程。

如果通过 GUI 以本地用户身份运行 Frida 工具(例如通过 Terminal.app),系统会通过 taskgate 机制提示您授权该进程。

您可能还需要临时禁用系统完整性保护(System Integrity Protection)。

Objective-C 基础监控示例

 import frida
 import sys
 ​
 def on_message(message, data):
     print("[{}] => {}".format(message, data))
 ​
 def main(target_process):
     session = frida.attach(target_process)
 ​
     script = session.create_script("""
         // 获取 NSApplicationDelegate 的 applicationWillFinishLaunching: 方法
         const appWillFinishLaunching = ObjC.classes.NSApplicationDelegate['- applicationWillFinishLaunching:'];
         
         // hook 该方法实现
         Interceptor.attach(appWillFinishLaunching.implementation, {
           onEnter(args) {
             // 注意:Objective-C 方法参数结构如下:
             // 0. 'self' 对象指针
             // 1. 方法选择器 (applicationWillFinishLaunching:)
             // 2. 该方法的第一个参数
             const notification = new ObjC.Object(args[2]);
 ​
             // 转换为 JS 字符串并输出日志
             const notificationStr = notification.absoluteString().toString();
             console.log('应用即将完成启动,通知对象: ' + notificationStr);
           }
         });
     """)
     script.on("message", on_message)
     script.load()
     print("[!] 使用 Ctrl+D(UNIX)或 Ctrl+Z(Windows/cmd.exe)退出被检测程序。\n\n")
     sys.stdin.read()
     session.detach()
 ​
 ​
 if __name__ == "__main__":
     main("Safari")

关键术语说明:

  1. task_for_pid - macOS 内核级进程控制权限

  2. taskgate - macOS 的权限请求提示机制

  3. System Integrity Protection (SIP) - 系统完整性保护,苹果的系统级安全机制

  4. ObjC.classes - Frida 对 Objective-C 运行时的封装接口

  5. Interceptor.attach - Frida 的动态代码插桩功能


原文链接:macOS | Frida • A world-class dynamic instrumentation toolkit

翻译来源:DeepSeek



Comment