April 17, 2024, 2:23 p.m. | Olatunji Ayodele Abidemi

DEV Community dev.to

import hashlib





List of known malware hashes (for demonstration purposes)

known_malware_hashes = {

'md5': ['5f4dcc3b5aa765d61d8327deb882cf99', '...'],

'sha1': ['aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d', '...'],

'sha256': ['9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08', '...']

}


def check_file_hash(file_path):

# Calculate the file's hashes

with open(file_path, 'rb') as file:

file_content = file.read()

md5_hash = hashlib.md5(file_content).hexdigest()

sha1_hash = hashlib.sha1(file_content).hexdigest()

sha256_hash = hashlib.sha256(file_content).hexdigest()



# Check if any of the file's hashes match known malware hashes

if md5_hash in known_malware_hashes['md5'] or \

sha1_hash in known_malware_hashes['sha1'] or \

sha256_hash in known_malware_hashes['sha256']:

return True # The file is infected …

ai antivirus check def demonstration file hashes import javascript list machine machine learning machinelearning malware md5 python security security operation sha1 sha256 solution

Information Security Engineers

@ D. E. Shaw Research | New York City

Technology Security Analyst

@ Halton Region | Oakville, Ontario, Canada

Senior Cyber Security Analyst

@ Valley Water | San Jose, CA

Consultant Sécurité SI Gouvernance - Risques - Conformité H/F - Strasbourg

@ Hifield | Strasbourg, France

Lead Security Specialist

@ KBR, Inc. | USA, Dallas, 8121 Lemmon Ave, Suite 550, Texas

Consultant SOC / CERT H/F

@ Hifield | Sèvres, France