Portable Executable (PE) Analysis
When to Use
- You receive a suspicious attachment (.exe, .dll, .scr) and need to verify if it is malicious without infecting a sandbox.
- When conducting static malware triage to determine the file's capabilities (e.g., does it have networking functions? Keylogging functions?).
- When trying to identify if a binary is "packed" (obfuscated/compressed) to evade antivirus signatures.
- To extract hardcoded Configuration Data, C2 (Command and Control) IP addresses, or Bitcoin wallets from ransomware or trojans.
Prerequisites
- Isolated analysis environment (VM with snapshot capability)
- Sample file safely obtained and handled with appropriate precautions
- PE analysis tools (PE-bear, CFF Explorer, Detect It Easy) installed
- Disassembler/decompiler (Ghidra, IDA Free, or Binary Ninja) configured
Workflow
Phase 1: File Identification & Hashing
# Concept: Always identify the actual file type, as malware authors often disguise
# executables with fake extensions (e.g., invoice.pdf.exe).
# 1. Generate Hashes to cross-reference with VirusTotal or Threat Intelligence
md5sum suspicious_file.bin
sha256sum suspicious_file.bin
# 2. Check the real file type using magic bytes
file suspicious_file.bin
# Output expected: PE32 executable (GUI) Intel 80386, for MS Windows
# Keep an eye out for UPX compressed warnings or unexpected compiled languages (.NET, Go).
Phase 2: String Extraction & Obfuscation Checks
# Concept: Malware contains hardcoded text (API names, error messages, IPs).
# Extracting them statically is the fastest way to understand a program's intent.
# 1. Standard string extraction (ASCII and Unicode)
strings -a suspicious_file.bin > strings_ascii.txt
strings -el suspicious_file.bin > strings_unicode.txt
# 2. Search for common malicious patterns:
grep -i "http\|https\|ftp\|www" strings_ascii.txt # Look for C2 domains
grep -i "cmd.exe\|powershell\|vssadmin" strings_ascii.txt # Look for execution / shadow copy deletion
grep -i "CurrentVersion\\Run" strings_ascii.txt # Look for persistence mechanisms
# 3. Use FLOSS (FireEye Labs Obfuscated String Solver)
# If strings output is garbage, the strings are likely encoded (XOR'd) or packed.
# FLOSS automatically deobfuscates standard encryption routines statically.
floss suspicious_file.bin > deobfuscated_strings.txt
Phase 3: PE Header Analysis
# Concept: The PE Header contains the blueprint for how Windows loads the file into memory.
# 1. Check Compilation Timestamps (pefile / pestudio)
# Is the timestamp in the future? Is it 1992? Attackers frequently spoof timestamps.
python3 -c "import pefile; pe = pefile.PE('suspicious_file.bin'); print(pe.FILE_HEADER.dump_dict())"
# 2. Analyze Sections (.text, .data, .rsrc)
# The .text section contains executable code. The .data contains initialized variables.
# - High Entropy (randomness > 7.0) in any section usually means it is packed or encrypted.
# - Virtual Size significantly larger than Raw Size means a payload will unpack itself into memory (classic packing indicator).
# Detect packers computationally:
# e.g., using PEiD or Detect It Easy (DIE) or Yara rules.
diec suspicious_file.bin # Automatically detects UPX, Themida, VMProtect, etc.
Phase 4: Import / Export Analysis (IAT / EAT)
# Concept: Programs import functions from Windows DLLs to interact with the OS.
# The Import Address Table (IAT) is the list of requested functions.
# A small IAT (e.g., only LoadLibrary and GetProcAddress) is the #1 indicator of a packed file.
# Using Python Pefile to list imports:
import pefile
pe = pefile.PE('suspicious_file.bin')
for entry in pe.DIRECTORY_ENTRY_IMPORT:
print(entry.dll.decode('utf-8'))
for imp in entry.imports:
print('\t', hex(imp.address), imp.name.decode('utf-8') if imp.name else '<ordinal>')
# Analyze capabilities based on imports:
# - Networking: WININET.dll (InternetOpen, InternetReadFile), WS2_32.dll (socket, connect)
# - Keylogging: USER32.dll (SetWindowsHookEx, GetAsyncKeyState)
# - Injection: KERNEL32.dll (VirtualAllocEx, WriteProcessMemory, CreateRemoteThread)
# - Anti-Debugging: KERNEL32.dll (IsDebuggerPresent, OutputDebugString)
Phase 5: Resource Extraction
# Concept: Malware often hides secondary payloads (like drivers or the actual malicious shellcode)
# inside the Resource (.rsrc) section (Icon, Dialogs, Version Info).
# 1. List Resources
# pestudio or Resource Hacker (Windows GUI) are excellent for this.
# 2. Extract anomalous resources (e.g., a "binary" resource nested inside an Icon file)
# If extracted, repeat Phase 1-4 on the new binary.
🔵 Blue Team Detection & Defense
- Yara Rules: Use Yara to scan endpoints for specific PE byte sequences, imported API clusters, or hardcoded strings identified during static analysis.
- Import Hashing (ImpHash): Calculate the MD5 hash of the malware's Import Address Table. Even if attackers change the code to alter the file's primary SHA256 hash, their ImpHash often remains identical, allowing immediate clustering of malware families.
- Endpoint Detection: EDR solutions hook into the precise Windows APIs (e.g.,
CreateRemoteThread) identified during IAT analysis to block process injection dynamically.
Key Concepts
| Concept |
Description |
| PE File |
Portable Executable; the standard file format for executables, object code, and DLLs in Windows |
| IAT |
Import Address Table; maps function calls to their physical addresses in standard Windows DLLs |
| Packer |
Software that compresses or encrypts a binary to avoid static detection, requiring it to unpack itself in memory |
| ImpHash |
Import Hash; a unique fingerprint based on the specific order and combination of functions a PE imports |
| FLOSS |
A reverse engineering tool that automatically decodes obfuscated strings statically |
Output Format
Static Malware Analysis Triage
==============================
File: invoice_urgent.exe
SHA256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
File Type: PE32 executable (GUI) Intel 80386
Indicators of Compromise (IOCs):
- Packed: YES. Entropy of .text section is 7.5. IAT contains only LoadLibraryA and GetProcAddress. DetectItEasy flags 'UPX 3.96'.
- Suspicious Imports (Post-Deobfuscation via FLOSS):
- VirtualAllocEx, WriteProcessMemory (Process Injection)
- InternetOpenUrlA (C2 Command structure)
- Extracted Networking Strings:
- hxxp://malicious-c2-domain[.]com/gate.php
- Mozilla/5.0 (Windows NT 10.0; Win64; x64)
Summary Assessment: HIGHLY MALICIOUS. Dropper/Downloader masking as a document. Attempts process hollowing and reaches out to a hardcoded command server. Do not execute in production.
🛡️ Remediation & Mitigation Strategy
- Input Validation: Sanitize and strictly type-check all inputs.
- Least Privilege: Constrain component execution bounds.
📚 Shared Resources
For cross-cutting methodology applicable to all vulnerability classes, see:
References
1---2name: portable-executable-analysis3description: >4 Perform static reverse engineering and analysis on Windows Portable Executable (PE) files to identify5 malicious indicators without executing the file. Use this skill during Incident Response, malware6 triage, or threat hunting to safely extract metadata, imported APIs, exported functions, embedded7 strings, and packed indicators from suspicious Windows binaries (.exe, .dll, .sys).8domain: cybersecurity9subdomain: malware-analysis10category: Static Analysis11difficulty: intermediate12estimated_time: "2-4 hours"13mitre_attack:14 tactics: [TA0005, TA0002]15 techniques: [T1027, T1129, T1106]16platforms: [windows, linux]17tags: [malware-analysis, static-analysis, reverse-engineering, portable-executable, infosec, pe-headers, string-extraction]18tools: [peirates, pestudio, peid, strings, floss, capstone, python-pefile]19version: "1.0"20author: CyberSkills-Elite21license: Apache-2.022metadata:23 source: https://skillmd.com/skills/shulkwisec/portable-executable-analysis24---2526# Portable Executable (PE) Analysis2728## When to Use29- You receive a suspicious attachment (.exe, .dll, .scr) and need to verify if it is malicious without infecting a sandbox.30- When conducting static malware triage to determine the file's capabilities (e.g., does it have networking functions? Keylogging functions?).31- When trying to identify if a binary is "packed" (obfuscated/compressed) to evade antivirus signatures.32- To extract hardcoded Configuration Data, C2 (Command and Control) IP addresses, or Bitcoin wallets from ransomware or trojans.333435## Prerequisites36- Isolated analysis environment (VM with snapshot capability)37- Sample file safely obtained and handled with appropriate precautions38- PE analysis tools (PE-bear, CFF Explorer, Detect It Easy) installed39- Disassembler/decompiler (Ghidra, IDA Free, or Binary Ninja) configured4041## Workflow4243### Phase 1: File Identification & Hashing4445```bash46# Concept: Always identify the actual file type, as malware authors often disguise 47# executables with fake extensions (e.g., invoice.pdf.exe).4849# 1. Generate Hashes to cross-reference with VirusTotal or Threat Intelligence50md5sum suspicious_file.bin51sha256sum suspicious_file.bin5253# 2. Check the real file type using magic bytes54file suspicious_file.bin55# Output expected: PE32 executable (GUI) Intel 80386, for MS Windows56# Keep an eye out for UPX compressed warnings or unexpected compiled languages (.NET, Go).57```5859### Phase 2: String Extraction & Obfuscation Checks6061```bash62# Concept: Malware contains hardcoded text (API names, error messages, IPs).63# Extracting them statically is the fastest way to understand a program's intent.6465# 1. Standard string extraction (ASCII and Unicode)66strings -a suspicious_file.bin > strings_ascii.txt67strings -el suspicious_file.bin > strings_unicode.txt6869# 2. Search for common malicious patterns:70grep -i "http\|https\|ftp\|www" strings_ascii.txt # Look for C2 domains71grep -i "cmd.exe\|powershell\|vssadmin" strings_ascii.txt # Look for execution / shadow copy deletion72grep -i "CurrentVersion\\Run" strings_ascii.txt # Look for persistence mechanisms7374# 3. Use FLOSS (FireEye Labs Obfuscated String Solver)75# If strings output is garbage, the strings are likely encoded (XOR'd) or packed.76# FLOSS automatically deobfuscates standard encryption routines statically.77floss suspicious_file.bin > deobfuscated_strings.txt78```7980### Phase 3: PE Header Analysis8182```bash83# Concept: The PE Header contains the blueprint for how Windows loads the file into memory.8485# 1. Check Compilation Timestamps (pefile / pestudio)86# Is the timestamp in the future? Is it 1992? Attackers frequently spoof timestamps.87python3 -c "import pefile; pe = pefile.PE('suspicious_file.bin'); print(pe.FILE_HEADER.dump_dict())"8889# 2. Analyze Sections (.text, .data, .rsrc)90# The .text section contains executable code. The .data contains initialized variables.91# - High Entropy (randomness > 7.0) in any section usually means it is packed or encrypted.92# - Virtual Size significantly larger than Raw Size means a payload will unpack itself into memory (classic packing indicator).9394# Detect packers computationally:95# e.g., using PEiD or Detect It Easy (DIE) or Yara rules.96diec suspicious_file.bin # Automatically detects UPX, Themida, VMProtect, etc.97```9899### Phase 4: Import / Export Analysis (IAT / EAT)100101```bash102# Concept: Programs import functions from Windows DLLs to interact with the OS.103# The Import Address Table (IAT) is the list of requested functions.104# A small IAT (e.g., only LoadLibrary and GetProcAddress) is the #1 indicator of a packed file.105106# Using Python Pefile to list imports:107```108```python109import pefile110pe = pefile.PE('suspicious_file.bin')111for entry in pe.DIRECTORY_ENTRY_IMPORT:112 print(entry.dll.decode('utf-8'))113 for imp in entry.imports:114 print('\t', hex(imp.address), imp.name.decode('utf-8') if imp.name else '<ordinal>')115```116```bash117118# Analyze capabilities based on imports:119# - Networking: WININET.dll (InternetOpen, InternetReadFile), WS2_32.dll (socket, connect)120# - Keylogging: USER32.dll (SetWindowsHookEx, GetAsyncKeyState)121# - Injection: KERNEL32.dll (VirtualAllocEx, WriteProcessMemory, CreateRemoteThread)122# - Anti-Debugging: KERNEL32.dll (IsDebuggerPresent, OutputDebugString)123```124125### Phase 5: Resource Extraction126127```bash128# Concept: Malware often hides secondary payloads (like drivers or the actual malicious shellcode)129# inside the Resource (.rsrc) section (Icon, Dialogs, Version Info).130131# 1. List Resources132# pestudio or Resource Hacker (Windows GUI) are excellent for this.133134# 2. Extract anomalous resources (e.g., a "binary" resource nested inside an Icon file)135# If extracted, repeat Phase 1-4 on the new binary.136```137138## 🔵 Blue Team Detection & Defense139- **Yara Rules**: Use Yara to scan endpoints for specific PE byte sequences, imported API clusters, or hardcoded strings identified during static analysis.140- **Import Hashing (ImpHash)**: Calculate the MD5 hash of the malware's Import Address Table. Even if attackers change the code to alter the file's primary SHA256 hash, their ImpHash often remains identical, allowing immediate clustering of malware families.141- **Endpoint Detection**: EDR solutions hook into the precise Windows APIs (e.g., `CreateRemoteThread`) identified during IAT analysis to block process injection dynamically.142143## Key Concepts144| Concept | Description |145|---------|-------------|146| PE File | Portable Executable; the standard file format for executables, object code, and DLLs in Windows |147| IAT | Import Address Table; maps function calls to their physical addresses in standard Windows DLLs |148| Packer | Software that compresses or encrypts a binary to avoid static detection, requiring it to unpack itself in memory |149| ImpHash | Import Hash; a unique fingerprint based on the specific order and combination of functions a PE imports |150| FLOSS | A reverse engineering tool that automatically decodes obfuscated strings statically |151152## Output Format153```154Static Malware Analysis Triage155==============================156File: invoice_urgent.exe157SHA256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855158File Type: PE32 executable (GUI) Intel 80386159160Indicators of Compromise (IOCs):161- Packed: YES. Entropy of .text section is 7.5. IAT contains only LoadLibraryA and GetProcAddress. DetectItEasy flags 'UPX 3.96'.162- Suspicious Imports (Post-Deobfuscation via FLOSS):163 - VirtualAllocEx, WriteProcessMemory (Process Injection)164 - InternetOpenUrlA (C2 Command structure)165- Extracted Networking Strings:166 - hxxp://malicious-c2-domain[.]com/gate.php167 - Mozilla/5.0 (Windows NT 10.0; Win64; x64)168169Summary Assessment: HIGHLY MALICIOUS. Dropper/Downloader masking as a document. Attempts process hollowing and reaches out to a hardcoded command server. Do not execute in production.170```171172## 🛡️ Remediation & Mitigation Strategy173- **Input Validation:** Sanitize and strictly type-check all inputs.174- **Least Privilege:** Constrain component execution bounds.175176177## 📚 Shared Resources178> For cross-cutting methodology applicable to all vulnerability classes, see:179> - [`_shared/references/elite-chaining-strategy.md`](../_shared/references/elite-chaining-strategy.md) — Exploit chaining methodology and high-payout chain patterns180> - [`_shared/references/elite-report-writing.md`](../_shared/references/elite-report-writing.md) — HackerOne-optimized report writing, CWE quick reference181> - [`_shared/references/real-world-bounties.md`](../_shared/references/real-world-bounties.md) — Verified disclosed bounties by vulnerability class182183## References184- Mandiant: [FLOSS String Deobfuscator](https://github.com/mandiant/flare-floss)185- PE Format Documentation: [Microsoft Learn](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format)186- PeStudio: [Static Triage Tool](https://www.winitor.com/)