PE file structure — from MZ to Import Table
The PE format carries with it the legacy of MS-DOS, which is why the path to the actual header is longer than in ELF. But the logic is the same: magic bytes, metadata, sections.
DOS Header и PE Signature
Each PE file begins with a 64-byte DOS Header. Two fields are required for analyzing executable files before dynamic analysis:
e_magic (offset 0x00): 0x5A4D— literals MZ. Format confirmation
e_lfanew (offset 0x3C): 4-byte offset to the PE signature. This field is used by the loader and analyst to find the actual header. As chuongdong.com rightly notes in their analysis, this is "the most important field in the DOS Header."
Between the DOS Header and the PE Signature lies the DOS Stub—a real-mode program that typically displays "This program cannot be run in DOS mode." The stub is typically 38 bytes in size, but it can be any size. On CTFs, authors sometimes hide hints or even flags inside the DOS Stub (yes, right there). It's worth checking through xxd.
By displacement from e_lfanewlies PE Signature: 0x50450000 (ASCII PE\0\0). If this signature is missing, the file is not a valid PE, even if it is present. MZat the beginning.
COFF Header, Optional Header and PE sections
Immediately after the PE Signature comes the COFF File Header (20 bytes):
Machine: 0x014C= i386, 0x8664= x86-64 — defines the architecture of the binary file, i.e., which processor module to install in Ghidra
NumberOfSections: standard PE contains 3-6 sections ( .text, .data, .rdata, .rsrc, .reloc). More than 10 or sections with non-standard names - smells like a packer
TimeDateStamp: compilation time. A zero value or a date in the distant future is suspicious. Packers and malware builders often reset this field.
Optional Header (mandatory for executable files, despite the name—thanks to Microsoft for the naming) contains:
Magic: 0x010B= PE32, 0x020B = PE32+ (64-bit)
AddressOfEntryPoint — RVA of the entry point, analog e_entryn ELF
ImageBase - The preferred base download address, by default 0x400000for EXE
Data Directories - an array of 16 entries pointing to the Import Table, Export Table, and Resource Table
The PE Header Import Table is the most informative structure for quick triage. It shows which DLLs and functions the binary imports:
Minimum set of imports (only kernel32.dllwith a couple of functions) with a large binary size - a sign of a packer that resolves the API dynamically
VirtualAlloc + WriteProcessMemory + CreateRemoteThread— a classic three-part code injection
IsDebuggerPresent, NtQueryInformationProcess— anti-debugging checks (T1497.001, System Checks for MITRE ATT&CK)
Complete absence of Import Table - the binary allows imports via LoadLibrary/ GetProcAddressat runtime
The Export Table usually belongs to a DLL, not an EXE. If an EXE exports functions, the pattern is atypical and warrants closer inspection.
Tools for static analysis of ELF PE
A set of utilities for reverse engineering binaries that performs faster than any disassembler:
ELF toolkit (Linux): fileto determine the format; readelfwith keys -h(headline), -l(segments), -S(sections), -d(dynamic dependencies), -s(character table); objdump -xfor summary information; strings -ato extract ASCII/Unicode strings; xxdfor raw hex dump.
PE toolkit (cross-platform): fileWorks for PE on Linux too; Python library pefileParses all structures from a script; PE-bear and CFF Explorer are GUI analyzers for Windows.
import pefile
pe = pefile.PE('task.exe')
print(f"Machine: {hex(pe.FILE_HEADER.Machine)}")
print(f"Entry: {hex(pe.OPTIONAL_HEADER.AddressOfEntryPoint)}")
print(f"Sections: {pe.FILE_HEADER.NumberOfSections}")
for s in pe.sections:
name = s.Name.decode().rstrip(chr(0))
print(f" {name:8s} VSize={hex(s.Misc_VirtualSize)} Raw={hex(s.SizeOfRawData)}")
Six lines—and on the screen—the architecture, entry point, and section list with sizes are displayed. If the virtual section size is several times larger than the raw size, the data is unpacked in memory, a classic sign of Software Packing (T1027.002).
Red flags in headlines: packers and obfuscation
When analyzing ELF and PE files—for CTF or malware research—the headers reveal suspicious binaries even before disassembly. This is, in fact, the whole point of triage.
Software Packing (T1027.002, Defense Evasion): - Sections with names .UPX0, .UPX1, .aspack, .petite— an open sign of a specific packer - Sections with unreadable names instead of ASCII - The entry point does not point to .text, and in the last section (unpacker pattern: code at the end, jump to the beginning after unpacking) - Minimal Import Table in PE with large file sizes - Section entropy above 7.0 (regular code - 5.0-6.5, packed - 7.5+)
Stripped Payloads (T1027.008): - fileshows stripped - readelf -Sdoes not contain .symtab And .strtab - The disassembler shows sub_401000instead of real function names
Obfuscated Files or Information (T1027): - Non-standard values in e_ident(unexpected OS/ABI byte) - The entropy of the entire file is higher than 7.0 - Discrepancy between the declared architecture and the actual code - in CTFs it is seen as a deliberate complication
The logic here is simple: attackers pack and strip binaries to evade antivirus signatures and complicate analysis. CTF authors use the same techniques to increase task difficulty.
Preparing for Analysis in Ghidra - Pre-Upload Checklist
After reading the headers, you've gathered enough information to configure the disassembler wisely:
Architecture and bit depth. e_machine(ELF) or Machine(PE) determine the processor module. Ghidra usually guesses automatically, but for MIPS, PowerPC, and RISC-V, it's worth checking manually.
Base address. For PIE binaries ( ET_DYN) Ghidra sets up a base 0x100000, the actual one may differ. For PE - check ImageBase из Optional Header
Stripped or not. If stripped, enable Function ID (Ghidra) or FLIRT (IDA) to recover library function names from signatures.
Packer? Signs of packaging - first unpack ( upx -dfor UPX, manual unpacking for the rest). Ghidra will show garbage on the packed binary.
Dynamic dependencies. readelf -dfor ELF, Import Table for PE. libcrypto.so= cryptography, ws2_32.dll= network interaction - this suggests functionality before code analysis
Security features. NX, RELRO, canaries, PIE — identify exploitation vectors in pwn tasks
Deadlines. strings -a ./binary | less— the most underrated tool. CTF flags, command server URLs, paths, and debug messages are all in .rodata And .data
The PE format carries with it the legacy of MS-DOS, which is why the path to the actual header is longer than in ELF. But the logic is the same: magic bytes, metadata, sections.
DOS Header и PE Signature
Each PE file begins with a 64-byte DOS Header. Two fields are required for analyzing executable files before dynamic analysis:
e_magic (offset 0x00): 0x5A4D— literals MZ. Format confirmation
e_lfanew (offset 0x3C): 4-byte offset to the PE signature. This field is used by the loader and analyst to find the actual header. As chuongdong.com rightly notes in their analysis, this is "the most important field in the DOS Header."
Between the DOS Header and the PE Signature lies the DOS Stub—a real-mode program that typically displays "This program cannot be run in DOS mode." The stub is typically 38 bytes in size, but it can be any size. On CTFs, authors sometimes hide hints or even flags inside the DOS Stub (yes, right there). It's worth checking through xxd.
By displacement from e_lfanewlies PE Signature: 0x50450000 (ASCII PE\0\0). If this signature is missing, the file is not a valid PE, even if it is present. MZat the beginning.
COFF Header, Optional Header and PE sections
Immediately after the PE Signature comes the COFF File Header (20 bytes):
Machine: 0x014C= i386, 0x8664= x86-64 — defines the architecture of the binary file, i.e., which processor module to install in Ghidra
NumberOfSections: standard PE contains 3-6 sections ( .text, .data, .rdata, .rsrc, .reloc). More than 10 or sections with non-standard names - smells like a packer
TimeDateStamp: compilation time. A zero value or a date in the distant future is suspicious. Packers and malware builders often reset this field.
Optional Header (mandatory for executable files, despite the name—thanks to Microsoft for the naming) contains:
Magic: 0x010B= PE32, 0x020B = PE32+ (64-bit)
AddressOfEntryPoint — RVA of the entry point, analog e_entryn ELF
ImageBase - The preferred base download address, by default 0x400000for EXE
Data Directories - an array of 16 entries pointing to the Import Table, Export Table, and Resource Table
The PE Header Import Table is the most informative structure for quick triage. It shows which DLLs and functions the binary imports:
Minimum set of imports (only kernel32.dllwith a couple of functions) with a large binary size - a sign of a packer that resolves the API dynamically
VirtualAlloc + WriteProcessMemory + CreateRemoteThread— a classic three-part code injection
IsDebuggerPresent, NtQueryInformationProcess— anti-debugging checks (T1497.001, System Checks for MITRE ATT&CK)
Complete absence of Import Table - the binary allows imports via LoadLibrary/ GetProcAddressat runtime
The Export Table usually belongs to a DLL, not an EXE. If an EXE exports functions, the pattern is atypical and warrants closer inspection.
Tools for static analysis of ELF PE
A set of utilities for reverse engineering binaries that performs faster than any disassembler:
ELF toolkit (Linux): fileto determine the format; readelfwith keys -h(headline), -l(segments), -S(sections), -d(dynamic dependencies), -s(character table); objdump -xfor summary information; strings -ato extract ASCII/Unicode strings; xxdfor raw hex dump.
PE toolkit (cross-platform): fileWorks for PE on Linux too; Python library pefileParses all structures from a script; PE-bear and CFF Explorer are GUI analyzers for Windows.
import pefile
pe = pefile.PE('task.exe')
print(f"Machine: {hex(pe.FILE_HEADER.Machine)}")
print(f"Entry: {hex(pe.OPTIONAL_HEADER.AddressOfEntryPoint)}")
print(f"Sections: {pe.FILE_HEADER.NumberOfSections}")
for s in pe.sections:
name = s.Name.decode().rstrip(chr(0))
print(f" {name:8s} VSize={hex(s.Misc_VirtualSize)} Raw={hex(s.SizeOfRawData)}")
Six lines—and on the screen—the architecture, entry point, and section list with sizes are displayed. If the virtual section size is several times larger than the raw size, the data is unpacked in memory, a classic sign of Software Packing (T1027.002).
Red flags in headlines: packers and obfuscation
When analyzing ELF and PE files—for CTF or malware research—the headers reveal suspicious binaries even before disassembly. This is, in fact, the whole point of triage.
Software Packing (T1027.002, Defense Evasion): - Sections with names .UPX0, .UPX1, .aspack, .petite— an open sign of a specific packer - Sections with unreadable names instead of ASCII - The entry point does not point to .text, and in the last section (unpacker pattern: code at the end, jump to the beginning after unpacking) - Minimal Import Table in PE with large file sizes - Section entropy above 7.0 (regular code - 5.0-6.5, packed - 7.5+)
Stripped Payloads (T1027.008): - fileshows stripped - readelf -Sdoes not contain .symtab And .strtab - The disassembler shows sub_401000instead of real function names
Obfuscated Files or Information (T1027): - Non-standard values in e_ident(unexpected OS/ABI byte) - The entropy of the entire file is higher than 7.0 - Discrepancy between the declared architecture and the actual code - in CTFs it is seen as a deliberate complication
The logic here is simple: attackers pack and strip binaries to evade antivirus signatures and complicate analysis. CTF authors use the same techniques to increase task difficulty.
Preparing for Analysis in Ghidra - Pre-Upload Checklist
After reading the headers, you've gathered enough information to configure the disassembler wisely:
Architecture and bit depth. e_machine(ELF) or Machine(PE) determine the processor module. Ghidra usually guesses automatically, but for MIPS, PowerPC, and RISC-V, it's worth checking manually.
Base address. For PIE binaries ( ET_DYN) Ghidra sets up a base 0x100000, the actual one may differ. For PE - check ImageBase из Optional Header
Stripped or not. If stripped, enable Function ID (Ghidra) or FLIRT (IDA) to recover library function names from signatures.
Packer? Signs of packaging - first unpack ( upx -dfor UPX, manual unpacking for the rest). Ghidra will show garbage on the packed binary.
Dynamic dependencies. readelf -dfor ELF, Import Table for PE. libcrypto.so= cryptography, ws2_32.dll= network interaction - this suggests functionality before code analysis
Security features. NX, RELRO, canaries, PIE — identify exploitation vectors in pwn tasks
Deadlines. strings -a ./binary | less— the most underrated tool. CTF flags, command server URLs, paths, and debug messages are all in .rodata And .data