背景
最近解决安卓抓包问题的时候,了解到Frida可以解决SSL Pinning的问题,于是对Frida产生了兴趣,看了看文档,感觉很好用,在这里记录下学习笔记。
Frida是什么?
It’s Greasemonkey for native apps, or, put in more technical terms, it’s a dynamic code instrumentation toolkit. It lets you inject snippets of JavaScript or your own library into native apps on Windows, macOS, GNU/Linux, iOS, watchOS, tvOS, Android, FreeBSD, and QNX. Frida also provides you with some simple tools built on top of the Frida API. These can be used as-is, tweaked to your needs, or serve as examples of how to use the API.
Frida是一个动态插桩工具,可以在平台原生APP插入JS代码,动态调试,而且是全平台支持(Linux/MacOS/Windows/Android/iOS)。
更形象地说,Frida好比是Greasemonkey,Greasemonkey可以让你在网页中插入JS,Frida是在二进制环境中插入JS。
Frida相关工具
| 名称 | 安装 | 描述 |
|---|---|---|
| frida-tools | pip3 install frida-tools | Frida CLI,包括frida/frida-ps/frida-trace等 |
| frida-server | https://github.com/frida/frida/releases | 用于远程连接 |
| Frida Python Binding | pip3 install frida | Frida Python库 |
| Frida Node.js Binding | npm install frida | Frida Node.js库 |
Android安装Frida
在安卓上安装Frida,需要有root权限,安装过程如下:
pip3 install frida-tools- 下载frida-server
unxz frida-server.xzadb rootadb push frida-server /data/local/tmp/adb shell "chmod 755 /data/local/tmp/frida-server"adb shell "/data/local/tmp/frida-server &"- 执行
frida-ps -U,如果输出Android上的进程,则安装成功
代码示例
这是官网的Android示例,其中jscode 是注入到目标进程中的JS代码。
|
|
代码的运行过程如下:
- 在安卓下,需要先通过
get_usb_device得到一个DeviceManager实例,代表实际的安卓设备 DeviceManager实例调用attach或者spwan方法得到一个Session实例,代表实际的目标进程Session实例调用create_script方法得到一个Script实例,代表注入到目标进程的脚本Script实例通过on方法接收JS的消息,通过load方法执行JS代码
Frida的[JavaScript API]功能非常强大,最常用的是Java.perform()。
Objection
objectionis a runtime mobile exploration toolkit, powered by Frida, built to help you assess the security posture of your mobile applications, without needing a jailbreak.
既然提到了Frida,那就不得不再说一下objection。Objection是基于Frida的移动平台运行时调试工具,集成了很多好用的功能,用于动态调试。
比如,绕过SSL Pinning,只需要执行:
再比如,为APP设置单独的代理:
总结
在Linux上,有丰富的Debug工具,比如strace 和gdb 等,可以很方便的安装;而在安卓上,安装类似的Debug工具比较麻烦,而Frida和objection把常用的Debug功能集成到一起,非常方便。