This project is licensed under the MIT License. See the LICENSE file for details. Limitation of Liability: The author is not responsible for any damage, legal repercussions caused by the use of this software. By using bintropy, you agree to assume all associated risks and liabilities.
A lightweight static analysis tool designed to calculate and map the Shannon Entropy of binary files using a sliding window approach. This script helps reverse engineers and security researchers quickly identify packed, compressed, or encrypted payloads within executable files without executing them.
In information theory, Shannon Entropy quantifies the amount of randomness or unpredictability within a dataset. For a binary file, if we treat individual byte values (
Where
- Structured Data (Native Code/Text): Contains repetitive opcodes, null padding, and standard string constants. This yields low entropy, typically ranging between 4.5 and 6.0.
- Random Data (Packed/Encrypted Payloads): Destroys predictable byte patterns, resulting in a uniform distribution where every byte value occurs with near-equal frequency. This drives the entropy score up toward its theoretical maximum of 8.0.
- Sliding Window Analysis: Processes files in configurable block sizes (default: 1024 bytes) to retain localized structural fidelity.
- Fast Execution: Uses vectorised
numpyarray operations for high-speed byte frequency computation. - Cyberpunk Visual Dashboard: Generates high-contrast, dark-themed charts plotting entropy spikes against file offsets.
- Suspicious Threshold Mapping: Visually highlights sections exceeding an entropy score of
7.2(the standard benchmark for obfuscation).
Ensure you have Python 3 installed along with the following dependencies:
pip install numpy matplotlib
Run the script from your terminal by passing the path to the target binary as an argument:
python entropy_scanner.py <path_to_binary_file>
Analyzing a standard Linux system binary:
python entropy_scanner.py /usr/bin/ls
Analyzing a suspicious sample or archived payload:
python entropy_scanner.py suspicious_sample.exe
When triaging binaries, this tool can yield false positives by flagging entirely benign applications as highly suspicious. This most frequently occurs when a file contains embedded graphics, icons, or high-resolution images.
- Lossy and Lossless Compression: Modern image formats (such as
.png,.jpeg, or.gif) rely heavily on compression algorithms like DEFLATE or Huffman coding to minimize file size. Compression functions explicitly by removing redundant patterns and maximizing information density per byte. - Uniform Distribution: From an information-theoretic standpoint, perfectly compressed data is indistinguishable from encrypted data or raw cryptographic keys. The frequency distribution of byte values becomes flat and uniform.
- High Entropy Signature: Because the scanner analyzes raw byte frequencies without parsing the file format's structural layout, an embedded asset folder containing complex UI graphics or large images will generate a sustained entropy plateau between 7.5 and 8.0.
Analysis Tip: When evaluating an unknown binary that throws a high-entropy alert, cross-reference the offset locations with a PE/ELF parser (like
pefileorreadelf) to check if the high-entropy block maps to a standard resource section (like.rsrc) rather than code execution sections (like.text).