nowsecure/r2frida

GitHub: nowsecure/r2frida

将 radare2 的静态分析能力与 Frida 的动态插桩技术相结合,让用户能通过 r2 命令直接操控运行中的本地或远程进程。

Stars: 1380 | Forks: 135

# r2frida Radare2 和 Frida 强强联手 [![ci](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/4fa6bba27c151350.svg)](https://github.com/nowsecure/r2frida/actions/workflows/ci.yml) [![radare2](https://img.shields.io/badge/radare2-6.0.4-green)](https://github.com/radareorg/radare2)

## 描述 [radare2](https://www.radare.org) 的独立插件,它内置了 [frida](https://www.frida.re) 并允许使用 r2 命令对本地或远程 进程进行检测,而不仅限于 Frida 脚本。 Radare 项目提供了一整套用于逆向工程的工具链, 它不仅积极维护,而且提供完善的功能, 并支持通过其他编程语言和工具扩展其特性。 Frida 是一个动态检测工具包,它可以轻松地 通过注入您自己的 JavaScript 来检查和操作正在运行的进程, 并可选择与您的脚本进行通信。 ## 功能特性 * 运行未经修改的 Frida 脚本(使用 `:.` 命令) * 在任何进程中执行 C、JavaScript 或 TypeScript 代码片段 * 可以在本地或远程系统中附加、生成或启动进程 * 列出节区、符号、导出、协议、类、方法 * 在 agent 内部或从主机搜索内存中的值 * 替换方法实现或使用简短命令创建 hook * 在目标进程中加载库和框架 * 支持 Dalvik、Java、ObjC、Swift 和 C 接口 * 操作文件描述符和环境变量 * 向进程发送信号,继续执行,设置断点 * r2frida io 插件同时也是 **fs** 和 **debug** 后端 * 使用 r2pipe 自动化 r2 和 frida * 读取/写入进程内存 * 调用函数、系统调用和原始代码片段 * 通过 USB 或 TCP/IP 连接到 frida-server * 枚举应用程序和进程 * 跟踪寄存器,函数参数 * 已在 Linux、Windows、macOS、iOS 和 Android 的 x64、arm32 和 arm64 架构上测试通过 * 不需要在主机上安装 frida(不需要 frida-tools) * 通过在 agent 中运行的插件扩展 r2frida 命令 * 修改页面权限,修补代码和数据 * 按名称或地址解析符号,并将其作为 flag 导入到 r2 * 从 agent 在主机上运行 r2 命令 * 在远程目标进程内使用 r2 api 并运行 r2 命令。 * 使用 `:db` api 实现原生断点 * 使用 `r_fs` api 访问远程文件系统。 ## 安装 推荐通过 r2pm 安装 r2frida: ``` $ r2pm -ci r2frida ``` 不需要编译的二进制构建版本将很快在 `r2pm` 和 `r2env` 中得到支持。与此同时,请随时从 [Releases 页面](https://github.com/nowsecure/r2frida/releases) 下载最新的构建版本。 ## 编译 ### 依赖项 * radare2 * pkg-config (Windows 上不需要) * curl 或 wget * make, gcc * npm, nodejs (即将移除) 在 GNU/Debian 中,您需要安装以下软件包: ``` $ sudo apt install -y make gcc libzip-dev nodejs npm curl pkg-config git ``` ### 说明 ``` $ git clone https://github.com/nowsecure/r2frida.git $ cd r2frida $ make $ make user-install ``` ### Windows * 安装 meson 和 Visual Studio * 将最新的 radare2 发布 zip 包解压到 r2frida 根目录 * 将其重命名为 `radare2`(而不是 radare2-x.y.z) * 使 VS 编译器在 PATH 中可用(`preconfigure.bat`) * 运行 `configure.bat` 然后运行 `make.bat` ## 用法 为了测试,使用 `r2 frida://0`,因为在 frida 中附加到 pid0 是一个特殊的 在本地运行的会话。现在您可以运行 `:?` 命令来获取可用命令的列表。 ``` $ r2 'frida://?' r2 frida://[action]/[link]/[device]/[target] * action = list | apps | attach | spawn | launch * link = local | usb | remote host:port * device = '' | host:port | device-id * target = pid | appname | process-name | program-in-path | abspath Local: * frida://? # show this help * frida:// # list local processes * frida://0 # attach to frida-helper (no spawn needed) * frida:///usr/local/bin/rax2 # abspath to spawn * frida://rax2 # same as above, considering local/bin is in PATH * frida://spawn/$(program) # spawn a new process in the current system * frida://attach/(target) # attach to target PID in current host USB: * frida://list/usb// # list processes in the first usb device * frida://apps/usb// # list apps in the first usb device * frida://attach/usb//12345 # attach to given pid in the first usb device * frida://spawn/usb//appname # spawn an app in the first resolved usb device * frida://launch/usb//appname # spawn+resume an app in the first usb device Remote: * frida://attach/remote/10.0.0.3:9999/558 # attach to pid 558 on tcp remote frida-server Environment: (Use the `%` command to change the environment at runtime) R2FRIDA_SAFE_IO=0|1 # Workaround a Frida bug on Android/thumb R2FRIDA_DEBUG=0|1 # Used to debug argument parsing behaviour R2FRIDA_COMPILER_DISABLE=0|1 # Disable the new frida typescript compiler (`:. foo.ts`) R2FRIDA_AGENT_SCRIPT=[file] # path to file of the r2frida agent ``` ### 示例 ``` $ r2 frida://0 # same as frida -p 0, connects to a local session ``` 您可以按名称或 pid 附加、生成或启动任何程序,以下命令行将附加到第一个名为 `rax2` 的进程(在另一个终端中运行 `rax2 -` 以测试此命令) ``` $ r2 frida://rax2 # attach to the first process named `rax2` $ r2 frida://1234 # attach to the given pid ``` 使用二进制文件的绝对路径将生成该进程: ``` $ r2 frida:///bin/ls [0x00000000]> :dc # continue the execution of the target program ``` 也适用于带参数的情况: ``` $ r2 frida://"/bin/ls -al" ``` 对于 USB 调试 iOS/Android 应用,请使用这些操作。请注意,`spawn` 可以替换为 `launch` 或 `attach`,进程名称可以是 bundleid 或 PID。 ``` $ r2 frida://spawn/usb/ # enumerate devices $ r2 frida://spawn/usb// # enumerate apps in the first iOS device $ r2 frida://spawn/usb//Weather # Run the weather app ``` ### 命令 这些是最常用的命令,因此您必须学习它们,并在命令后加上 `?` 以获取子命令的帮助。 ``` :i # get information of the target (pid, name, home, arch, bits, ..) .:i* # import the target process details into local r2 :? # show all the available commands :dm # list maps. Use ':dm|head' and seek to the program base address :iE # list the exports of the current binary (seek) :dt fread # trace the 'fread' function :dt-* # delete all traces ``` ### 插件 r2frida 插件在 agent 端运行,并通过 `r2frida.pluginRegister` API 进行注册。 有关更多示例插件脚本,请参阅 `plugins/` 目录。 ``` [0x00000000]> cat example.js r2frida.pluginRegister('test', function(name) { if (name === 'test') { return function(args) { console.log('Hello Args From r2frida plugin', args); return 'Things Happen'; } } }); [0x00000000]> :. example.js # load the plugin script ``` `:` 命令的工作方式类似于 r2 的 `.` 命令,但它是在 agent 内部运行的。 ``` :. a.js # run script which registers a plugin :. # list plugins :.-test # unload a plugin by name :.. a.js # eternalize script (keeps running after detach) ``` ## Termux 如果您希望通过 Termux 在 Android 上原生安装和使用 r2frida,由于某些符号解析的原因,库依赖项存在一些限制。使其工作的方法是将 `LD_LIBRARY_PATH` 环境变量扩展到指向系统目录,且 *位于* termux libdir 之前。 `$ LD_LIBRARY_PATH=/system/lib64:$LD_LIBRARY_PATH r2 frida://...` ## 故障排除 请确保您使用的是最新版本的 r2(最好是最新发布版或 git 版本)。 运行 `r2 -L | grep frida` 以验证插件是否已加载,如果没有打印任何内容,请使用 `R2_DEBUG=1` 环境变量获取调试信息以找出原因。 如果您在编译 r2frida 时遇到问题,可以使用 `r2env` 或从 GitHub releases 页面获取发布构建版本,请注意只有 MAJOR.MINOR 版本必须匹配,即 r2-5.7.6 可以加载任何在 5.7.0 到 5.7.8 之间版本编译的插件。 ## 设计 ``` +---------+ | radare2 | The radare2 tool, on top of the rest +---------+ : +----------+ | io_frida | r2frida io plugin +----------+ : +---------+ | frida | Frida host APIs and logic to interact with target +---------+ : +-------+ | app | Target process instrumented by Frida with Javascript +-------+ ``` ## 致谢 本插件由 pancake 又名 Sergi Alvarez(radare2 的作者)为 NowSecure 开发。 我要感谢 Ole André 编写和维护 Frida, 并如此友善地主动修复错误并讨论有关 使此结合得以工作的任何技术细节。致敬
标签:Aarch64, Android逆向, ARM, CMS安全, CTF工具, DAST, Docker支持, Frida, Hook技术, iOS逆向, JavaScript, MITM代理, r2frida, Radare2, TLS指纹, TypeScript, 二进制分析, 云安全运维, 云资产清单, 内存操纵, 动态二进制分析, 安全插件, 恶意软件分析, 情报收集, 数据可视化, 漏洞搜索, 漏洞研究, 目录枚举, 移动安全, 自动化攻击, 自动化攻击, 逆向工程, 预握手, 高性能