Created
November 11, 2021 00:05
-
-
Save valkheim/50227fe786d1b9016b49771ceedfc27c to your computer and use it in GitHub Desktop.
Quick glance at ELF sections during a pwn debug session
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[*] ELF sections summary: | |
+-------+--------------------+----------+-------+-------+-----------------+ | |
| index | name | vaddr | size | perms | type | | |
+-------+--------------------+----------+-------+-------+-----------------+ | |
| 0x0 | | 0x0 | 0x0 | --- | SHT_NULL | | |
| 0x1 | .interp | 0x400238 | 0x1c | r-- | SHT_PROGBITS | | |
| 0x2 | .note.ABI-tag | 0x400254 | 0x20 | r-- | SHT_NOTE | | |
| 0x3 | .note.gnu.build-id | 0x400274 | 0x24 | r-- | SHT_NOTE | | |
| 0x4 | .gnu.hash | 0x400298 | 0x38 | r-- | SHT_GNU_HASH | | |
| 0x5 | .dynsym | 0x4002d0 | 0xf0 | r-- | SHT_DYNSYM | | |
| 0x6 | .dynstr | 0x4003c0 | 0x7c | r-- | SHT_STRTAB | | |
| 0x7 | .gnu.version | 0x40043c | 0x14 | r-- | SHT_GNU_versym | | |
| 0x8 | .gnu.version_r | 0x400450 | 0x20 | r-- | SHT_GNU_verneed | | |
| 0x9 | .rela.dyn | 0x400470 | 0x30 | r-- | SHT_RELA | | |
| 0xa | .rela.plt | 0x4004a0 | 0x30 | r-- | SHT_RELA | | |
| 0xb | .init | 0x4004d0 | 0x17 | r-x | SHT_PROGBITS | | |
| 0xc | .plt | 0x4004f0 | 0x30 | r-x | SHT_PROGBITS | | |
| 0xd | .text | 0x400520 | 0x182 | r-x | SHT_PROGBITS | | |
| 0xe | .fini | 0x4006a4 | 0x9 | r-x | SHT_PROGBITS | | |
| 0xf | .rodata | 0x4006b0 | 0x10 | r-- | SHT_PROGBITS | | |
| 0x10 | .eh_frame_hdr | 0x4006c0 | 0x44 | r-- | SHT_PROGBITS | | |
| 0x11 | .eh_frame | 0x400708 | 0x120 | r-- | SHT_PROGBITS | | |
| 0x12 | .init_array | 0x600df0 | 0x8 | rw- | SHT_INIT_ARRAY | | |
| 0x13 | .fini_array | 0x600df8 | 0x8 | rw- | SHT_FINI_ARRAY | | |
| 0x14 | .dynamic | 0x600e00 | 0x1f0 | rw- | SHT_DYNAMIC | | |
| 0x15 | .got | 0x600ff0 | 0x10 | rw- | SHT_PROGBITS | | |
| 0x16 | .got.plt | 0x601000 | 0x28 | rw- | SHT_PROGBITS | | |
| 0x17 | .data | 0x601028 | 0x10 | rw- | SHT_PROGBITS | | |
| 0x18 | .bss | 0x601038 | 0x8 | rw- | SHT_NOBITS | | |
| 0x19 | .comment | 0x0 | 0x29 | --- | SHT_PROGBITS | | |
| 0x1a | .symtab | 0x0 | 0x618 | --- | SHT_SYMTAB | | |
| 0x1b | .strtab | 0x0 | 0x1f6 | --- | SHT_STRTAB | | |
| 0x1c | .shstrtab | 0x0 | 0x103 | --- | SHT_STRTAB | | |
+-------+--------------------+----------+-------+-------+-----------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pwn import * | |
from tabulate import tabulate | |
def show_sections(elf): | |
header = ["index", "name", "vaddr", "size", "perms", "type"] | |
table = [] | |
for index, section in enumerate(elf.sections): | |
perms = ["-", "-", "-"] # rwx | |
if section.header.sh_flags & 0x2: | |
perms[0] = "r" | |
if section.header.sh_flags & 0x4: | |
perms[2] = "x" | |
if section.header.sh_flags & 0x1: | |
perms[1] = "w" | |
table.append( | |
[ | |
hex(index), | |
section.name, | |
hex(section.header.sh_addr), | |
hex(section.header.sh_size), | |
"".join(perms), | |
section.header.sh_type, | |
] | |
) | |
info("ELF sections summary:\n%s", tabulate(table, headers=header, tablefmt="pretty", colalign="left")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment