Выбрать главу

218 0x00079b00 0x00079b00 GLOBAL FUNC 15 LZ4_createStreamDecode

With rabin2, the generated symbols list format is similar to the imports list. Use the -s option to get it:

rabin2 -s /bin/ls | head

[Symbols]

nth paddr vaddr bind type size lib name

――――――――――――――――――――――――――――――――――――――――――――――――――――――

110 0x000150a0 0x000150a0 GLOBAL FUNC 56 _obstack_allocated_p

111 0x0001f600 0x0021f600 GLOBAL OBJ 8 program_name

112 0x0001f620 0x0021f620 GLOBAL OBJ 8 stderr

113 0x00014f90 0x00014f90 GLOBAL FUNC 21 _obstack_begin_1

114 0x0001f600 0x0021f600 WEAK OBJ 8 program_invocation_name

115 0x0001f5c0 0x0021f5c0 GLOBAL OBJ 8 alloc_failed_handler

116 0x0001f5f8 0x0021f5f8 GLOBAL OBJ 8 optarg

117 0x0001f5e8 0x0021f5e8 GLOBAL OBJ 8 stdout

118 0x0001f5e0 0x0021f5e0 GLOBAL OBJ 8 program_short_name

With the -sr option rabin2 produces a radare2 script instead. It can later be passed to the core to automatically flag all symbols and to define corresponding byte ranges as functions and data blocks.

$ rabin2 -sr /bin/ls | head

fs symbols

f sym.obstack_allocated_p 56 0x000150a0

f sym.program_invocation_name 8 0x0021f600

f sym.stderr 8 0x0021f620

f sym.obstack_begin_1 21 0x00014f90

f sym.program_invocation_name 8 0x0021f600

f sym.obstack_alloc_failed_handler 8 0x0021f5c0

f sym.optarg 8 0x0021f5f8

f sym.stdout 8 0x0021f5e8

f sym.program_invocation_short_name 8 0x0021f5e0

Rabin2 can list libraries used by a binary with the -l option:

$ rabin2 -l `which r2`

[Linked libraries]

libr_core.so

libr_parse.so

libr_search.so

libr_cons.so

libr_config.so

libr_bin.so

libr_debug.so

libr_anal.so

libr_reg.so

libr_bp.so

libr_io.so

libr_fs.so

libr_asm.so

libr_syscall.so

libr_hash.so

libr_magic.so

libr_flag.so

libr_egg.so

libr_crypto.so

libr_util.so

libpthread.so.0

libc.so.6

22 libraries

Lets check the output with ldd command:

$ ldd `which r2`

linux-vdso.so.1 (0x00007fffba38e000)

libr_core.so => /usr/lib64/libr_core.so (0x00007f94b4678000)

libr_parse.so => /usr/lib64/libr_parse.so (0x00007f94b4425000)

libr_search.so => /usr/lib64/libr_search.so (0x00007f94b421f000)

libr_cons.so => /usr/lib64/libr_cons.so (0x00007f94b4000000)

libr_config.so => /usr/lib64/libr_config.so (0x00007f94b3dfa000)

libr_bin.so => /usr/lib64/libr_bin.so (0x00007f94b3afd000)

libr_debug.so => /usr/lib64/libr_debug.so (0x00007f94b38d2000)

libr_anal.so => /usr/lib64/libr_anal.so (0x00007f94b2fbd000)

libr_reg.so => /usr/lib64/libr_reg.so (0x00007f94b2db4000)

libr_bp.so => /usr/lib64/libr_bp.so (0x00007f94b2baf000)

libr_io.so => /usr/lib64/libr_io.so (0x00007f94b2944000)

libr_fs.so => /usr/lib64/libr_fs.so (0x00007f94b270e000)

libr_asm.so => /usr/lib64/libr_asm.so (0x00007f94b1c69000)

libr_syscall.so => /usr/lib64/libr_syscall.so (0x00007f94b1a63000)

libr_hash.so => /usr/lib64/libr_hash.so (0x00007f94b185a000)

libr_magic.so => /usr/lib64/libr_magic.so (0x00007f94b164d000)

libr_flag.so => /usr/lib64/libr_flag.so (0x00007f94b1446000)

libr_egg.so => /usr/lib64/libr_egg.so (0x00007f94b1236000)

libr_crypto.so => /usr/lib64/libr_crypto.so (0x00007f94b1016000)

libr_util.so => /usr/lib64/libr_util.so (0x00007f94b0d35000)

libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f94b0b15000)

libc.so.6 => /lib64/libc.so.6 (0x00007f94b074d000)

libr_lang.so => /usr/lib64/libr_lang.so (0x00007f94b0546000)

libr_socket.so => /usr/lib64/libr_socket.so (0x00007f94b0339000)

libm.so.6 => /lib64/libm.so.6 (0x00007f94affaf000)

libdl.so.2 => /lib64/libdl.so.2 (0x00007f94afdab000)

/lib64/ld-linux-x86-64.so.2 (0x00007f94b4c79000)

libssl.so.1.0.0 => /usr/lib64/libssl.so.1.0.0 (0x00007f94afb3c000)

libcrypto.so.1.0.0 => /usr/lib64/libcrypto.so.1.0.0 (0x00007f94af702000)

libutil.so.1 => /lib64/libutil.so.1 (0x00007f94af4ff000)

libz.so.1 => /lib64/libz.so.1 (0x00007f94af2e8000)

If you compare the outputs of rabin2 -l and ldd, you will notice that rabin2 lists fewer libraries than ldd. The reason is that rabin2 does not follow and does not show dependencies of libraries. Only direct binary dependencies are shown.

The -z option is used to list readable strings found in the .rodata section of ELF binaries, or the .text section of PE files. Example:

$ rabin2 -z /bin/ls | head

[Strings]

nth paddr vaddr len size section type string

―――――――――――――――――――――――――――――――――――――――――――――――――――――――

000 0x000160f8 0x000160f8 11 12 (.rodata) ascii dev_ino_pop

001 0x00016188 0x00016188 10 11 (.rodata) ascii sort_files

002 0x00016193 0x00016193 6 7 (.rodata) ascii posix-

003 0x0001619a 0x0001619a 4 5 (.rodata) ascii main

004 0x00016250 0x00016250 10 11 (.rodata) ascii ?pcdb-lswd

005 0x00016260 0x00016260 65 66 (.rodata) ascii # Configuration file for dircolors, a utility to help you set the

006 0x000162a2 0x000162a2 72 73 (.rodata) ascii # LS_COLORS environment variable used by GNU ls with the --color option.

007 0x000162eb 0x000162eb 56 57 (.rodata) ascii # Copyright (C) 1996-2018 Free Software Foundation, Inc.

008 0x00016324 0x00016324 70 71 (.rodata) ascii # Copying and distribution of this file, with or without modification,

009 0x0001636b 0x0001636b 76 77 (.rodata) ascii # are permitted provided the copyright notice and this notice are preserved.

With the -zr option, this information is represented as a radare2 commands list. It can be used in a radare2 session to automatically create a flag space called "strings" pre-populated with flags for all strings found by rabin2. Furthermore, this script will mark corresponding byte ranges as strings instead of code.

$ rabin2 -zr /bin/ls | head

fs stringsf str.dev_ino_pop 12 @ 0x000160f8

Cs 12 @ 0x000160f8

f str.sort_files 11 @ 0x00016188

Cs 11 @ 0x00016188

f str.posix 7 @ 0x00016193

Cs 7 @ 0x00016193

f str.main 5 @ 0x0001619a

Cs 5 @ 0x0001619a

f str.pcdb_lswd 11 @ 0x00016250

Cs 11 @ 0x00016250

Rabin2 called with the -S option gives complete information about the sections of an executable. For each section the index, offset, size, alignment, type and permissions, are shown. The next example demonstrates this:

$ rabin2 -S /bin/ls

[Sections]

nth paddr size vaddr vsize perm name

―――――――――――――――――――――――――――――――――――――――――――――――――――――

00 0x00000000 0 0x00000000 0 ----

01 0x00000238 28 0x00000238 28 -r-- .interp

02 0x00000254 32 0x00000254 32 -r-- .note.ABI_tag

03 0x00000278 176 0x00000278 176 -r-- .gnu.hash

04 0x00000328 3000 0x00000328 3000 -r-- .dynsym

05 0x00000ee0 1412 0x00000ee0 1412 -r-- .dynstr

06 0x00001464 250 0x00001464 250 -r-- .gnu.version

07 0x00001560 112 0x00001560 112 -r-- .gnu.version_r