The PE header is the file's ID card and blueprint: it says what the file claims to be, where its code lives, what it imports, and when it was built. Malware forges parts of it (timestamps, section names) and cannot forge others (structural consistency). This sub-skill covers reading headers in PE-bear and pefile with an analyst's eye: which fields to check in which order, and what each anomaly means. Scope: analyze only samples you are authorized to handle, in an isolated lab, during authorized DFIR or malware research.
Quick Workflow
- Verify the basics: MZ signature, PE signature, machine type (32 vs 64 bit).
- Check the entry point: file offset, section, and whether it is sane.
- Walk the section table: names, sizes, entropy, characteristics.
- Review the data directories: import table, export table, resources, certificate, debug.
- Check the timestamp, Rich header, and linker version for dating and tampering signs.
- Verify the certificate if present.
- Summarize header findings as triage evidence.
1. Entry point analysis
import pefile
pe = pefile.PE("sample.exe")
ep = pe.OPTIONAL_HEADER.AddressOfEntryPoint
print(f"entry point RVA: {ep:#x}")
for s in pe.sections:
name = s.Name.rstrip(b"\x00").decode(errors="replace")
start = s.VirtualAddress
end = start + s.Misc_VirtualSize
if start <= ep < end:
print(f"entry point is in section: {name}")
Example output shape:
entry point RVA: 0xa310
entry point is in section: UPX1
Entry point in .text is normal. Entry point in the last section, in a
section named after a packer, or in .rsrc is a packer or tampering
tell. An entry point that points outside all sections means corrupted
headers (or deliberate anti-tooling); note it and switch to raw
analysis.
2. Section table reading
In PE-bear's section view, check each section:
Name VirtSize RawSize Entropy Characteristics
.text 0x12000 0x12000 5.31 CODE | EXECUTE | READ
.data 0x4000 0x2000 7.87 DATA | READ | WRITE
UPX0 0x2a000 0x0 0.00 DATA | READ | WRITE
UPX1 0x8000 0x8000 7.94 CODE | EXECUTE | READ | WRITE
.rsrc 0x1000 0x1000 4.10 DATA | READ
Tells: zero RawSize with huge VirtSize (unpacked-at-runtime section), entropy near 8 with WRITE plus EXECUTE (packed payload), section names that are packer brands, more than ~8 sections or sections with random names. Writable-plus-executable sections are suspicious in legitimate software and normal in packed malware; record them either way.
3. Data directories
for entry in pe.OPTIONAL_HEADER.DATA_DIRECTORY:
if entry.Size:
print(f"{entry.name:20} addr={entry.VirtualAddress:#x} size={entry.Size:#x}")
Example output shape:
IMPORT_TABLE addr=0x12000 size=0x3c
RESOURCE_TABLE addr=0x14000 size=0x1000
CERTIFICATE_TABLE addr=0x0 size=0x0
DEBUG_TABLE addr=0x0 size=0x0
What to read: a tiny IMPORT_TABLE (under ~0x100 bytes) means few imports, which corroborates packing. An EXPORT_TABLE on an .exe is unusual and worth noting (possible DLL masquerading). A missing DEBUG_TABLE is normal for malware (no PDB shipped); a present one with a PDB path is an attribution gift. CERTIFICATE_TABLE present means signed: verify next.
4. Timestamps, Rich header, linker version
# Compile timestamp
python3 -c "
import pefile, datetime
pe = pefile.PE('sample.exe')
ts = pe.FILE_HEADER.TimeDateStamp
print(datetime.datetime.utcfromtimestamp(ts).isoformat(), f'({ts:#x})')"
Example output shape:
2026-10-20T03:14:07 (0x6713abcd)
Interpretation: a recent timestamp on a fresh sample is consistent; a 1970 or 1992 timestamp is a known packer default (deliberate); a future date is forgery or clock skew. Compare against the Rich header (DIE shows the decoded Rich data): the Rich header lists linker versions and build counts that are hard to fake consistently. A Rich header claiming MSVC 19.40 with a linker version of 14.0 is a mismatch worth noting. Neither proves anything alone; together they date the build environment.
5. Certificate verification
In PE-bear, open the certificate view: signer name, validity dates, counter-signature timestamp.
Signer: Example Software Ltd
Valid: 2024-01-01 to 2027-01-01
Status: signature VALID, but signer unknown to allowlist
A valid signature from an unknown or recently created company is the stolen-or-bought certificate pattern: do not treat "signed" as "legitimate". An invalid signature (hash mismatch) means the file was modified after signing: strong tampering evidence. Unsigned system- looking binaries (a "svchost.exe" with no Microsoft signature) are an immediate red flag.
6. Header findings as triage evidence
Template for the report:
Headers: PE32, entry in UPX1 (packer stub), 14 imports,
timestamp 2026-10-20 (recent, plausible),
unsigned, Rich header MSVC 19.40 consistent.
Finding: packed with UPX; header evidence supports proceeding
to unpacking before verdict.
Every header claim cites the field: "entry point in UPX1" not "looks packed". Header evidence is the most defensible part of a triage report because it is structural, not behavioral.
Edge cases
- Overlay data: bytes past the last section are not in any header; check separately (often appended config or payload).
- Header-erased dumps: memory dumps may have zeroed headers; graft from the disk file before analysis.
- .NET assemblies: the PE headers wrap CLR metadata; the interesting fields are in the CLR header, not the section table.
- 64-bit vs 32-bit: OPTIONAL_HEADER magic 0x20b vs 0x10b; some tools misparse when the magic lies.
- Deliberately broken headers that still execute: Windows is lenient about some fields; a tool failing to parse does not mean the file is not executable.
Escalation
If headers are so damaged that multiple tools disagree on basic facts (bitness, entry point), escalate to raw byte analysis and note the tooling disagreement in the report.
If certificate analysis suggests a stolen cert from a real company, escalate to threat intel; that is attribution-relevant.
If header analysis suggests a valid signature on a known-malicious hash, escalate to threat intel; the certificate abuse is the story.
If multiple tools disagree on basic header facts, escalate to raw byte analysis and record the disagreement.
Detection and defender view
Header anomalies make good pipeline heuristics: entry point outside .text, writable-executable sections, and tiny import tables route samples to unpacking automatically. Rich header linker versions cluster samples by build environment, which groups campaigns. Signed-malware tracking (signer names, certificate serials) feeds threat intel: one abused certificate often signs a whole campaign's worth of samples.
Key references
- PE-bear: https://github.com/hasherezade/pe-bear
- pefile documentation: https://github.com/erocarrera/pefile
- Microsoft PE format specification: https://learn.microsoft.com/en-us/windows/win32/debug/pe-format
- Detect It Easy: https://github.com/horsicq/Detect-It-Easy
- MITRE ATT&CK: T1027.002 (Software Packing)
