一、前言
如下是如何在mac以及python3.7环境下对frida安装以及frida的基本使用进行简单介绍。至于windows以及linux系统下frida的安装可自行百度,安装方式都大同小异,主要是如何解决安装过程中所遇到的问题。
二、frida安装
1、通过命令进行安装
安装命令:pip install frida-tools
;不过安装过程可能会遇到如下报错:
× Running setup.py install for frida did not run successfully.
│ exit code: 1
╰─> [18 lines of output]
running install
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/command/install.py:37: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
setuptools.SetuptoolsDeprecationWarning,
running build
running build_py
creating build
creating build/lib.macosx-10.9-x86_64-cpython-37
creating build/lib.macosx-10.9-x86_64-cpython-37/frida
copying frida/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-37/frida
copying frida/core.py -> build/lib.macosx-10.9-x86_64-cpython-37/frida
running build_ext
looking for prebuilt extension in home directory, i.e. /Users/xx(本机用户名)/frida-15.1.22-py3.7-macosx-10.9-x86_64.egg
prebuilt extension not found in home directory, will try downloading it
querying pypi for available prebuilds
using default index URL: https://pypi.org/simple/
downloading package list from https://pypi.org/simple/frida/
unable to download it within 20 seconds; please download it manually to /Users/xx(本机用户名)/frida-15.1.22-py3.7-macosx-10.9-x86_64.egg
error: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)>
[end of output]
这么大一坨日志中最关键的就是looking for prebuilt extension in home directory......
,明确告诉我们是因为在路径/Users/xx(本机用户名)/
下没有frida-15.1.22-py3.7-macosx-10.9-x86_64.egg
文件所导致的。
2、解决报错
所以我们只需要去pypi.org/simple/frid… 下载指定文件即可。如下:
上述列表并没有找到python3.7相关的文件,不过本地实际尝试了一下python3.8相关的文件同样适用于python3.7;只需要下载完成将其重命名为frida-15.1.22-py3.7-macosx-10.9-x86_64.egg
即可。
将文件copy到/Users/xx(本机用户名)/
之后,再次执行命令pip install frida-tools
即可安装成功。
3、检测frida是否安装成功
执行命令frida --version
,如果打印了frida版本则说明安装成功。比如15.1.22
三、frida-server安装(已经root设备)
对于未root设备稍显麻烦,需要对apk重打包才行。可参考koz.io/using-frida…
1、cpu架构信息查看
frida-server在不同的cpu架构上实现方式有所不同,因此我们需要根据不同的cpu架构下载指定frida-server才能正常运行。不然可能会出现如下报错syntax error: unexpected '?H?__eh_frame__TEXT'
。
命令adb shell getprop ro.product.cpu.abi
即可查看当前设备cpu架构信息,比如我这台设备的cpu架构信息则是arm64-v8a
2、frida-server下载
github.com/frida/frida… 中可下载与当前安装的frida版本以及Cpu架构相匹配的frida-server相关文件。如下:
3、frida-server执行
将下载成功后的frida-server相关文件进行解压,执行如下几条命令即可运行成功:
- adb push xxxx(解压成功后的文件) /data/local/tmp/fridaServer (将文件push到Android指定目录)
- adb shell
- cd /data/local/tmp (进入指定目录)
- ls -l | grep "fridaServer" (查看是否存在对应文件)
- chmod 777 fridaServer (修改文件的读写权限)
- ./fridaServer (执行frida-server)
上述命令成功之后,新开一个cmd窗口;执行命令
frida-ps -U
,如果出现如下打印则说明frida-server执行成功:
PID Name
----- -----------------------------------------------------
18294 zygote
18293 zygote64
24843 下载管理
3896 天气
24949 小爱同学
......
三、frida简单使用
1、js修改
对于具体的用例可参考github.com/0xdea/frida… ;如下使用事例则是直接修改github.com/0xdea/frida… 文件进行实现。如下仅给出修改后的代码部分:
......
// usage examples
setTimeout(function() { // avoid java.lang.ClassNotFoundException
Java.perform(function() {
//hook类com.example.mydemo.MainActivity中的otherSystem方法
trace("com.example.mydemo.MainActivity.otherSystem");
// trace("com.target.utils.CryptoUtils");
// trace("CryptoUtils");
// trace(/crypto/i);
// trace("exports:*!open*");
});
}, 0);
2、hook
在frida-server运行的情况下执行命令:frida -U --no-pause -f org.hapjs.mockup(需要hook的应用包名) -l js/raptor_frida_android_trace.js(js路径)
,如果出现如下日志则说明注入成功:
/ _ | Frida 15.1.22 - A world-class dynamic instrumentation toolkit
| (_| |
> _ | Commands:
/_/ |_| help -> Displays the help system
. . . . object? -> Display information about 'object'
. . . . exit/quit -> Exit
. . . . More info at https://frida.re/docs/home/
. . . . Connected to Redmi K30 (id=db3d2484)
**Spawned `org.hapjs.mockup`. Resuming main thread!**
[Redmi K30::org.hapjs.mockup ]-> Tracing com.example.mydemo.MainActivity.otherSystem [1 overload(s)]
最后执行方法otherSystem,如果出现如下日志则说明整个流程完全OK:
***** traceMethod entered com.example.mydemo.MainActivity.otherSystem**
//方法参数值打印
arg[0]: 1
arg[1]: 2
traceMethod retval: undefined
***** exiting com.example.mydemo.MainActivity.otherSystem**