Skip to content
Back to skills

Analyzing Compiled Python Malware

ASecurity

'Analyzes Python-based malware packaged as PyInstaller/py2exe executables by detecting

  • 22 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 11, 2026
securitypythonbashapisecurity

Works with

  • api

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned September 11, 2026

npx -y skills add meltedinhex/analyst-ai-pack --skill analyzing-compiled-python-malware --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Analyzing Compiled Python Malware?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Analyzing Compiled Python Malware
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/meltedinhex-analyzing-compiled-python-malware/badge)](https://www.skillsdirectory.com/skills/meltedinhex-analyzing-compiled-python-malware)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: analyzing-compiled-python-malware
description: 'Analyzes Python-based malware packaged as PyInstaller/py2exe executables by detecting
  the packer, locating the embedded archive, and identifying bundled .pyc modules for extraction and
  decompilation. Activates for requests to analyze compiled Python malware, unpack a PyInstaller
  binary, or extract pyc modules from a frozen Python executable.'
domain: cybersecurity
subdomain: reverse-engineering
tags:
  - reverse-engineering
  - python
  - pyinstaller
  - pyc
  - unpacking
version: 1.0.0
author: analyst-ai-pack
license: Apache-2.0
mitre_attack:
  - T1027
  - T1059.006
  - T1587.001
d3fend:
  - D3-SDA
  - D3-DA
references:
  - 'PyInstaller archive format (CArchive/PKG) — https://pyinstaller.org/en/stable/advanced-topics.html'
  - 'Python bytecode (dis module / .pyc magic) — https://docs.python.org/3/library/dis.html'
---

# Analyzing Compiled Python Malware

## When to Use

- You have an executable that is actually a frozen Python app (PyInstaller, py2exe, cx_Freeze) and
  need to identify the packer and locate the embedded Python modules.
- You want to extract `.pyc` files for decompilation.

**Do not use** this to run the executable — it identifies and locates the embedded archive
statically. Decompile extracted `.pyc` in an isolated environment.

## Prerequisites

- The frozen executable (read inertly).

## Safety & Handling

- Read bytes statically; treat extracted modules as malicious until reviewed.

## Workflow

### Step 1: Detect the packer

```bash
python scripts/analyst.py detect sample.exe
```

Looks for PyInstaller markers (`pyi-`, `PYZ-00.pyz`, the `MEI` CArchive cookie `MEI\014\013\012\013\016`),
py2exe (`PYTHONSCRIPT`, `zipfile.zip`), and embedded `python3x.dll` references.

### Step 2: Locate the embedded archive

Find the CArchive cookie near the end of the file and report the offset and the embedded Python
version string (`python3.x`).

### Step 3: Extract and decompile

Use a PyInstaller extractor to dump the archive, then decompile `.pyc` (matching the detected
Python version) for source recovery.

### Step 4: Analyze the source

Review the recovered Python for C2, persistence, and capability; map to ATT&CK.

## Validation

- The packer is identified by its specific marker, not just the presence of Python strings.
- The CArchive cookie offset and Python version are reported when PyInstaller is present.
- Findings distinguish the bootloader stub from the embedded Python payload.

## Pitfalls

- `.pyc` version mismatch breaking decompilation — match the interpreter version.
- Stripped/obfuscated bytecode (e.g., custom magic) needing header repair before decompiling.
- Encrypted PYZ archives (PyInstaller `--key`) requiring the key.

## References

- See [`references/api-reference.md`](references/api-reference.md) for the detector.
- PyInstaller archive and Python bytecode references (linked in frontmatter).

Files in this skill

  • LICENSE340 B
  • SKILL.md2.9 KB
  • references/api-reference.md1.1 KB
  • scripts/analyst.py2.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.