Portable executable analysis

From ShulkwiSEC/bb-huge · View interactive version

Portable executable analysis is an AI agent skill from the GitHub repository ShulkwiSEC/bb-huge. Perform static reverse engineering and analysis on Windows Portable Executable (PE) files to identify malicious indicators without executing the file. Use this skill during Incident Response, malware triage, or threat hunting to safely extract metadata, imported APIs, exported functions, embedded st

How to use this skill

Skill file

Portable Executable (PE) Analysis

When to Use

Prerequisites

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

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

📚 Shared Resources

For cross-cutting methodology applicable to all vulnerability classes, see:

- CODE0 — Exploit chaining methodology and high-payout chain patterns

- CODE0 — HackerOne-optimized report writing, CWE quick reference

- CODE0 — Verified disclosed bounties by vulnerability class

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.