url: https://linuxcommand.net/readelf/
title: "readelf - ELFファイルについての情報を表示する"
description: "readelfコマンドはELFファイルについての情報を表示するコマンドになります。ELFはExecutable and Linkable Formatの略でコンパイラが生成するオブジェクトファイルや実行ファイルで利用されているファイルフォー..."
host: linuxcommand.net
favicon: https://linuxcommand.net/wp-content/uploads/2021/02/cropped-favicon-32x32.png
image: https://linuxcommand.net/wp-content/uploads/2018/07/readelf.jpg
readelf は ELF ファイルの情報を表示します。 #ELF は Linux で利用される実行可能プログラムのファイル形式です。
Header の情報を確認する
-e
オプションを利用します。
- ELF ファイルヘッダ
- セクションヘッダ
- プログラムヘッダ
など複数のヘッダを確認できます。
ファイルヘッダの Entry point address
によって、 _start
C 言語のスタートアップ ラベルが 0x8c0 であることがわかります。
セクションヘッダでは
- .text = プログラム命令が 0x8c0 から 0x248 だけある
- .data = データ領域が 0x10058 から 0x10 だけある ことがわかります。
ganyariya@utmkali:~/ctf/fullweakctf$ readelf -e main
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 (Position-Independent Executable file)
Machine: AArch64
Version: 0x1
# _start ラベルのアドレス位置
Entry point address: 0x8c0
Start of program headers: 64 (bytes into file)
Start of section headers: 70368 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 10
Size of section headers: 64 (bytes)
Number of section headers: 36
Section header string table index: 35
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .note.gnu.bu[...] NOTE 0000000000000270 00000270
0000000000000024 0000000000000000 A 0 0 4
[ 2] .interp PROGBITS 0000000000000294 00000294
000000000000001b 0000000000000000 A 0 0 1
[ 3] .gnu.hash GNU_HASH 00000000000002b0 000002b0
000000000000001c 0000000000000000 A 4 0 8
[ 4] .dynsym DYNSYM 00000000000002d0 000002d0
00000000000001b0 0000000000000018 A 5 3 8
[ 5] .dynstr STRTAB 0000000000000480 00000480
00000000000000ce 0000000000000000 A 0 0 1
[ 6] .gnu.version VERSYM 000000000000054e 0000054e
0000000000000024 0000000000000002 A 4 0 2
[ 7] .gnu.version_r VERNEED 0000000000000578 00000578
0000000000000030 0000000000000000 A 5 1 8
[ 8] .rela.dyn RELA 00000000000005a8 000005a8
0000000000000108 0000000000000018 A 4 0 8
[ 9] .rela.plt RELA 00000000000006b0 000006b0
0000000000000108 0000000000000018 AI 4 22 8
[10] .init PROGBITS 00000000000007b8 000007b8
000000000000001c 0000000000000000 AX 0 0 4
[11] .plt PROGBITS 00000000000007e0 000007e0
00000000000000d0 0000000000000000 AX 0 0 16
# プログラム命令は 000008c0 から 0x248 のサイズだけある
[12] .text PROGBITS 00000000000008c0 000008c0
0000000000000248 0000000000000000 AX 0 0 64
[13] .fini PROGBITS 0000000000000b08 00000b08
0000000000000018 0000000000000000 AX 0 0 4
[14] .rodata PROGBITS 0000000000000b20 00000b20
000000000000004c 0000000000000000 A 0 0 4
[15] .eh_frame_hdr PROGBITS 0000000000000b6c 00000b6c
000000000000004c 0000000000000000 A 0 0 4
[16] .eh_frame PROGBITS 0000000000000bb8 00000bb8
0000000000000120 0000000000000000 A 0 0 8
[17] .note.ABI-tag NOTE 0000000000000cd8 00000cd8
0000000000000020 0000000000000000 A 0 0 4
[18] .init_array INIT_ARRAY 000000000001fdb0 0000fdb0
0000000000000010 0000000000000008 WA 0 0 8
[19] .fini_array FINI_ARRAY 000000000001fdc0 0000fdc0
0000000000000008 0000000000000008 WA 0 0 8
[20] .dynamic DYNAMIC 000000000001fdc8 0000fdc8
00000000000001e0 0000000000000010 WA 5 0 8
[21] .got PROGBITS 000000000001ffa8 0000ffa8
0000000000000040 0000000000000008 WA 0 0 8
[22] .got.plt PROGBITS 000000000001ffe8 0000ffe8
0000000000000070 0000000000000008 WA 0 0 8
[23] .data PROGBITS 0000000000020058 00010058
0000000000000010 0000000000000000 WA 0 0 8
[24] .bss NOBITS 0000000000020068 00010068
0000000000000008 0000000000000000 WA 0 0 1
[25] .comment PROGBITS 0000000000000000 00010068
0000000000000042 0000000000000001 MS 0 0 1
[26] .debug_info PROGBITS 0000000000000000 000100aa
00000000000000e8 0000000000000000 0 0 1
[27] .debug_abbrev PROGBITS 0000000000000000 00010192
0000000000000097 0000000000000000 0 0 1
[28] .debug_line PROGBITS 0000000000000000 00010229
00000000000000ac 0000000000000000 0 0 1
[29] .debug_str PROGBITS 0000000000000000 000102d5
000000000000007d 0000000000000001 MS 0 0 1
[30] .debug_addr PROGBITS 0000000000000000 00010352
0000000000000040 0000000000000000 0 0 1
[31] .debug_line_str PROGBITS 0000000000000000 00010392
0000000000000027 0000000000000001 MS 0 0 1
[32] .debug_str_o[...] PROGBITS 0000000000000000 000103b9
0000000000000034 0000000000000000 0 0 1
[33] .symtab SYMTAB 0000000000000000 000103f0
0000000000000ac8 0000000000000018 34 82 8
[34] .strtab STRTAB 0000000000000000 00010eb8
00000000000002c5 0000000000000000 0 0 1
[35] .shstrtab STRTAB 0000000000000000 0001117d
0000000000000163 0000000000000000 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
D (mbind), p (processor specific)
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000000000040 0x0000000000000040
0x0000000000000230 0x0000000000000230 R 0x8
INTERP 0x0000000000000294 0x0000000000000294 0x0000000000000294
0x000000000000001b 0x000000000000001b R 0x1
[Requesting program interpreter: /lib/ld-linux-aarch64.so.1]
LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000cf8 0x0000000000000cf8 R E 0x10000
LOAD 0x000000000000fdb0 0x000000000001fdb0 0x000000000001fdb0
0x00000000000002b8 0x00000000000002c0 RW 0x10000
DYNAMIC 0x000000000000fdc8 0x000000000001fdc8 0x000000000001fdc8
0x00000000000001e0 0x00000000000001e0 RW 0x8
NOTE 0x0000000000000270 0x0000000000000270 0x0000000000000270
0x0000000000000024 0x0000000000000024 R 0x4
NOTE 0x0000000000000cd8 0x0000000000000cd8 0x0000000000000cd8
0x0000000000000020 0x0000000000000020 R 0x4
GNU_EH_FRAME 0x0000000000000b6c 0x0000000000000b6c 0x0000000000000b6c
0x000000000000004c 0x000000000000004c R 0x4
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RW 0x10
GNU_RELRO 0x000000000000fdb0 0x000000000001fdb0 0x000000000001fdb0
0x0000000000000250 0x0000000000000250 R 0x1
# Section = リンカがリンクできるように、「論理的に」命令を分けたもの
# .text Section, .init Section, .data Section...
# Segment = OS がロードする論理的単位
# 02 .note.gnu.build-id .interp ... .text. ... は OS が人まとまりでロードする
# Section = Linker 用, Segment = OS 用
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .note.gnu.build-id .interp .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame .note.ABI-tag
03 .init_array .fini_array .dynamic .got .got.plt .data .bss
04 .dynamic
05 .note.gnu.build-id
06 .note.ABI-tag
07 .eh_frame_hdr
08
09 .init_array .fini_array .dynamic .got