SlideShare a Scribd company logo
radare2
//rooted
     pancake
  pancake@nopcode.org

      nibble
  nibble.ds@gmail.com
Overview
radare2 is a rewrite of radare (r1) focusing on:
 - API (refactor, clean)
 - Por tability (osx,linux,bsd,w32)
 - Modularity (˜40 modules)
 - Scripting and bindings (valaswig)
Status of 0.4
 - Aiming to be as compatible as possible with r1
 - Some command and concepts has been redefined
 - Runtime >10x faster
 - Smar t and cleaner code (40% of LOCs)
 - Refactoring never ends -:)
radare2 // 0.4 release

Download sources:
 http://www.radare.org/get/radare2-0.4.tar.gz
Debian packages:
 http://www.radare.org/get/r2deb
Chiptune session: (Thanks neuroflip!)
 http://www.radare.org/get/r2-0.4.mp3

6 months from 0.3 and ˜300 commits
Language bindings
* C is fun, but people love to loose CPU cycles..
  - Automatic bindings generated by valaswig
  - Vala and Genie by default
  - Python, Perl, Lua and Ruby (more will come)
  - Access to full internal API
  - Binded code can use native instances and viceversa
  - Transparent access to generics, collections, iterators,
    classes, enums, structures, arrays, basic types..
* Valaswig is a .vapi to .i translator
   $ hg clone http://hg.youterm.com/valaswig
   $ wget http://radare.org/get/valaswig-0.1.tar.gz
Scripting demo

$ python
>>> import libr
>>> core = libr.RCore()
>>> core.loadlibs()
>>> file = core.file_open("dbg:///bin/ls", False)
>>> core.dbg.use("native")
>>> core.cmd0("dp=%d"%file.fd)

$ lua
> require "r_bin"
> file = arg[1] or "/bin/ls"
> b = r_bin.RBin ()
> b:load (file, "")
> baddr = b:get_baddr ()
> s = b:get_sections ()
> for i=0,s:size()-1 do
>   print (string.format (’0x%08x va=0x%08x size=%05i %s’,
      s[i].offset, baddr+s[i].rva, s[i].size, s[i].name))
> end
Scripting demo (2)

$ ruby <<EOF
require ’libr’
core = Libr::RCore.new
core.file_open("/bin/ls", 0);
print core.cmd_str("pd 20");
EOF

$ perl <<EOF
require "r2/r_asm.pm";
sub disasm {
  my ($a, $arch, $op) = @_;
  $a->use ($arch);
  my $code = $a->massemble ($op);
  if (defined($code)) {
    my $buf = r_asmc::RAsmCode_buf_hex_get ($code);
    print "$op | $arch | $bufn";
  }
}
my $a = new r_asm::RAsm();
disasm ($a, ’x86.olly’, ’mov eax, 33’);
disasm ($a, ’java’, ’bipush 33’);
EOF
r2w
Aims to be a web frontend for radare2
 - Written in python (no dependencies)
 - jQuer y and CSS hardly simplifies the design of the gui
 - At the moment it is just a PoC
 - Assembler/disassembler, debugger, hasher demos
 $ python main.py
 Process with PID 20951 started...
 URL=http://127.0.0.1:8080/
 ROOT=/home/pancake/prg/r2w/www

$ surf http://127.0.0.1:8080
 ...


                      (demo)
Searching bytes
* One of the very basic features of r1 has been rewritten
  in order to offer a clean API to search keywords with
  binar y masks, patterns, regular expressions and strings.

 /* Genie example search patterns */
 uses
      Radare.RSearch
 init
     var s = new RSearch (Mode.KEYWORD)
     s.kw_add ("lib", "")
     s.begin ()
     var str = "foo is pure lib"
     s.update_i (0, str, str.len ())
Debugging
* Several APIs affected: (debug, reg, bp, io)
  - No os/arch specific stuff
  - Same code works on w32, OSX, BSD and GNU/Linux
  - Basics on x86-32/64, PowerPC, MIPS and ARM
  - Not all functionalities of r1 implemented (work in progress)
  - Debugger is no longer an IO backend
  - Program transplant between different backends
  - Some basics on backtrace, process childs and threads
  - Memor y management (user/system memory maps)
  - Only software breakpoints atm
  - Traptracing, and software stepping implemented
Demo
Sample debugging session
 $ r2 -V
 radare2 0.4 @ linux-lil-x86

 $ r2 -d ls
 [0x080498a0]> ds   # step one instruction
 [0x080498a0]> dsl # step source line
 [0x080498a0]> dr= # display registers
  eip 0xb7883812   oeax 0xffffffff    eax 0xbfd89800
  ecx 0x00000000    edx 0x00000000    esp 0xbfd89800
  esi 0x00000000    edi 0x00000000 eflags 0x00000292
 [0x080498a0]> dcu sym.main # continue until sym.main
 [0x080498a0]> dpt # display process threads
  6064 s (current)
  6064 s thread_0
 [0x080498a0]> dbt # display backtrace

NOTE: Debugger commands no longer relay on IO backend ’!’
r2rc the relocatable code compiler
* Simple and minimal compiler for x86 32/64
  - arm and powerpc suppor t will follow
  - C-like syntax, with low-level hints
  - Allows to generate assembly code ready to be injected
  - Used as interface for native and crossplatform injection
* Accessible thru shell and API
 # r_sys_cmd_str -> r_asm_massemble -> r_debug_inject
 $ r2rc main.r > main.asm
 $ rasm2 -f main.asm > main.hex
 $ r2 -d ls
 [0x08048594]> wF main.hex @ eip # write hexpairs
 [0x08048594]> dc                 # continue execution
r2rc code example

main@global(128) {
        .var80 = "argc = %dn";                         # arguments
        printf (.var80, .arg0);
        .var80 = "0x%08x : argv[%02d] = %sn";
        .var0 = 0;
        .var4 = *.arg1;
        while (.var0 <= .arg0) {
                printf (.var80, .var4, .var0, .var4);
                .var0 += 1;                             # increment counter
                .arg1 += 4;                             # increment pointer
                .var4 = *.arg1;                         # get next argument
        }
        .var80 = "0x%08x : envp[%02d] = %sn";          # environ
        .var0 = 0;
        .var4 = *.arg2;
        { printf (.var80, .var4, .var0, .var4);
                .var0 += 1;                             # increment counter
                .arg2 += 4;                             # increment pointer
                .var4 = *.arg2;                         # get next environ
        } while (.var4);
        0;
}
RAnal
* Data and code analysis
* Analyzed data is accessible from opcode level to
  function level (opcode, BB, functions, vars, xrefs...)
* Combine data is very quickly
  Eg.: Filter bb by function, graph bb hierarchy,
  analyze references...
* Graph output in graphviz format (dot)
Demo
* Code & Data analysis
* Graph generation
  - Full
  - Par tial
* Source code graph
RAnal
RBin
* Header analysis
* Suppor ts:
  ELF32, ELF64, PE32, PE32+, MACH-O,
  MACH-O64, CLASS...
* Format-Agnostic API
* All sub-libs have been written from scratch
* All sub-libs offer a complete API for working
  with specific formats
* Keeps reversing (and minimalism) in mind
RBin
* Read support
  - Impor ts
  - Symbols (Exports)
  - Sections
  - Linked libraries
  - Strings
  - Binar y info
    object type
    endianness
    debug data/stripped
    static/dynamic...
RBin
* Write support (*)
  - Add/Remove/Resize {sections, impor ts, symbols}
  - Edit header fields
* Metadata support (*)
(*) = Work in progress
Demo
* Format-agnostic API
 $ python imports.py ls
 $ python imports.py user32.dll
 $ python imports.py osx-ls.1

$ cat imports.py
#!/usr/bin/python
from libr import *
import sys
if (len (sys.argv) == 2):
        file = sys.argv[1]
else:
        file = "/bin/ls"
        b = RBin ()
        b.load(file, None)
        baddr= b.get_baddr()
        print ’-> Imports’
        for i in b.get_imports ():
                 print ’offset=0x%08x va=0x%08x %s’ % (
                           i.offset, baddr+i.rva, i.name)
RAsm
* (Dis)Assembly library
* Suppor ts x86, x86-64, PPC, MIPS, ARM,
  SPARC, m68k, psosvm...
* Uses:
  - (Dis)Assembly backed
  - Compile inline code in order to be injected
  - Assembly backend of rcc
* All parameters (arch, wordsize...) can be modified
  in runtine, so generic injection are easy to implement
Demo
* Interactive disassembler
 $ ./widget-asm
Demo
* XorPacker
  - ELF structure
Demo (XorPacker)

$ rabin2 -S test |   cut -d ’ ’ -f 2,6-7
[...]
address=0x08048340   privileges=-r-x name=.text
address=0x080484fc   privileges=-r-x name=.fini
address=0x08048518   privileges=-r-- name=.rodata
[...]
Demo (XorPacker)
- Xor from .text to .rodata
- Execution flow
  Entr ypoint -> Init -> main
- Analyze entrypoint
  Get init address
- Overwrite init with the packer payload
  Change page permissions with mprotect
  Xor from .text to .data (take care of payload code)
Demo (XorPacker)

$ rabin2 -z test | grep "section=.rodata"
  | cut -d ’ ’ -f 1,5-6
address=0x08048520 section=.rodata string=passw0rd
address=0x08048529 section=.rodata string=ROOTED!
address=0x08048531 section=.rodata string=Ooops
$ rabin2 -z a.out | grep "section=.rodata"
  | cut -d ’ ’ -f 1,5-6
address=0x08048518 section=.rodata string=jiiihiki
address=0x08048528 section=.rodata string=i;&&=,-Hi&
$ ./a.out foo
Ooops
$ ./a.out passw0rd
ROOTED!
Demo
* ITrace
Demo (ITrace)
- Edit all plt entries but hijacked impor t
- Analyze entrypoin
  Get init address
- Write Hook code into init
  Push interesting parameters
  Call hijacked impor t
  Fix stack
  jump to the first PLT entry
- LD_PRELOAD library containing hijacked impor t
Demo (ITrace)

$ LD_PRELOAD=./preload.so ./a.out
Fake sleep call from import 0x8 @ 0x804830c
Fake sleep call from import 0x18 @ 0x804832c
ROOTED!
Fake sleep call from import 0x18 @ 0x804832c
ROOTED!
Fake sleep call from import 0x18 @ 0x804832c
ROOTED!
ˆC
So...
EOF
• Ideas, questions?




                      Thanks for listening!

More Related Content

PDF
Ruby 2.0
ODP
PHP applications/environments monitoring: APM & Pinba
PPTX
Python
PDF
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
PDF
PHP Internals and Virtual Machine
PPTX
PPTX
ODP
Runtime Symbol Resolution
Ruby 2.0
PHP applications/environments monitoring: APM & Pinba
Python
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
PHP Internals and Virtual Machine
Runtime Symbol Resolution

What's hot (20)

PPT
Esprima - What is that
ODP
Perl one-liners
PPTX
AST - the only true tool for building JavaScript
PDF
AST Rewriting Using recast and esprima
KEY
Yapcasia2011 - Hello Embed Perl
PPTX
Perl basics for Pentesters
PDF
Klee and angr
PDF
Php engine
ODP
PHP5.5 is Here
PDF
PHP7 is coming
PDF
Interceptors: Into the Core of Pedestal
PDF
Rust LDN 24 7 19 Oxidising the Command Line
PDF
ROP 輕鬆談
ODP
PHP Tips for certification - OdW13
PDF
High Performance tDiary
PDF
$kernel->infect(): Creating a cryptovirus for Symfony2 apps
PDF
Quick tour of PHP from inside
PDF
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
KEY
dotCloud and go
PPTX
Perl basics for pentesters part 2
Esprima - What is that
Perl one-liners
AST - the only true tool for building JavaScript
AST Rewriting Using recast and esprima
Yapcasia2011 - Hello Embed Perl
Perl basics for Pentesters
Klee and angr
Php engine
PHP5.5 is Here
PHP7 is coming
Interceptors: Into the Core of Pedestal
Rust LDN 24 7 19 Oxidising the Command Line
ROP 輕鬆談
PHP Tips for certification - OdW13
High Performance tDiary
$kernel->infect(): Creating a cryptovirus for Symfony2 apps
Quick tour of PHP from inside
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
dotCloud and go
Perl basics for pentesters part 2
Ad

Similar to Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010] (20)

PDF
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...
PDF
Getting Started with Raspberry Pi - DCC 2013.1
PDF
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
PPTX
Linux Initialization Process (1)
KEY
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
PDF
Hadoop meetup : HUGFR Construire le cluster le plus rapide pour l'analyse des...
PPTX
C from hello world to 010101
PDF
Specialized Compiler for Hash Cracking
PDF
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
PPT
Introduction to Assembly Language
PDF
Design Summit - Rails 4 Migration - Aaron Patterson
PDF
Exploring the x64
PPTX
Debug generic process
PDF
[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkR
PPTX
C programming language tutorial
PDF
Xdp and ebpf_maps
PDF
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
PPTX
Go Native : Squeeze the juice out of your 64-bit processor using C++
PDF
How to use Parquet as a basis for ETL and analytics
PDF
Spark Streaming Programming Techniques You Should Know with Gerard Maas
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...
Getting Started with Raspberry Pi - DCC 2013.1
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
Linux Initialization Process (1)
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Hadoop meetup : HUGFR Construire le cluster le plus rapide pour l'analyse des...
C from hello world to 010101
Specialized Compiler for Hash Cracking
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
Introduction to Assembly Language
Design Summit - Rails 4 Migration - Aaron Patterson
Exploring the x64
Debug generic process
[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkR
C programming language tutorial
Xdp and ebpf_maps
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
Go Native : Squeeze the juice out of your 64-bit processor using C++
How to use Parquet as a basis for ETL and analytics
Spark Streaming Programming Techniques You Should Know with Gerard Maas
Ad

More from RootedCON (20)

PDF
Rooted2020 A clockwork pentester - Jose Carlos Moral & Alvaro Villaverde
PDF
rooted2020 Sandbox fingerprinting -_evadiendo_entornos_de_analisis_-_victor_c...
PDF
Rooted2020 hunting malware-using_process_behavior-roberto_amado
PPSX
Rooted2020 compliance as-code_-_guillermo_obispo_-_jose_mariaperez_-_
PDF
Rooted2020 the day i_ruled_the_world_deceiving_software_developers_through_op...
PPTX
Rooted2020 si la-empresa_ha_ocultado_el_ciberataque,_como_se_ha_enterado_el_r...
PPTX
Rooted2020 wordpress-another_terror_story_-_manuel_garcia_-_jacinto_sergio_ca...
PPTX
Rooted2020 Atacando comunicaciones-de_voz_cifradas_-_jose_luis_verdeguer
PDF
rooted2020-Rootkit necurs no_es_un_bug,_es_una_feature_-_roberto_santos_-_jav...
PDF
Rooted2020 stefano maccaglia--_the_enemy_of_my_enemy
PPTX
Rooted2020 taller de-reversing_de_binarios_escritos_en_golang_-_mariano_palom...
PPTX
Rooted2020 virtual pwned-network_-_manel_molina
PDF
Rooted2020 van a-mear_sangre_como_hacer_que_los_malos_lo_paguen_muy_caro_-_an...
PDF
Rooted2020 todo a-siem_-_marta_lopez
PPTX
Rooted2020 roapt evil-mass_storage_-_tu-ya_aqui_-_david_reguera_-_abel_valero
PDF
Rooted2020 live coding--_jesus_jara
PDF
Rooted2020 legalidad de-la_prueba_tecnologica_indiciaria_cuando_tu_papi_es_un...
PDF
Rooted2020 hackeando el-mundo_exterior_a_traves_de_bluetooth_low-energy_ble_-...
PDF
Rooted2020 evading deep-learning_malware_detectors_-_javier_yuste
PDF
Rooted2020 encontrando 0days-en_2020_-_antonio_morales
Rooted2020 A clockwork pentester - Jose Carlos Moral & Alvaro Villaverde
rooted2020 Sandbox fingerprinting -_evadiendo_entornos_de_analisis_-_victor_c...
Rooted2020 hunting malware-using_process_behavior-roberto_amado
Rooted2020 compliance as-code_-_guillermo_obispo_-_jose_mariaperez_-_
Rooted2020 the day i_ruled_the_world_deceiving_software_developers_through_op...
Rooted2020 si la-empresa_ha_ocultado_el_ciberataque,_como_se_ha_enterado_el_r...
Rooted2020 wordpress-another_terror_story_-_manuel_garcia_-_jacinto_sergio_ca...
Rooted2020 Atacando comunicaciones-de_voz_cifradas_-_jose_luis_verdeguer
rooted2020-Rootkit necurs no_es_un_bug,_es_una_feature_-_roberto_santos_-_jav...
Rooted2020 stefano maccaglia--_the_enemy_of_my_enemy
Rooted2020 taller de-reversing_de_binarios_escritos_en_golang_-_mariano_palom...
Rooted2020 virtual pwned-network_-_manel_molina
Rooted2020 van a-mear_sangre_como_hacer_que_los_malos_lo_paguen_muy_caro_-_an...
Rooted2020 todo a-siem_-_marta_lopez
Rooted2020 roapt evil-mass_storage_-_tu-ya_aqui_-_david_reguera_-_abel_valero
Rooted2020 live coding--_jesus_jara
Rooted2020 legalidad de-la_prueba_tecnologica_indiciaria_cuando_tu_papi_es_un...
Rooted2020 hackeando el-mundo_exterior_a_traves_de_bluetooth_low-energy_ble_-...
Rooted2020 evading deep-learning_malware_detectors_-_javier_yuste
Rooted2020 encontrando 0days-en_2020_-_antonio_morales

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
KodekX | Application Modernization Development
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
MYSQL Presentation for SQL database connectivity
20250228 LYD VKU AI Blended-Learning.pptx
Electronic commerce courselecture one. Pdf
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
Diabetes mellitus diagnosis method based random forest with bat algorithm
“AI and Expert System Decision Support & Business Intelligence Systems”
NewMind AI Weekly Chronicles - August'25 Week I
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
GamePlan Trading System Review: Professional Trader's Honest Take
KodekX | Application Modernization Development
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Review of recent advances in non-invasive hemoglobin estimation
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
madgavkar20181017ppt McKinsey Presentation.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf

Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]

  • 2. Overview radare2 is a rewrite of radare (r1) focusing on: - API (refactor, clean) - Por tability (osx,linux,bsd,w32) - Modularity (˜40 modules) - Scripting and bindings (valaswig) Status of 0.4 - Aiming to be as compatible as possible with r1 - Some command and concepts has been redefined - Runtime >10x faster - Smar t and cleaner code (40% of LOCs) - Refactoring never ends -:)
  • 3. radare2 // 0.4 release Download sources: http://www.radare.org/get/radare2-0.4.tar.gz Debian packages: http://www.radare.org/get/r2deb Chiptune session: (Thanks neuroflip!) http://www.radare.org/get/r2-0.4.mp3 6 months from 0.3 and ˜300 commits
  • 4. Language bindings * C is fun, but people love to loose CPU cycles.. - Automatic bindings generated by valaswig - Vala and Genie by default - Python, Perl, Lua and Ruby (more will come) - Access to full internal API - Binded code can use native instances and viceversa - Transparent access to generics, collections, iterators, classes, enums, structures, arrays, basic types.. * Valaswig is a .vapi to .i translator $ hg clone http://hg.youterm.com/valaswig $ wget http://radare.org/get/valaswig-0.1.tar.gz
  • 5. Scripting demo $ python >>> import libr >>> core = libr.RCore() >>> core.loadlibs() >>> file = core.file_open("dbg:///bin/ls", False) >>> core.dbg.use("native") >>> core.cmd0("dp=%d"%file.fd) $ lua > require "r_bin" > file = arg[1] or "/bin/ls" > b = r_bin.RBin () > b:load (file, "") > baddr = b:get_baddr () > s = b:get_sections () > for i=0,s:size()-1 do > print (string.format (’0x%08x va=0x%08x size=%05i %s’, s[i].offset, baddr+s[i].rva, s[i].size, s[i].name)) > end
  • 6. Scripting demo (2) $ ruby <<EOF require ’libr’ core = Libr::RCore.new core.file_open("/bin/ls", 0); print core.cmd_str("pd 20"); EOF $ perl <<EOF require "r2/r_asm.pm"; sub disasm { my ($a, $arch, $op) = @_; $a->use ($arch); my $code = $a->massemble ($op); if (defined($code)) { my $buf = r_asmc::RAsmCode_buf_hex_get ($code); print "$op | $arch | $bufn"; } } my $a = new r_asm::RAsm(); disasm ($a, ’x86.olly’, ’mov eax, 33’); disasm ($a, ’java’, ’bipush 33’); EOF
  • 7. r2w Aims to be a web frontend for radare2 - Written in python (no dependencies) - jQuer y and CSS hardly simplifies the design of the gui - At the moment it is just a PoC - Assembler/disassembler, debugger, hasher demos $ python main.py Process with PID 20951 started... URL=http://127.0.0.1:8080/ ROOT=/home/pancake/prg/r2w/www $ surf http://127.0.0.1:8080 ... (demo)
  • 8. Searching bytes * One of the very basic features of r1 has been rewritten in order to offer a clean API to search keywords with binar y masks, patterns, regular expressions and strings. /* Genie example search patterns */ uses Radare.RSearch init var s = new RSearch (Mode.KEYWORD) s.kw_add ("lib", "") s.begin () var str = "foo is pure lib" s.update_i (0, str, str.len ())
  • 9. Debugging * Several APIs affected: (debug, reg, bp, io) - No os/arch specific stuff - Same code works on w32, OSX, BSD and GNU/Linux - Basics on x86-32/64, PowerPC, MIPS and ARM - Not all functionalities of r1 implemented (work in progress) - Debugger is no longer an IO backend - Program transplant between different backends - Some basics on backtrace, process childs and threads - Memor y management (user/system memory maps) - Only software breakpoints atm - Traptracing, and software stepping implemented
  • 10. Demo Sample debugging session $ r2 -V radare2 0.4 @ linux-lil-x86 $ r2 -d ls [0x080498a0]> ds # step one instruction [0x080498a0]> dsl # step source line [0x080498a0]> dr= # display registers eip 0xb7883812 oeax 0xffffffff eax 0xbfd89800 ecx 0x00000000 edx 0x00000000 esp 0xbfd89800 esi 0x00000000 edi 0x00000000 eflags 0x00000292 [0x080498a0]> dcu sym.main # continue until sym.main [0x080498a0]> dpt # display process threads 6064 s (current) 6064 s thread_0 [0x080498a0]> dbt # display backtrace NOTE: Debugger commands no longer relay on IO backend ’!’
  • 11. r2rc the relocatable code compiler * Simple and minimal compiler for x86 32/64 - arm and powerpc suppor t will follow - C-like syntax, with low-level hints - Allows to generate assembly code ready to be injected - Used as interface for native and crossplatform injection * Accessible thru shell and API # r_sys_cmd_str -> r_asm_massemble -> r_debug_inject $ r2rc main.r > main.asm $ rasm2 -f main.asm > main.hex $ r2 -d ls [0x08048594]> wF main.hex @ eip # write hexpairs [0x08048594]> dc # continue execution
  • 12. r2rc code example main@global(128) { .var80 = "argc = %dn"; # arguments printf (.var80, .arg0); .var80 = "0x%08x : argv[%02d] = %sn"; .var0 = 0; .var4 = *.arg1; while (.var0 <= .arg0) { printf (.var80, .var4, .var0, .var4); .var0 += 1; # increment counter .arg1 += 4; # increment pointer .var4 = *.arg1; # get next argument } .var80 = "0x%08x : envp[%02d] = %sn"; # environ .var0 = 0; .var4 = *.arg2; { printf (.var80, .var4, .var0, .var4); .var0 += 1; # increment counter .arg2 += 4; # increment pointer .var4 = *.arg2; # get next environ } while (.var4); 0; }
  • 13. RAnal * Data and code analysis * Analyzed data is accessible from opcode level to function level (opcode, BB, functions, vars, xrefs...) * Combine data is very quickly Eg.: Filter bb by function, graph bb hierarchy, analyze references... * Graph output in graphviz format (dot)
  • 14. Demo * Code & Data analysis * Graph generation - Full - Par tial * Source code graph
  • 15. RAnal
  • 16. RBin * Header analysis * Suppor ts: ELF32, ELF64, PE32, PE32+, MACH-O, MACH-O64, CLASS... * Format-Agnostic API * All sub-libs have been written from scratch * All sub-libs offer a complete API for working with specific formats * Keeps reversing (and minimalism) in mind
  • 17. RBin * Read support - Impor ts - Symbols (Exports) - Sections - Linked libraries - Strings - Binar y info object type endianness debug data/stripped static/dynamic...
  • 18. RBin * Write support (*) - Add/Remove/Resize {sections, impor ts, symbols} - Edit header fields * Metadata support (*) (*) = Work in progress
  • 19. Demo * Format-agnostic API $ python imports.py ls $ python imports.py user32.dll $ python imports.py osx-ls.1 $ cat imports.py #!/usr/bin/python from libr import * import sys if (len (sys.argv) == 2): file = sys.argv[1] else: file = "/bin/ls" b = RBin () b.load(file, None) baddr= b.get_baddr() print ’-> Imports’ for i in b.get_imports (): print ’offset=0x%08x va=0x%08x %s’ % ( i.offset, baddr+i.rva, i.name)
  • 20. RAsm * (Dis)Assembly library * Suppor ts x86, x86-64, PPC, MIPS, ARM, SPARC, m68k, psosvm... * Uses: - (Dis)Assembly backed - Compile inline code in order to be injected - Assembly backend of rcc * All parameters (arch, wordsize...) can be modified in runtine, so generic injection are easy to implement
  • 22. Demo * XorPacker - ELF structure
  • 23. Demo (XorPacker) $ rabin2 -S test | cut -d ’ ’ -f 2,6-7 [...] address=0x08048340 privileges=-r-x name=.text address=0x080484fc privileges=-r-x name=.fini address=0x08048518 privileges=-r-- name=.rodata [...]
  • 24. Demo (XorPacker) - Xor from .text to .rodata - Execution flow Entr ypoint -> Init -> main - Analyze entrypoint Get init address - Overwrite init with the packer payload Change page permissions with mprotect Xor from .text to .data (take care of payload code)
  • 25. Demo (XorPacker) $ rabin2 -z test | grep "section=.rodata" | cut -d ’ ’ -f 1,5-6 address=0x08048520 section=.rodata string=passw0rd address=0x08048529 section=.rodata string=ROOTED! address=0x08048531 section=.rodata string=Ooops $ rabin2 -z a.out | grep "section=.rodata" | cut -d ’ ’ -f 1,5-6 address=0x08048518 section=.rodata string=jiiihiki address=0x08048528 section=.rodata string=i;&&=,-Hi& $ ./a.out foo Ooops $ ./a.out passw0rd ROOTED!
  • 27. Demo (ITrace) - Edit all plt entries but hijacked impor t - Analyze entrypoin Get init address - Write Hook code into init Push interesting parameters Call hijacked impor t Fix stack jump to the first PLT entry - LD_PRELOAD library containing hijacked impor t
  • 28. Demo (ITrace) $ LD_PRELOAD=./preload.so ./a.out Fake sleep call from import 0x8 @ 0x804830c Fake sleep call from import 0x18 @ 0x804832c ROOTED! Fake sleep call from import 0x18 @ 0x804832c ROOTED! Fake sleep call from import 0x18 @ 0x804832c ROOTED! ˆC
  • 29. So...
  • 30. EOF • Ideas, questions? Thanks for listening!