如何在 Radare2 中打印地址

逆向工程 雷达2
2021-06-29 08:45:54

我正在从与 peda 混合的 GDB 切换到 Radare2。我喜欢 GDB 的一件事是p命令。例如,p system打印出系统的地址。同样,peda 的searchmem功能对于诸如searchmem SHELL. 在 Radare2 中,我不知道如何实现这一点。我一直在谷歌到高处,但无济于事。有谁知道Radare2有这个能力吗?

2个回答

要打印带有radare2system导出地址,libc您可以使用dmi libc system

首先,您需要打开radare2 并继续执行,直到到达程序的入口点。您必须这样做,因为radare2 在libc 加载之前开始调试 当您到达入口点时,可能会加载该库。

现在使用该 dmi命令并将其传递给 libc 和所需的函数。

$ r2 -d binary_name

[0xf771ab30]> dcu entry0
Continue until 0x080483d0 using 1 bpsize
hit breakpoint at: 80483d0

[0x080483d0]> dmi libc system

这里值得一提的是,在分析(参见a?)之后,radare2 将名称与文件中有趣的偏移量相关联,例如部分、函数、符号、字符串等。这些名称称为“标志”。您可以使用 打印标志及其地址f如需更多帮助,请参阅radare2 书中f?“标志”章节。

要了解如何以不同的方式打印不同的地址和标志,我建议您尝试使用该p?命令并阅读“打印”一章。


可以使用该/命令在radare2 中搜索,包括在内存中搜索您可以使用 获得有关可用搜索命令的更多帮助/?我强烈建议阅读radare2 书中“搜索”一章。例如,在此处查看我的答案


参考

peda源代码

 def searchmem(self, start, end, search, mem=None):
        """
        Search for all instances of a pattern in memory from start to end
        Args:
            - start: start address (Int)
            - end: end address (Int)
            - search: string or python regex pattern (String)
            - mem: cached mem to not re-read for repeated searches (raw bytes)
        Returns:
            - list of found result: (address(Int), hex encoded value(String))
        """

这听起来与r2搜索功能非常相似

radare2 搜索引擎基于 esteve 所做的工作,以及在其上实现的多项功能。它支持多关键字搜索、二进制掩码和十六进制值。它会自动为搜索命中位置创建标志,方便以后的引用。

搜索由 / 命令启动。

[0x00000000]> /?
|Usage: /[amx/] [arg]Search stuff (see 'e??search' for options)
| / foo\x00           search for string 'foo\0'
| /j foo\x00          search for string 'foo\0' (json output)
| /! ff               search for first occurrence not matching
| /+ /bin/sh          construct the string with chunks
| /!x 00              inverse hexa search (find first byte != 0x00)
| //                  repeat last search
| /h[t] [hash] [len]  find block matching this hash. See /#?
| /a jmp eax          assemble opcode and search its bytes
| /A jmp              find analyzed instructions of this type (/A? for help)
| /b                  search backwards
| /B                  search recognized RBin headers
| /c jmp [esp]        search for asm code
| /C[ar]              search for crypto materials
| /d 101112           search for a deltified sequence of bytes
| /e /E.F/i           match regular expression
| /E esil-expr        offset matching given esil expressions %%= here
| /f file [off] [sz]  search contents of file with offset and size
| /i foo              search for string 'foo' ignoring case
| /m magicfile        search for matching magic file (use blocksize)
| /o                  show offset of previous instruction
| /p patternsize      search for pattern of given size
| /P patternsize      search similar blocks
| /r[e] sym.printf    analyze opcode reference an offset (/re for esil)
| /R [grepopcode]     search for matching ROP gadgets, semicolon-separated
| /v[1248] value      look for an `cfg.bigendian` 32bit value
| /V[1248] min max    look for an `cfg.bigendian` 32bit value in range
| /w foo              search for wide string 'f\0o\0o\0'
| /wi foo             search for wide string ignoring case 'f\0o\0o\0'
| /x ff..33           search for hex string ignoring some nibbles
| /x ff0033           search for hex string
| /x ff43 ffd0        search for hexpair with mask
| /z min max          search for strings of given size