
r2frida v6.2.2
Radare2 e Frida meglio insieme.
r2frida
Radare2 e Frida insieme, meglio
Descrizione
Plugin autonomo per radare2 che include frida e consente di strumentare processi locali o remoti utilizzando comandi r2 invece (ma non solo) di script Frida.
Il progetto radare fornisce una toolchain completa per il reverse engineering, è attivamente mantenuto e offre funzionalità ben curate ed estende le proprie capacità con altri linguaggi di programmazione e strumenti.
Frida è un toolkit di strumentazione dinamica che semplifica l'ispezione e la manipolazione dei processi in esecuzione iniettando il proprio JavaScript e, opzionalmente, comunicando anche con i propri script.
Funzionalità
- Eseguire script Frida non modificati (usare il comando
:.) - Eseguire frammenti in C, Javascript o TypeScript in qualsiasi processo
- Consente di collegarsi, avviare o lanciare processi in sistemi locali o remoti
- Elencare sezioni, simboli, export, protocolli, classi, metodi
- Cercare valori in memoria all'interno dell'agent o dall'host
- Sostituire implementazioni di metodi o creare hook con comandi brevi
- Caricare librerie e framework nel processo target
- Supporto per le interfacce Dalvik, Java, ObjC, Swift e C
- Manipolare descrittori di file e variabili d'ambiente
- Inviare segnali al processo, continuare, breakpoint
- Il plugin io di r2frida è anche un backend fs e debug per il filesystem
- Automatizzare r2 e frida usando r2pipe
- Leggere/Scrivere la memoria del processo
- Chiamare funzioni, syscall e frammenti di codice grezzo
- Connettersi a frida-server via usb o tcp/ip
- Enumerare app e processi
- Tracciare registri, argomenti delle funzioni
- Testato su x64, arm32 e arm64 per Linux, Windows, macOS, iOS e Android
- Non richiede l'installazione di frida sull'host (non serve frida-tools)
- Estendere i comandi r2frida con plugin che girano nell'agent
- Modificare i permessi delle pagine, applicare patch a codice e dati
- Risolvere simboli per nome o indirizzo e importarli come flag in r2
- Eseguire comandi r2 sull'host dall'agent
- Usare le API di r2 ed eseguire comandi r2 all'interno del processo target remoto
- Breakpoint nativi usando l'API
:db - Accedere a filesystem remoti usando l'API
r_fs
Installazione
Il modo consigliato per installare r2frida è tramite r2pm:
$ r2pm -ci r2frida
Le build binarie che non richiedono compilazione saranno presto supportate in
r2pm e r2env. Nel frattempo sentitevi liberi di scaricare le ultime build
dalla pagina Releases.
Compilazione
Dipendenze
- radare2
- pkg-config (non richiesto su windows)
- curl o wget
- make, gcc
- npm, nodejs (sarà presto rimosso)
In GNU/Debian sarà necessario installare i seguenti pacchetti:
$ sudo apt install -y make gcc libzip-dev nodejs npm curl pkg-config git
Istruzioni
$ git clone https://github.com/nowsecure/r2frida.git
$ cd r2frida
$ make
$ make user-install
Meson
$ meson setup build -Duser_install=true
$ ninja -C build
$ meson install -C build
Opzioni: -Dfrida_sdk=<dir>, -Dprecompiled_agent=<_agent.js>, -Dr2_plugdir=<dir>, -Dsession_debugger=false.
Windows
- Installa meson e Visual Studio
- Decomprimi l'archivio zip della release più recente di radare2 nella directory radice di r2frida
- Rinominalo in
radare2(anziché radare2-x.y.z) - Per rendere disponibile il compilatore VS nel PATH (
preconfigure.bat) - Esegui
configure.bate poimake.bat
Utilizzo
Per i test, usa r2 frida://0, poiché l'aggancio al pid0 in frida è una sessione
speciale che viene eseguita in locale. Ora puoi eseguire il comando :? per ottenere l'elenco
dei comandi disponibili.
$ 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
Esempi
$ r2 frida://0 # same as frida -p 0, connects to a local session
Puoi collegarti, generare o avviare qualsiasi programma tramite nome o pid. La seguente riga si collegherà al primo processo chiamato rax2 (esegui rax2 - in un altro terminale per testare questa riga)
$ r2 frida://rax2 # attach to the first process named `rax2`
$ r2 frida://1234 # attach to the given pid
Usare il percorso assoluto di un binario per eseguire lo spawn avvierà il processo:
$ r2 frida:///bin/ls
[0x00000000]> :dc # continue the execution of the target program
Funziona anche con argomenti:
$ r2 frida://"/bin/ls -al"
Per il debug USB di app iOS/Android usa queste azioni. Nota che spawn
può essere sostituito con launch o attach, e il nome del processo può essere
il bundleid o il 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
Comandi
Questi sono i comandi più frequenti, quindi devi impararli e aggiungere il suffisso ? per ottenere l'aiuto sui sottocomandi.
: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
Plugin
I plugin di r2frida vengono eseguiti sul lato agent e sono registrati tramite l'API r2frida.pluginRegister.
Consulta la directory plugins/ per ulteriori esempi di script di plugin.
[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