Skip to main content

纯 Python 零依赖 PE 文件结构异常扫描器 | Pure-Python PE structural anomaly scanner

Project description

PE Anomaly · PE 文件结构异常扫描器

纯 Python、零依赖的 PE 文件结构异常检测工具。不依赖签名库,用启发式规则识别加壳、加密段、RWX 权限等安全风险。支持 Linux、macOS、Windows。

A pure-Python, zero-dependency CLI tool to detect structural anomalies in Windows PE files. Uses heuristic rules — not signature databases — to identify packers, encrypted sections, RWX permissions, and other security risks.

Features

  • 9 detection rules covering the most common PE anomalies
  • Zero dependencies — only the Python standard library
  • No signature database — detects unknown/new packers, not just known ones
  • Cross-platform — parses PE format on Linux, macOS, Windows
  • JSON output for integration with scripts and CI pipelines
  • Supports PE32 (x86) and PE32+ (x64) formats

Installation

pip install git+https://github.com/songshiyu777/pe-anomaly.git

Or clone and install:

git clone https://github.com/songshiyu777/pe-anomaly.git
cd pe-anomaly
pip install -e .

Quick Start

# Scan a single file
pe-anomaly scan program.exe

# JSON output for automation
pe-anomaly scan program.exe --json

Example output

$ pe-anomaly scan packed.exe

File   : packed.exe
Summary: PE  10 sections  92,192,768 bytes  x64
Findings (7):
  [HIGH] Virtual section: VSize=21.3 MB, RawSize=0 (.themida)
  [HIGH] High entropy: 7.94 (likely encrypted/compressed) (.boot)
  [MEDIUM] Elevated entropy: 7.12 (possibly packed) (.themida)
  [HIGH] Sparse import table: 3 DLLs, 12 functions
  [HIGH] Entry point in known packer section: .themida
  [MEDIUM] Known packer section name: .themida
  [MEDIUM] Large VSize/RawSize mismatch: VSize=40.1 MB, RawSize=11.2 MB
Risk   : HIGH
$ pe-anomaly scan clean.exe

File   : clean.exe
Summary: PE  4 sections  156,672 bytes  x86
Findings (0):
  No anomalies detected.
Risk   : LOW

Detection Rules

Rule Severity What it catches
virtual-section HIGH Sections with RawSize=0 that expand at runtime (Themida, WinLicense)
high-entropy HIGH Entropy > 7.5 — encrypted/compressed payload
elevated-entropy MEDIUM Entropy 6.8-7.5 — possible packing
writable-executable CRITICAL RWX sections — shellcode injection risk
sparse-imports HIGH < 3 DLLs / < 15 functions — packed with runtime resolution
packer-entry-section HIGH Entry point inside a known packer section
packer-section-name MEDIUM Section named .themida, upx0, etc.
size-mismatch MEDIUM VSize >> RawSize — runtime expansion
tls-callbacks MEDIUM TLS callbacks execute before entry point
entry-in-non-code MEDIUM Entry point not in a code section
nonstandard-section LOW Unusual section names

Python API

from pe_anomaly import PEParser, scan

with PEParser("program.exe") as pe:
    info = pe.parse()

    # Inspect sections
    for s in info.sections:
        print(f"{s.name:<10s}  {s.perms}  entropy={s.entropy:.2f}  "
              f"VSize={s.virtual_size:,}  RawSize={s.raw_size:,}")

    # Run anomaly scanner
    result = scan(info)
    for finding in result.findings:
        print(f"[{finding.severity.name}] {finding.summary}")

    print(f"Risk level: {result.risk_level.name}")

License

MIT — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pe_anomaly-0.1.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pe_anomaly-0.1.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file pe_anomaly-0.1.0.tar.gz.

File metadata

  • Download URL: pe_anomaly-0.1.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for pe_anomaly-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9ba5497b2f42b0d37acbab32d15ab5d87dedc69e0739745e45db68b69f115c69
MD5 c2d0c48168834213522caa2039a19961
BLAKE2b-256 635dd7fa3f8952f35a4aa47199523a32624c2c4429f243b3eef2d8028b59f056

See more details on using hashes here.

File details

Details for the file pe_anomaly-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pe_anomaly-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for pe_anomaly-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8317ed1d83da4534fc19a3bb82f57b0188e17d1aebaf3622b78ac9cdecb874d7
MD5 fc80ab3f54b9b7d58cb765c681ae5b57
BLAKE2b-256 be4b95c721404394b3ed17ce2416d0594f87378d4cf605755007cf357bb083fb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page