為什麼不用IDA,因為貴。 為什麼不用gdb,因為lldb的出現,取代gdb只是遲早的事情,可以說gdb是Depracated。
在 Android逆向之ARM64靜態分析對app的中的so進行了靜態分析,這篇文章介紹兩種動態調試的方式,一種是radare2,另一種是lldb。
r2frida
概術
Radare2 and Frida better together. 兩個強大的工具放在一起,必然會產生更為強大的能量,可以稱為"Best Dynamic Debugging Tool ",最主要是免費。其本質是Radare2的插件。
安裝
唯一的一個缺點,安裝過程堪稱災難。我用
r2pm -ci r2frida
進行的安裝。目前只能在Linux下使用。筆者使用Nodejs最新的穩定版本才安裝成功。
缺少庫文件的問題,解決辦法如下,這裡只是舉例,具體情況可能不一樣,筆者是ssl庫連結不了。
/usr/bin/ld: 找不到 -ldhnetsdk
1)找到本地的libGL.so 文件路徑 ,在終端執行:
locate libdhnetsdk.so
命令: /usr/local/ahuasdk/libdhnetsdk.so 2)建立連結: sudo ln -s /usr/local/ahuasdk/libdhnetsdk.so /usr/lib/libdhnetsdk.so
介紹
選擇淘寶來介紹。
Attach process
r2 frida://BH9500C2JR/com.taobao.taobao
其中BH9500C2JR通過
frida-ls-devices
獲取。
Spawn process
r2 frida://spawn/usb/BH9500C2JR/com.taobao.taobao
這種情況下是以suspend模式啟動app,因此屏幕會卡住。這樣就可以hook程序啟動的時候或之前的操作,比如onCreate。通過
=!dc
可恢復。
命令
所有r2frida的命令都必須以
\或者=!
開頭 。
版本命令
獲取Frida版本的命令
\?V
獲取信息的命令
\i: Shows target information\ii* : List imports in r2 form.\il: List libraries. Commonly used with the symbol ~, which is the internal grep of r2.\iE : List exports of library, filtering by library name.iEa () : Show address of export symbol.\isa[*] () : Show address of symbol\ic: List classes
部分結果如下:
搜索命令
\/ keyword
:Searchhex/stringpatterninmemoryranges(seesearch.in=?)以JSON格式顯示,搜索關鍵字rooted,命令為:
\/j rooted
動態調試
這是r2frida最強大的功能。
\dt (<addr>|<sym>) ...
: Trace list of addresses or symbols. Similar to frida-trace
\dmas
: Allocate a string inited with on the heap
\dmal
:Listliveheapallocationscreatedwithdma[s]
通過px還看不出來什麼,通過下圖就唔唔溝看出這是UTF-8編碼。
dt命令的簡單使用:
其他命令
dpt: List threads
dr: List thread registers
e[?] [a[=b]]
: List/get/set config evaluable vars
env: Get/set environment variable
腳本
JS code to be run in the target can be loaded with
\. script.js.
A common practice is always to call this script agent.js to remember that's the code to be run inside the target.
[0x00000000]> \. agent.js
[0x00000000]> \dc
resumed spawned process.
調試libnative-lib.so
通過smali代碼可知libnative-lib.so文件是在中被加載的,在onCreate方法中被調用的。
因此在hookonCreate方法來下斷點。
參考
https://www.qqxiuzi.cn/bianma/Unicode-UTF.php https://frida.re/docs/home/ https://github.com/enovella/r2frida-wiki
寫在最後
r2frida在so調試方面基本可以替代IDA的,至於Smali的調試會在後面的文章中涉及。lldb這個利器本來是IOS上面的,用來取代gdb的,目前Google在Android中也大力推廣,取代gdb也只是時間問題。
更多內容,歡迎關注我的微信公眾號:無情劍客。