Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Magic Number Analyzer

A Python-based cybersecurity tool that performs static file analysis using file signatures (magic numbers), cryptographic hashing, entropy analysis, and risk assessment techniques commonly used in malware triage and digital forensics.

Features

  • Magic Number Detection
  • File Type Identification
  • Extension Mismatch Detection
  • SHA-256 Hash Generation
  • Entropy Analysis
  • Entropy Classification
  • Risk Assessment Engine
  • Compressed File Awareness (MP3, ZIP, Images, etc.)

How It Works

The tool analyzes a file by:

  1. Reading its binary header.
  2. Identifying the true file type using magic numbers.
  3. Comparing the detected file type with the file extension.
  4. Generating a SHA-256 hash.
  5. Calculating file entropy.
  6. Interpreting entropy based on file type.
  7. Producing a risk assessment.

Example Use Case

An attacker may disguise a malicious executable as:

invoice.pdf

Although the extension suggests a PDF document, the file signature may reveal that the file is actually a Windows executable.

The tool detects such discrepancies and flags them for investigation.

Example Output

File: invoice.pdf

Extension: .pdf

Magic Number: 4D 5A

Detected Type: Windows PE Executable

SHA256: 17035A34337372368D7C40F8278E967626C778650216453E13558D07ACCFC18F

Entropy: 7.96/8.0

Entropy Category: Very High

Analysis: Potentially packed or encrypted executable.

Risk Assessment

Risk Level: High

Reasons:

  • Extension does not match file signature
  • Executable file detected
  • High entropy may indicate packing or encryption

Screenshot

Extension Mismatch Detection

Technologies Used

  • Python 3
  • hashlib
  • pathlib
  • collections
  • math

Skills Demonstrated

  • Digital Forensics
  • Malware Analysis Fundamentals
  • Static File Analysis
  • Cryptographic Hashing
  • File Signature Analysis
  • Risk Assessment
  • Python Programming

Project Structure

magic-number-analyzer/

├── scanner.py

├── signatures.py

├── hashing.py

├── entropy.py

├── risk.py

└── README.md

Future Improvements

  • Batch Directory Scanning
  • YARA Rule Support
  • Report Generation (CSV/PDF)
  • VirusTotal Integration
  • Additional File Signature Coverage

Author

Karthik G

About

A Python-based cybersecurity tool that performs static file analysis using magic numbers, SHA-256 hashing, entropy analysis, and risk assessment to identify suspicious files and extension mismatches.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages