The Framework

The Radare2 project is a set of small command-line utilities that can be used together or independently.

This chapter will give you a quick understanding of them, but you can check the dedicated sections for each tool at the end of this book.

radare2

The main tool of the whole framework. It uses the core of the hexadecimal editor and debugger. radare2 allows you to open a number of input/output sources as if they were simple, plain files, including disks, network connections, kernel drivers, processes under debugging, and so on.

It implements an advanced command line interface for moving around a file, analyzing data, disassembling, binary patching, data comparison, searching, replacing, and visualizing. It can be scripted with a variety of languages, including Python, Ruby, JavaScript, Lua, and Perl.

rabin2

A program to extract information from executable binaries, such as ELF, PE, Java CLASS, Mach-O, plus any format supported by r2 plugins. rabin2 is used by the core to get data like exported symbols, imports, file information, cross references (xrefs), library dependencies, and sections.

rasm2

A command line assembler and disassembler for multiple architectures (including Intel x86 and x86-64, MIPS, ARM, PowerPC, Java, and myriad of others).

Examples

  1. $ rasm2 -a java 'nop'
  2. 00
  1. $ rasm2 -a x86 -d '90'
  2. nop
  1. $ rasm2 -a x86 -b 32 'mov eax, 33'
  2. b821000000
  1. $ echo 'push eax;nop;nop' | rasm2 -f -
  2. 509090

rahash2

An implementation of a block-based hash tool. From small text strings to large disks, rahash2 supports multiple algorithms, including MD4, MD5, CRC16, CRC32, SHA1, SHA256, and others. rahash2 can be used to check the integrity or track changes of big files, memory dumps, or disks.

Examples

  1. $ rahash2 file
  2. file: 0x00000000-0x00000007 sha256: 887cfbd0d44aaff69f7bdbedebd282ec96191cce9d7fa7336298a18efc3c7a5a
  1. $ rahash2 -a md5 file
  2. file: 0x00000000-0x00000007 md5: d1833805515fc34b46c2b9de553f599d

radiff2

A binary diffing utility that implements multiple algorithms. It supports byte-level or delta diffing for binary files, and code-analysis diffing to find changes in basic code blocks obtained from the radare code analysis.

rafind2

A program to find byte patterns in files.

ragg2

A frontend for r_egg. ragg2 compiles programs written in a simple high-level language into tiny binaries for x86, x86-64, and ARM.

Examples

  1. $ cat hi.r
  2. /* hello world in r_egg */
  3. write@syscall(4); //x64 write@syscall(1);
  4. exit@syscall(1); //x64 exit@syscall(60);
  5. main@global(128) {
  6. .var0 = "hi!\n";
  7. write(1,.var0, 4);
  8. exit(0);
  9. }
  10. $ ragg2 -O -F hi.r
  11. $ ./hi
  12. hi!
  13. $ cat hi.c
  14. main@global(0,6) {
  15. write(1, "Hello0", 6);
  16. exit(0);
  17. }
  18. $ ragg2 hi.c
  19. $ ./hi.c.bin
  20. Hello

rarun2

A launcher for running programs within different environments, with different arguments, permissions, directories, and overridden default file descriptors. rarun2 is useful for:

  • Solving crackmes
  • Fuzzing
  • Test suites

Sample rarun2 script

  1. $ cat foo.rr2
  2. #!/usr/bin/rarun2
  3. program=./pp400
  4. arg0=10
  5. stdin=foo.txt
  6. chdir=/tmp
  7. #chroot=.
  8. ./foo.rr2

Connecting a Program with a Socket

  1. $ nc -l 9999
  2. $ rarun2 program=/bin/ls connect=localhost:9999

Debugging a Program Redirecting the stdio into Another Terminal

1 - open a new terminal and type ‘tty’ to get a terminal name:

  1. $ tty ; clear ; sleep 999999
  2. /dev/ttyS010

2 - Create a new file containing the following rarun2 profile named foo.rr2:

  1. #!/usr/bin/rarun2
  2. program=/bin/ls
  3. stdio=/dev/ttys010

3 - Launch the following radare2 command:

  1. r2 -r foo.rr2 -d /bin/ls

rax2

A minimalistic mathematical expression evaluator for the shell that is useful for making base conversions between floating point values, hexadecimal representations, hexpair strings to ASCII, octal to integer, and more. It also supports endianness settings and can be used as an interactive shell if no arguments are given.

Examples

  1. $ rax2 1337
  2. 0x539
  3. $ rax2 0x400000
  4. 4194304
  5. $ rax2 -b 01111001
  6. y
  7. $ rax2 -S radare2
  8. 72616461726532
  9. $ rax2 -s 617765736f6d65
  10. awesome