从内存转储构造有效的ELF二进制文件

问题描述 投票:0回答:1

我编写了以下简单的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上设置捕获点的原因是因为此syscall在程序执行之前被调用,但程序已加载到内存中)

在内存转储上使用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二进制文件,该二进制文件的运行方式与原始程序相同。请注意,我只想使用十六进制编辑器(例如hexedit)而不使用原始二进制文件即可。

linux debugging binary reverse-engineering elf
1个回答
0
投票

dump binary memory testdump 0x8000000 0x8001000

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

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

我只想用十六进制编辑器就可以做到这一点

此任务实际上并不简单,我怀疑您是否可以使用GDB完成它。

© www.soinside.com 2019 - 2024. All rights reserved.