0. Frida官方資料學習
官方網站:https://frida.re/docs/home/
1. 安裝firda-server到Android並啟動
https://github.com/frida/frida/releases
這里手機是Pixel2(arm64)所以安裝:frida-server-12.9.4-android-arm64.xz
啟動的時候Pixel2(Android 9)有坑是命名行沒法啟動,提示沒有權限(雖然已Root):
Unable to load SELinux policy from the kernel: Failed to open file ?/sys/fs/selinux/policy?: Permission denie
此時可以采用的啟動辦法是:
adb shell $ su # /data/local/tmp/frida-server &
2. 安裝frida-tools
這里在Windows7_X64上安裝frida-tools,經歷非常的坎坷,要注意安裝上述對應版本(12.9.4)的frida-tools要注意以下幾點:
(1)使用的frida注意一定要是跟Android上使用的frida-server版本一致。
(2)最新版的frida(12.9.4)要使用Python3.8,注意還不能是3.7這種。。
(3)直接用pip3 install frida-tools不知道為什么就會一直卡在(但是在MacOSX上安裝卻沒有這個問題,很快就能裝好,可能是Windows平台特有問題):Running setup.py install for frida ... –
(4)就算更換國內pip源一樣的會卡住,這個時候可以手動先把frida安裝一下再pip3 install frida-tools,方法如下:
https://pypi.org/project/frida/#files (1)手動下載frida包: https://files.pythonhosted.org/packages/28/45/47fed8715620ca607e3a3802aab4165714e3fd95c1e8eb35c0c432cf83b0/frida-12.9.4-py2.7-win-amd64.egg (2)放置到本地: C:\Users\liuheng.klh\AppData\Local\Programs\Python\Python38\Lib\site-packages\frida-12.9.4-py3.8-win-amd64.egg (3)非常關鍵的一步,要用easy_install去安裝一下egg文件(網友不知道這個方法走了彎路): C:\Users\liuheng.klh\AppData\Local\Programs\Python\Python38\Scripts>easy_install.exe C:\Users\liuheng.klh\AppData\Local\Programs\Python\Python38\Lib\site-packages\frida-12.9.4-py3.8-win-amd64.egg (4)最后用pip3執行就可以了: pip3 install frida-tools
3. 簡單示例
如果擔心frida-server工作不正常拿不到進程信息,可以重新啟動一下frida-server進程,在客戶端可以測試一下效果:
C:\Users\liuheng.klh>frida-ps -U PID Name ----- --------------------------------------------------- 6466 ATFWD-daemon 794 adbd 819 adsprpcd 499 android.hardware.atrace@1.0-service 661 android.hardware.audio@2.0-service 838 android.hardware.biometrics.fingerprint@2.1-service 662 android.hardware.bluetooth@1.0-service-qti 500 android.hardware.boot@1.0-service 663 android.hardware.camera.provider@2.4-service 。。。 。。。
抓一下進程的某個方法調用情況,非常輕松就能看到函數的調用時間戳:
C:\Users\liuheng.klh>frida-trace -U -i eglSwapBuffers com.auto***.***auto Instrumenting functions... eglSwapBuffers: Loaded handler at "C:\\Users\\liuheng.klh\\__handlers__\\libOpenMAXAL.so\\eglSwapBuffers.js" eglSwapBuffers: Loaded handler at "C:\\Users\\liuheng.klh\\__handlers__\\libEGL_adreno.so\\eglSwapBuffers.js" Started tracing 2 functions. Press Ctrl+C to stop. /* TID 0x2cb2 */ 297 ms eglSwapBuffers() 298 ms | eglSwapBuffers() 327 ms eglSwapBuffers() 327 ms | eglSwapBuffers() 720 ms eglSwapBuffers() 720 ms | eglSwapBuffers() 1141 ms eglSwapBuffers() 1142 ms | eglSwapBuffers() 1333 ms eglSwapBuffers() 1333 ms | eglSwapBuffers() 1560 ms eglSwapBuffers() 1561 ms | eglSwapBuffers() 1977 ms eglSwapBuffers() 1977 ms | eglSwapBuffers() 2330 ms eglSwapBuffers()
4. 查找C++函數Hook目標
Android符號庫中是包含所有符號的,用如下nm命令可以拿到:
nm -D libXXX.so | grep ***
其實frida-trace可以支持通配符的,不需要填寫完整的符號名。