Malware Analysis

PE Header Analysis

Analyzing Portable Executable headers including DOS header, COFF header, optional header, section tables, Import Address Table, and detecting packed binaries.

Contents

PE Header Analysis

Purpose: Analyze the structure of Windows executables (PE format) to identify compilation details, packing, suspicious characteristics, and behavioral indicators — all before running the file.


1. Tools for PE Analysis

Quick Setup

  1. PE-bear — Open PE-bear → File → Load PEs → drop executable
  2. PEAnatomist — Drop file into PEAnatomist for detailed timestamp and header analysis
  3. CFF Explorer — Full PE editor with hex view and structure browser
  4. pestudio — Automated PE analysis with threat indicators
  5. Detect It Easy (DiE) — Packer/compiler detection, entropy visualization

All Necessary Information

All header info, imports, resources, and debug info are visible on the main screen of PE-bear.


2. PE File Format Structure

+-----------------------------+
|       DOS Header            |  <- Starts with "MZ" (0x4D 0x5A)
|       (64 bytes)            |
+-----------------------------+
|       DOS Stub              |  <- "This program cannot be run in DOS mode"
|       (Variable)            |
+-----------------------------+
|       PE Signature          |  <- "PE\0\0" (0x50 0x45 0x00 0x00)
+-----------------------------+
|       COFF File Header      |  <- Machine type, number of sections, timestamp
|       (20 bytes)            |
+-----------------------------+
|     Optional Header         |  <- Entry point, image base, subsystem
|     (PE32: 96 + data dirs)  |
|     (PE32+: 112 + data dirs)|
+-----------------------------+
|     Section Headers         |  <- .text, .data, .rdata, .rsrc, etc.
|     (40 bytes each)         |
+-----------------------------+
|     Section Data            |
|     .text (code)            |
|     .rdata (read-only data) |
|     .data (global vars)     |
|     .rsrc (resources)       |
|     .reloc (relocations)    |
+-----------------------------+

3. DOS Header

  • MZ on the blue screen or 4D 5A on the white sheet (hex view) = it is an executable file
  • The DOS header is a legacy structure from MS-DOS — the only important field is:
    • e_lfanew (offset 0x3C) -> points to the PE signature

Quick Check

If first 2 bytes = "MZ" (0x4D 0x5A) -> Valid PE file
If e_lfanew points to "PE\0\0" -> Valid PE header found

4. COFF File Header (IMAGE_FILE_HEADER)

FieldOffsetMeaningMalware Relevance
Machine0x00Target architecture0x14C = x86, 0x8664 = x64
NumberOfSections0x02How many sectionsUnusual count = suspicious
TimeDateStamp0x04Compilation timestampWhen was it compiled? Fake? Future?
PointerToSymbolTable0x08Symbol table offsetUsually 0 for release builds
NumberOfSymbols0x0CSymbol countUsually 0
SizeOfOptionalHeader0x10Optional header sizeVaries by PE32/PE32+
Characteristics0x12File attributesDLL flag, executable, etc.

Timestamp Analysis

PEAnatomist -> File Header section -> TimeDateStamp

Things to check:
- Is the timestamp realistic? (not year 1970 or 2038)
- Is it in the future? (forgery)
- Does it match other samples in the campaign?
- Is it 0x00000000? (stripped)
- Epoch converter: https://www.epochconverter.com/

5. Optional Header (Key Fields)

FieldMeaningMalware Relevance
Magic0x10B = PE32, 0x20B = PE32+ (64-bit)Architecture identification
AddressOfEntryPointRVA where execution beginsUnusual location -> packed/injected
ImageBasePreferred load addressDefault: 0x400000 (exe), 0x10000000 (DLL)
SectionAlignmentMemory alignmentUsually 0x1000 (4KB)
FileAlignmentDisk alignmentUsually 0x200 (512 bytes)
SizeOfImageTotal memory sizeMust match actual sections
SubsystemGUI=2, Console=3, Driver=1What type of executable
DllCharacteristicsSecurity featuresASLR, DEP/NX, CFG, SEH flags
NumberOfRvaAndSizesData directory countUsually 16

DllCharacteristics Security Flags

FlagValueMeaning
IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE0x0040ASLR enabled
IMAGE_DLLCHARACTERISTICS_NX_COMPAT0x0100DEP/NX enabled
IMAGE_DLLCHARACTERISTICS_NO_SEH0x0400No SEH (Structured Exception Handling)
IMAGE_DLLCHARACTERISTICS_GUARD_CF0x4000Control Flow Guard enabled

Malware with no security flags = compiled without protections (intentional or old compiler)


6. Section Headers (IMAGE_SECTION_HEADER)

Standard Sections

SectionPurposeExpected Characteristics
.textExecutable codeIMAGE_SCN_MEM_EXECUTE + IMAGE_SCN_MEM_READ
.rdataRead-only initialized data, importsIMAGE_SCN_MEM_READ
.dataRead-write initialized dataIMAGE_SCN_MEM_READ + IMAGE_SCN_MEM_WRITE
.bssUninitialized dataIMAGE_SCN_MEM_READ + IMAGE_SCN_MEM_WRITE
.rsrcResources (icons, dialogs, version)IMAGE_SCN_MEM_READ
.relocRelocation data (for ASLR)IMAGE_SCN_MEM_READ

Suspicious Section Indicators

IndicatorWhat It Means
Section with RWX (Read+Write+Execute)Self-modifying code or shellcode unpacking
Unknown section names (.upx0, .aspack)Known packer sections
Entry point outside .text sectionPacked — stub in different section
.text section is WRITEableSelf-modifying code
Very high entropy in a section (>7.0)Compressed or encrypted content
Huge gap between VirtualSize and RawSizePacker will expand data in memory

7. Packed Binary Detection

  • If the size of raw data is almost equal to the virtual size (IMAGE_SECTION_HEADER .text) then it is not a packed binary
  • A packed binary is a normal Windows PE executable (.exe, .dll, .sys, etc.) that has been compressed or encrypted by a special tool called a packer (or crypter/protector)

What Happens When You Run a Packed Binary

  1. The packed file is very small or looks like random/garbage data
  2. At runtime, a small piece of code (the stub or unpacking stub) executes first
  3. This stub decompresses or decrypts the real original program in memory
  4. The stub then jumps to the real program’s original entry point (OEP) and the malware runs normally

Packing Detection Checklist

[ ] Virtual Size >> Raw Size for .text section? -> PACKED
[ ] Entry point in unusual section (not .text)? -> PACKED  
[ ] Very few imports (only LoadLibrary/GetProcAddress)? -> PACKED
[ ] Section names match known packers? -> PACKED
[ ] High entropy (>7.0) across sections? -> PACKED
[ ] Few/no meaningful strings? -> PACKED
[ ] Detect It Easy / PEiD identifies a packer? -> PACKED

Common Packers & Their Signatures

PackerSection NamesOther Indicators
UPX.UPX0, .UPX1UPX! magic at end of file
ASPack.aspack, .adataASPack string in overlay
Themida / WinLicense.themidaVirtualized code
VMProtect.vmp0, .vmp1Code virtualization
PECompact.pec, PECompact headerPECompact2 string
MPRESS.MPRESS1, .MPRESS2Similar to UPX
Enigma Protector.enigma1, .enigma2Anti-debug, anti-dump

8. Import Address Table (IAT) Analysis

The IAT lists all DLL functions the binary imports:

What to Check

PE-bear -> Imports tab
  -> Which DLLs are imported?
  -> Which functions from each DLL?
  -> Do the imports match the claimed functionality?

Red-Flag Import Patterns

PatternInterpretation
Only kernel32.dll with LoadLibrary + GetProcAddressDynamic resolution — hiding real imports
ws2_32.dll + wininet.dll importsNetwork communication
crypt32.dll importsEncryption/decryption
VirtualAllocEx + WriteProcessMemoryProcess injection
No imports at allHeavily packed or uses syscalls
ntdll.dll Nt* functionsDirect syscalls, EDR evasion

9. Resources Section (.rsrc)

Resources can contain:

  • Icons — Social engineering (mimicking legitimate software)
  • Version info — Fake publisher, product name
  • Embedded binaries — Payloads hidden in resources
  • Configuration data — Encrypted C2 config
  • Dialogs — Ransom notes, fake error messages

Tools for Resource Analysis

ToolUse
Resource HackerView/extract/edit all resources
PE-bearResources tab shows resource tree
7-ZipCan open PE resources as archive
binwalkFind embedded files in resources

10. Data Directories

IndexNameMalware Relevance
0Export TableDLL exports (check for suspicious function names)
1Import TableIAT — critical for behavior analysis
2Resource TableEmbedded payloads, configs
5Base RelocationNeeded for ASLR
6DebugPDB path -> developer machine info
11Bound ImportRarely used — if present, suspicious
12IATRuntime import resolution
14CLR Runtime Header.NET binary indicator

Debug Directory — Developer Info Leak

The PDB (Program Database) path can leak:
- Developer username
- Project folder structure
- Development machine OS  
- Build environment

Example: C:\Users\attackerName\Desktop\malware_project\Release\payload.pdb

11. Quick PE Analysis Checklist

[ ] 1. Verify MZ header (is it actually a PE file?)
[ ] 2. Check architecture (x86 vs x64)
[ ] 3. Read timestamp (when compiled?)
[ ] 4. Check entry point location (in .text? -> normal)
[ ] 5. Examine sections (names, sizes, entropy, permissions)
[ ] 6. Detect packing (VirtualSize vs RawSize, entropy, DiE)
[ ] 7. Analyze imports (which APIs? -> predict behavior)
[ ] 8. Check resources (embedded files? fake version info?)
[ ] 9. Look for debug info (PDB path leak?)
[ ] 10. Check DLL characteristics (security flags)
[ ] 11. Calculate hashes (MD5/SHA256) -> VirusTotal lookup
[ ] 12. Run through pestudio for automated indicators

Pro Tips

Use pestudio for automated first-pass — It highlights suspicious imports, strings, and sections with color-coded indicators. Best initial triage tool.

Entropy is your packing detector — Normal .text section: ~6.0 entropy. Packed/encrypted: ~7.5+. Use DiE for visual entropy graphs.

Fake timestamps are common — Malware authors often set timestamps to 0, far in the past, or match legitimate software timestamps. Never trust timestamps alone.

Resources hide payloads — Many malware families (Emotet, QakBot) embed encrypted payloads in the PE resource section, decoded at runtime.