# Malware Packer Triage Entropy Analysis

> Use when you need to determine whether a binary region is packed, encrypted, or compressed using statistical measurement rather than signatures. Covers computing Shannon entropy per section and per block, visualizing entropy across the file, interpreting readings for code versus packed versus encrypted data, finding blob boundaries, and combining entropy with structural clues. Use when DIE reports unknown, when hunting embedded encrypted configs or payloads, or when validating that an unpack actually restored normal code.

- Skill: `mizazhaider-ceh/malware-packer-triage-entropy-analysis` (Agent Skill)
- Install (CLI): `npx get-skill add mizazhaider-ceh/malware-packer-triage-entropy-analysis`
- Raw SKILL.md: https://api.skillmd.com/api/skills/mizazhaider-ceh/malware-packer-triage-entropy-analysis/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: mizazhaider-ceh (https://skillmd.com/u/mizazhaider-ceh)
- Updated: 2026-11-22
- Page: https://skillmd.com/skills/mizazhaider-ceh/malware-packer-triage-entropy-analysis

---


Entropy measures randomness in bytes, and different content types have
characteristic readings: compiled code sits around 4 to 6, compressed or
encrypted data near 8, padding near 0. When signatures fail, entropy
tells you where the interesting bytes are and what kind they might be.
This sub-skill covers measuring, visualizing, and interpreting entropy
for packer triage. Scope: analyze only samples you are authorized to
handle, in an isolated lab, during authorized DFIR or malware research.

## Quick Workflow

1. Compute per-section entropy from the PE headers.
2. Compute per-block entropy (256 or 512 byte windows) across the file.
3. Plot or list the readings; mark cliffs and plateaus.
4. Interpret each region using the reference bands below.
5. Correlate with structure: section names, entry point, imports.
6. Use the map to aim unpacking (dump the high-entropy region) or config
   extraction (decode the encrypted blob).

## 1. Reference bands

```text
7.8 - 8.0   encrypted or well-compressed data (packed payload, crypto blob)
7.0 - 7.8   compressed data, packed code with some structure
6.0 - 7.0   compressed resources, mixed code and data
4.5 - 6.0   normal compiled code (.text typically lands here)
3.0 - 4.5   structured data, import tables, resources
0.0 - 2.0   padding, zeroed sections, empty space
```

These are guides, not verdicts. x86 code with many immediates reads
higher than RISC code; a section of pure ASCII strings reads around 4.5.
Always compare against the same binary's own `.text` as a baseline when
one exists.

## 2. Per-section measurement

```python
import math, collections, pefile

pe = pefile.PE("sample.exe")
for s in pe.sections:
    name = s.Name.rstrip(b"\x00").decode(errors="replace")
    data = s.get_data()
    c = collections.Counter(data)
    ent = -sum(v/len(data) * math.log2(v/len(data)) for v in c.values()) if data else 0
    print(f"{name:8} raw={s.SizeOfRawData:#8x} virt={s.Misc_VirtualSize:#8x} entropy={ent:.2f}")
```

Example output shape:

```text
.text    raw=0x1000    virt=0x1000    entropy=5.21
.data    raw=0x2000    virt=0x4000    entropy=7.87
.rsrc    raw=0x1000    virt=0x1000    entropy=4.02
```

The `.data` section at 7.87 with virtual size double the raw size is the
packed payload waiting to be unpacked; `.text` at 5.21 is the stub.
This two-line output often answers the whole "is it packed" question.

## 3. Block-level mapping for blob boundaries

```python
# 256-byte sliding windows find boundaries inside sections
data = open("sample.exe","rb").read()
import math, collections
def ent(chunk):
    c = collections.Counter(chunk)
    n = len(chunk)
    return -sum(v/n*math.log2(v/n) for v in c.values())

for off in range(0, len(data), 256):
    e = ent(data[off:off+256])
    bar = "#" * int(e)
    if e > 7.5 or e < 2.0:
        print(f"{off:#08x} {e:.2f} {bar}")
```

Example output shape (abridged):

```text
0x002a00 7.91 ########
...
0x002f00 7.88 ########
0x003000 4.62 ####
```

The cliff at 0x3000 marks the blob boundary: bytes 0x2a00-0x2fff are the
encrypted region to feed the config decoder or the unpacker. Print only
the anomalous windows to keep the output readable on large files.

## 4. Combining entropy with structure

Entropy alone misleads; combine:

- High entropy plus tiny import table plus entry point in last
  section: packed, proceed to unpacking.
- High entropy region plus normal imports plus normal entry point:
  encrypted config or resource blob, proceed to config extraction.
- High entropy in `.rsrc` only: compressed resources, probably benign
  for triage purposes.
- Uniform ~8.0 across the whole file: full-file crypter; the stub is
  tiny or the file is just an encrypted blob with a loader elsewhere.

After unpacking, re-measure: the unpacked `.text` should read 4.5-6.0.
If it still reads 7.9, the unpack failed or there is another layer.

## Edge cases

- Base64-encoded blobs read ~6.0, not 8.0; encoding lowers entropy.
  Check for alphabet patterns before concluding "not encrypted".
- Small windows (under 128 bytes) give noisy readings; use 256+.
- Chi-square complements entropy: high entropy plus uniform chi-square
  means encrypted; high entropy plus skewed chi-square means
  compressed. Both matter for choosing decode vs decompress.
- Overlay data past the last section: measure it separately, it is
  often an appended encrypted payload.
- Entropy of the whole file is almost useless; always go per-section
  or per-block.

## Escalation

- If entropy suggests encryption but no decoder is found statically,
  escalate to runtime extraction (debugger or memory dump at the decode
  point).
- If readings contradict the packer verdict (DIE says UPX, entropy says
  normal code), trust the measurement and re-examine; the signature may
  be faked.

- If entropy contradicts DIE on every sample from one source, escalate: the source may be pre-processing files before you see them.
- If the blob boundary from entropy does not match the decoder's expectations, trust the decoder's parse and re-examine the map.

## Detection and defender view

Entropy is a triage signal, not a detection: "section entropy above 7.5
with fewer than 20 imports" is a useful pipeline heuristic for routing
samples to unpacking, but it is too generic to alert the SOC on its own.
Record entropy profiles per family; when a new variant arrives with the
same section entropy shape, that is a clustering signal. Share the
measurement scripts with the team so every analyst maps blobs the same
way.

## Key references

- pefile (Python PE parsing):
  https://github.com/erocarrera/pefile
- Detect It Easy:
  https://github.com/horsicq/Detect-It-Easy
- MITRE ATT&CK: T1027.002 (Software Packing), T1027 (Obfuscated Files
  or Information)
- Practical Malware Analysis (Sikorski and Honig), Chapter 18
  (packing indicators)

- Shannon entropy (information theory):
  https://en.wikipedia.org/wiki/Entropy_(information_theory)

