import os import hashlib
malware_hashes = [ "d41d8cd98f00b204e9800998ecf8427e", # Example hash "5d41402abc4b2a76b9719d911017c592" # Example hash ]
def calculate_hash(file_path): sha1 = hashlib.sha1() with open(file_path, 'rb') as f: while chunk := f.read(8192): sha1.update(chunk) return sha1.hexdigest()
def scan_directory(directory): for root, _, files in os.walk(directory): for file in files: file_path = os.path.join(root, file) file_hash = calculate_hash(file_path) if file_hash in malware_hashes: print(f"Malware detected: {file_path}") os.remove(file_path) print(f"Malware removed: {file_path}")
scan_directory(".")