【问题标题】:Constructing working ELF binary from memory dump从内存转储构建工作 ELF 二进制文件
【发布时间】:2020-07-31 12:35:41
【问题描述】:

我编写了以下简单的 C 程序

#include <stdio.h>

int main()
{
  printf("Hello\n");
  return 0;
}

编译后我在 GDB 中加载这个程序并继续如下

> catch syscall brk  
*run and wait for GDB to catch syscall*
> info proc mappings

Start Addr    End Addr    Size    Offset    
0x8000000     0x8001000   0x1000  0x0       <--- this region is r-xp, so this is the code in memory
0x8200000     0x8202000   0x2000  0x0       <--- this region is rw-p, so this is the data in memory
> dump binary memory testdump 0x8000000 0x8001000

(我在 brk 上设置一个 catchpoint 的原因是因为这个系统调用在程序执行之前被调用,但是程序加载到内存中)

在内存转储上使用 readelf 会得到以下输出

$ readelf -h testdump
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              DYN (Shared object file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x530
  Start of program headers:          64 (bytes into file)
  Start of section headers:          6440 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         9
  Size of section headers:           64 (bytes)
  Number of section headers:         29
  Section header string table index: 28
readelf: Error: Reading 1856 bytes extends past end of file for section headers
readelf: Error: Section headers are not available!

我想知道如何修复这些错误并从这个内存转储中生成一个可执行的 ELF 二进制文件,它与原始程序运行相同。请注意,我只想使用 hexeditor(例如 hexedit)而不使用原始二进制文件来执行此操作。

【问题讨论】:

    标签: linux debugging binary reverse-engineering elf


    【解决方案1】:

    dump binary memory testdump 0x8000000 0x8001000

    要制作可运行的程序,您还需要转储数据。

    您的测试二进制文件是动态链接的,这会使您的任务变得非常复杂。我建议从完全静态的二进制文件开始。

    我想只用一个十六进制编辑器来做这个

    这项任务实际上并不简单,我怀疑你是否能够使用 GDB 完成它。

    【讨论】:

    • 如果二进制文件是静态链接的,我该如何修复原始帖子中的错误,并从与原始程序运行相同的内存转储中生成可执行的 ELF 二进制文件?
    • 我不相信你可以。我认为在 GDB 中不可能做到这一点。
    猜你喜欢
    • 1970-01-01
    • 2014-08-10
    • 2021-03-17
    • 2012-07-21
    • 2015-12-28
    • 2017-11-16
    • 2015-11-07
    • 1970-01-01
    • 2013-11-25
    相关资源
    最近更新 更多