<!-- Copyright (c) 2026 defconxt. All rights reserved. -->
<!-- Licensed under AGPL-3.0 — see LICENSE file for details. -->
<!-- NERF is a trademark of defconxt. -->
---
name: analyzing-packed-executables
description: >-
  Analyze packed and compressed executables to identify packing algorithms, unpack protected binaries, and recover original code.
domain: cybersecurity
subdomain: reverse-engineering
tags:
  - packing
  - unpacking
  - upx
  - themida
  - entropy
version: "1.0"
author: defconxt
license: AGPL-3.0
metadata:
  mitre-attack: ["T1027.002"]
  cwe: ["CWE-506"]
  tools: ["DIE", "UPX", "unipacker", "PE-bear", "binwalk"]
---

# Analyzing Packed Executables

## Overview

Analyze packed and compressed executables to identify packing algorithms, unpack protected binaries, and recover original code.

## Prerequisites

| Tool / Requirement | Details |
|---|---|
| `DIE` | Security tooling |
| `UPX` | Security tooling |
| `unipacker` | Security tooling |
| `PE-bear` | Security tooling |
| `binwalk` | Security tooling |
| Isolated lab environment for testing | Environment requirement |
| Authorization and signed Rules of Engagement (RoE) | Environment requirement |
| Relevant target samples or systems acquired through authorized channels | Environment requirement |

## Quick Reference

```bash
# Detect packing
python3 -c "import pefile; pe = pefile.PE('./sample.exe'); print(pe.sections)"
die ./sample.exe          # Detect It Easy

# Check entropy per section
rabin2 -S ./sample.exe | awk '{print $1, $NF}'

# Unpack UPX
upx -d ./sample.exe -o unpacked.exe

# Dynamic unpacking with x64dbg
# Set breakpoint on VirtualAlloc, run until OEP
```

## Workflow

### Step 1: Preparation and Reconnaissance

```bash
# Identify target and gather initial intelligence
file ./target_sample
die --version 2>/dev/null || echo "Install DIE"

# Set up working directory
mkdir -p /tmp/analyzing-packed-executables/{output,logs,artifacts}
```

### Step 2: Primary Analysis

```bash
# Execute primary analysis with DIE
# Refer to Quick Reference above for detailed commands
echo "[*] Running Analyzing Packed Executables with DIE..."

# Log all operations
script -q /tmp/analyzing-packed-executables/logs/session.log
```

### Step 3: Deep Investigation

```bash
# Apply UPX for secondary analysis
echo "[*] Deep investigation with UPX..."

# Cross-reference findings
diff /tmp/analyzing-packed-executables/output/primary.json /tmp/analyzing-packed-executables/output/secondary.json
```

### Step 4: Documentation and Reporting

```bash
# Generate structured findings report
cat <<'EOF' > /tmp/analyzing-packed-executables/output/report.json
{
  "technique": "analyzing-packed-executables",
  "domain": "reverse-engineering",
  "tools_used": ["DIE", "UPX"],
  "findings": [],
  "recommendations": []
}
EOF
```

## Detection

```yaml
title: Packed Executables Detection
id: 09fab9c8-ee5f-47f7-ab9a-c1570ec7d984
status: experimental
description: Detects suspicious activity related to analyzing packed executables techniques in reverse engineering context
logsource:
  category: process_creation
  product: windows
detection:
  selection:
    CommandLine: "*analyzing*packed*"
  condition: selection
level: medium
tags:
  - attack.t1027.002
  - attack.defense_evasion
falsepositives:
  - Malware analysis sandbox performing automated binary inspection
```


**Detection Opportunities**

| Indicator | Source | Detection Logic |
|---|---|---|
| Packed Executables Detection | windows/process_creation | Sigma rule (medium) |
| ATT&CK Coverage | MITRE ATT&CK | T1027.002 |

## Verification

- [ ] Environment and tools verified and operational
- [ ] Target samples acquired through authorized channels
- [ ] Primary analysis completed with findings documented
- [ ] Secondary validation performed with independent tooling
- [ ] All artifacts preserved in structured output directory
- [ ] Detection opportunities documented for blue team

## References

- [MITRE ATT&CK T1027.002](https://attack.mitre.org/techniques/T1027/002) — Related technique
- [DIE Documentation](https://die.org/) — Primary tooling
- [UPX Reference](https://upx.org/) — Secondary tooling
