
Radare2とFridaは一緒に使うとより優れています。
frida を同梱した radare2 用の自己完結型プラグインで、Fridaスクリプトに限らずr2コマンドを使ってローカルまたはリモートのプロセスをインストルメント(計測・操作)できるようにします。
radareプロジェクトはリバースエンジニアリング向けの完全なツールチェーンを提供しており、活発にメンテナンスされ、よく整備された機能を提供するとともに、他のプログラミング言語やツールと連携して機能を拡張しています。
Fridaは動的インストルメンテーションツールキットで、独自のJavaScriptを注入することで実行中のプロセスを簡単に検査・操作でき、オプションでスクリプトとの通信も可能です。
:. コマンドを使用):db APIを使用したネイティブブレークポイントr_fs APIを使用したリモートファイルシステムへのアクセスr2fridaをインストールする推奨の方法はr2pm経由です:
$ r2pm -ci r2frida
コンパイル不要のバイナリビルドは近日中に
r2pm と r2env でサポートされる予定です。それまでの間、Releases ページから最新のビルドを自由にダウンロードしてください。
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
$ meson setup build -Duser_install=true
$ ninja -C build
$ meson install -C build
オプション: -Dfrida_sdk=<dir>、-Dprecompiled_agent=<_agent.js>、-Dr2_plugdir=<dir>、-Dsession_debugger=false。
radare2 に変更する(radare2-x.y.z ではなく)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 プラグインはエージェント側で実行され、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 の . コマンドと同様に動作しますが、エージェント内で実行されます。
:. a.js # run script which registers a plugin
:. # list plugins
:.-test # unload a plugin by name
:.. a.js # eternalize script (keeps running after detach)
Android上でTermux経由でr2fridaをネイティブにインストールして使用する場合、一部のシンボル解決のためにライブラリ依存関係に関していくつかの注意点があります。これを機能させる方法は、termuxのlibdirの前にシステムディレクトリを指すようにLD_LIBRARY_PATH環境変数を拡張することです。
$ LD_LIBRARY_PATH=/system/lib64:$LD_LIBRARY_PATH r2 frida://...
最新バージョンのr2(できれば最新リリースまたはgit)を使用していることを確認してください。
CIはradare2 6.2.2リリースとgit masterをテストしています。互換性ヘルパーは、古いradare2 ABI上でのWindows絶対パス検出と引用符付きスクリプトファイル名を保持します。
r2 -L | grep fridaを実行してプラグインがロードされているか確認してください。何も出力されない場合は、R2_DEBUG=1環境変数を使用してデバッグメッセージを取得し、原因を特定してください。
r2fridaのコンパイルに問題がある場合は、r2envを使用するか、GitHubのリリースページからリリースビルドを取得できます。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 のために開発されました。
Frida を開発・保守し、この統合を機能させるために必要なあらゆる事柄について積極的にバグを修正し技術的な詳細を議論してくださった Ole André に感謝します。Kudos