A comprehensive Python tool for calculating file hashes (MD5, SHA1, SHA256, SHA512) and checking them against online databases (VirusTotal API) and local hash databases for malware detection.
- Hash Calculation: MD5, SHA1, SHA256, SHA512 with progress bars for large files
- VirusTotal Integration: Query VirusTotal API v3 for malware detection
- Local Hash Databases:
- SQLite database with metadata (malware name, family, source, tags)
- Simple text file database for quick lookups
- Multiple Interfaces: CLI tool, Python API, batch scanning
- Flexible Output: Table, JSON, and simple text formats
- Configuration: INI-based config with API key management
- Sample Database: Pre-populated with known malware hashes (EICAR, WannaCry, NotPetya, etc.)
# Clone the repository
git clone https://github.com/ng-sudo/malware-hash-lookup.git
# Change to the directory
cd malware_hash_lookup
# Install dependencies
pip install -r requirements.txt- Python 3.7+
- requests
- click
- colorama
- tqdm
- python-dotenv
# Get your API key from https://www.virustotal.com/gui/my-apikey
malware_hash_lookup.py config --key YOUR_API_KEYmalware_hash_lookup.py create-db --samplemalware_hash_lookup.py scan suspicious_file.exemalware_hash_lookup.py lookup d41d8cd98f00b204e9800998ecf8427emalware_hash_lookup.py batch ./samples --recursive -e exe -e dllmalware_hash_lookup.py scan malware_sample.exeOutput:
======================================================================
FILE: malware_sample.exe
======================================================================
FILE HASHES:
MD5 : d41d8cd98f00b204e9800998ecf8427e
SHA1 : da39a3ee5e6b4b0d3255bfef95601890afd80709
SHA256 : e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
LOCAL DATABASE MATCHES:
[MATCH] SHA256: EICAR-Test-File (Test) [eicar]
VIRUSTOTAL: MALICIOUS DETECTED
Name: EICAR-Test-File
Detection: 45/72 engines
Top detections:
Kaspersky: EICAR-Test-File (not a virus)
Microsoft: EICAR-Test-File
...
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
THREAT DETECTED: This file matches known malware!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Source: LOCAL_DB
Malware: EICAR-Test-File
Family: Test
Hash: SHA256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
malware_hash_lookup.py lookup 275a021bbfb6489e54d471899f7db9d1663fc695ec2fe2a2c4538aabf651fd0fmalware_hash_lookup.py batch ./samples --recursive --only-matches -e exe -e dll -e sys# Export to text file
malware_hash_lookup.py export hashes.txt --type sha256
# Import from text file
malware_hash_lookup.py import hashes.txt --type sha256 --source mysourcemalware_hash_lookup.py add-hash suspicious_file.exemalware_hash_lookup.py statsThe tool uses config.ini for configuration:
[config]
virustotal_api_key = YOUR_API_KEY_HERE
local_hash_db_path = ./hash_database/malware_hashes.db
hash_algorithms = md5,sha1,sha256
output_format = table
verbose = false
vt_rate_limit = 4- Create account at VirusTotal
- Go to My API Key
- Copy your API key
- Run:
malware_hash_lookup.py config --key YOUR_API_KEY
Rate Limits:
- Free tier: 4 requests/minute
- Premium: Higher limits
from malware_hash_lookup import MalwareHashLookup, HashCalculator, VirusTotalAPI
# Initialize tool
tool = MalwareHashLookup()
# Scan a file
results = tool.scan_file("suspicious.exe")
print(tool.format_results(results))
# Calculate hashes only
calculator = HashCalculator(['md5', 'sha1', 'sha256'])
hashes = calculator.calculate_hashes("file.exe")
print(hashes)
# Direct VirusTotal lookup
vt = VirusTotalAPI("YOUR_API_KEY")
result = vt.get_file_report("sha256_hash_here")
print(f"Malicious: {result.malicious}/{result.total_engines}")
# Use local database
from malware_hash_lookup import LocalHashDatabase
db = LocalHashDatabase("./hash_database/malware_hashes.db")
matches = db.lookup_hash("sha256_hash")CREATE TABLE malware_hashes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
hash_value TEXT NOT NULL,
hash_type TEXT NOT NULL, -- md5, sha1, sha256, sha512
malware_name TEXT,
malware_family TEXT,
source TEXT, -- eicar, virustotal, manual, imported
tags TEXT, -- JSON array
first_seen TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
last_seen TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(hash_value, hash_type)
);Simple format - one hash per line:
d41d8cd98f00b204e9800998ecf8427e
da39a3ee5e6b4b0d3255bfef95601890afd80709
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
The sample database includes hashes for:
- EICAR Test File (standard AV test file)
- WannaCry ransomware
- NotPetya/ExPetr wiper
- Emotet banking trojan
- TrickBot banking trojan
- Mirai IoT botnet
Color-coded table with file info, hashes, and detection results.
Machine-readable format for scripting:
{
"file": "suspicious.exe",
"hashes": {
"md5": "...",
"sha1": "...",
"sha256": "..."
},
"matches": [...],
"virustotal": {...}
}Minimal text output for quick scanning.
0: Clean (no matches found)1: Malware detected (matches found)2: Error occurred
pip install pyinstaller
pyinstaller --onefile malware_hash_lookup.pyThe executable will be in dist/malware_hash_lookup.exe
malware_hash_lookup/
├── malware_hash_lookup.py # Main CLI entry point
├── hash_calculator.py # Hash calculation module
├── virustotal_api.py # VirusTotal API integration
├── local_hash_db.py # Local database modules
├── config.ini # Configuration file
├── requirements.txt # Python dependencies
├── hash_database/ # Local hash databases
│ ├── malware_hashes.db # SQLite database
│ └── malware_hashes.txt # Text file database
└── README.md
- Fork the repository
- Create a feature branch
- Add your changes
- Submit a pull request
MIT License - See LICENSE file for details.
This tool is for educational and authorized security testing purposes only. Always ensure you have proper authorization before scanning files or systems. The sample malware hashes are from publicly known samples and test files.