首页 > 编程语言 >python杀毒引擎

python杀毒引擎

时间:2024-07-11 17:55:24浏览次数:16  
标签:eicar hash algorithm python 杀毒 引擎 file test md5

import os
import hashlib

malware_signatures_md5 = {
    "eicar_test_file": "44d88612fea8a8f36de82e1278abb02f", 
    "eicar_test_file":'eda588c0ee78b585f645aa42eff1e57a'  ,
    "eicar_test_file":'19dbec50735b5f2a72d4199c4e184960'
    "eicar_test_file":'815b63b8bc28ae052029f8cbdd7098ce'
    "eicar_test_file":'c71091507f731c203b6c93bc91adedb6' 
    "eicar_test_file":'0a456ffff1d3fd522457c187ebcf41e4'
    "eicar_test_file":'1aa4c64363b68622c9426ce96c4186f2' 
    "eicar_test_file":'d214c717a357fe3a455610b197c390aa'
    "eicar_test_file":'dffe6e34209cb19ebe720c457a06edd6'
    "eicar_test_file":'512301c535c88255c9a252fdf70b7a03' 
    "eicar_test_file":'d4a05ada747a970bff6e8c2c59c9b5cd'
    "eicar_test_file":'ad41ec81ab55c17397d3d6039752b0fd' 
    "eicar_test_file":'a57db79f11a8c58d27f706bc1fe94e25'
    "eicar_test_file":'fc14eaf932b76c51ebf490105ba843eb'    
    "eicar_test_file":'2a92da4b5a353ca41de980a49b329e7d'
    "eicar_test_file":'68abd642c33f3d62b7f0f92e20b266aa' 
    "eicar_test_file":'ff5e1f27193ce51eec318714ef038bef'
    "eicar_test_file":'4c36884f0644946344fa847756f4a04e' 
    "eicar_test_file":'2391109c40ccb0f982b86af86cfbc900'
    "eicar_test_file":'915178156c8caa25b548484c97dd19c1'
    "eicar_test_file":'dac5f1e894b500e6e467ae5d43b7ae3e'
    "eicar_test_file":'84c82835a5d21bbcf75a61706d8ab549'
    "eicar_test_file":'db349b97c37d22f5ea1d1841e3c89eb4'
    "eicar_test_file":'1de73f49db23cf5cc6e06f47767f7fda'
    "eicar_test_file":'71b6a493388e7d0b40c83ce903bc6b04'
    "eicar_test_file":'106b537598bce8003d787f4c47e6ecb9'
}

malware_signatures_sha256 = {
    "eicar_test_file": "275a021bbfb648ebfab0f49d40a5f99163e921b2089f0aabf377bab4a8ab6a9e",  # EICAR测试文件的SHA-256哈希
}

def calculate_hash(file_path, algorithm='md5'):
    """计算文件的哈希值"""
    if algorithm == 'md5':
        hash_func = hashlib.md5()
    elif algorithm == 'sha256':
        hash_func = hashlib.sha256()
    else:
        raise ValueError("Unsupported hash algorithm")

    try:
        with open(file_path, "rb") as f:
            for chunk in iter(lambda: f.read(4096), b""):
                hash_func.update(chunk)
        return hash_func.hexdigest()
    except Exception as e:
        print(f"无法读取文件 {file_path}: {e}")
        return None

def scan_directory(directory, algorithm='md5'):
    """扫描目录中的文件并检查是否包含已知恶意软件签名"""
    if algorithm == 'md5':
        signatures = malware_signatures_md5
    elif algorithm == 'sha256':
        signatures = malware_signatures_sha256
    else:
        raise ValueError("Unsupported hash algorithm")

    for root, dirs, files in os.walk(directory):
        for file in files:
            file_path = os.path.join(root, file)
            file_hash = calculate_hash(file_path, algorithm)
            if file_hash:
                if file_hash in signatures.values():
                    print(f"发现恶意软件: {file_path} ({algorithm.upper()}: {file_hash})")
                else:
                    print(f"文件安全: {file_path} ({algorithm.upper()}: {file_hash})")

if __name__ == "__main__":
    directory_to_scan = input("请输入要扫描的目录路径: ")
    hash_algorithm = input("请选择哈希算法(md5/sha256,默认md5):").lower() or 'md5'
    if os.path.isdir(directory_to_scan):
        scan_directory(directory_to_scan, hash_algorithm)
    else:
        print("无效的目录路径")


标签:eicar,hash,algorithm,python,杀毒,引擎,file,test,md5
From: https://blog.csdn.net/vliu612/article/details/140330227

相关文章

  • Python期末考试知识点(史上最全)
     python简介type()不会认为子类是一种父类类型。isinstance()会认为子类是一种父类类型基础语法运算符:算术运算符:多了一个**,代表幂方5**5就是5的5次方还多了一个//整数除法逻辑运算符:and,or,not与,或,非赋值运算符:没有++,–身份运算符:......
  • Python爬虫入门详细教程,通俗易懂,看一遍就会!(含实例)
    一、正确认识Python爬虫爬虫是门很有意思的技术,可以通过爬虫技术获取一些别人拿不到或者需要付费才能拿到的东西,也可以对大量数据进行自动爬取和保存,减少时间和精力去手动做一些累活。【爬虫资料领取方式在文末!!】可以说很多人学编程,不玩点爬虫确实少了很多意思,不管是业余......
  • Python 神器:wxauto 库——解锁微信自动化的无限可能
    ......
  • 【python零基础入门到就业】009、Python中的数据类型(超详细)
    文章目录前言1.基本数据类型1.1整数(int)1.2浮点数(float)1.3字符串(str)1.4布尔值(bool)1.5基本数据类型示意图2.复合数据类型2.1列表(list)2.2元组(tuple)2.3字典(dict)2.4集合(set)2.5复合数据类型示意图3.type()语句的使用方法3.1基本用法3.2动态类型检查3.3与`isi......
  • 8 个 Python 实用脚本,赶紧收藏备用!
    脚本写的好,下班下得早!程序员的日常工作除了编写程序代码,还不可避免地需要处理相关的测试和验证工作。例如,访问某个网站一直不通,需要确定此地址是否可访问,服务器返回什么,进而确定问题在于什么。完成这个任务,如果一味希望采用编译型语言来编写这样的代码,实践中的时间和精力是不......
  • 使用python获取江苏省历年GDP#获取数据#爬虫程序#统计
    我们在搜索页面随机点开拥有数据的页面。www.shujujidi.com观察其所需数据的元素特点,编写代码frombs4importBeautifulSoupimportrequestsheaders={"User-Agent":"Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/1......
  • 用Python和TensorFlow实现图像分类:从零开始
    引言图像分类是计算机视觉中的一个基本任务,它能够让计算机自动识别图像中的物体。在这篇文章中,我们将使用Python和TensorFlow来实现一个简单的图像分类模型,帮助大家了解AI技术的基础知识。准备工作首先,我们需要安装一些必要的Python库。打开命令行终端并运行以下命令:pipin......
  • 【python生成用例报告】unittest、HTMLTestReport、参数化demo
    使用第三方的报告模版,生成报告HTMLTestReport,本质是TestRunner-安装pipinstallHTMLTestReport-使用1.导包unittest、HTMLTestReport2.组装用例(套件,loader)3.使用HTMLTestReport中的runner执行套件4.查看报告目录结构:app.py:importosBase......
  • 代码随想录算法训练营第六天 | Python | LeetCode242.有效的字母异位词、LeetCode349.
    哈希表理论https://programmercarl.com/%E5%93%88%E5%B8%8C%E8%A1%A8%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80.html一般哈希表都是用来快速判断一个元素是否出现集合里。数组/set/mapLeetCode242.有效的字母异位词题目链接:https://leetcode.cn/problems/valid-anagr......
  • 代码随想录算法训练营第四天 | Python | LeetCode24.两两交换链表中的节点、19.删除链
    LeetCode24.两两交换链表中的节点题目链接:https://leetcode.cn/problems/swap-nodes-in-pairs/description/文章/视频链接:https://programmercarl.com/0024.%E4%B8%A4%E4%B8%A4%E4%BA%A4%E6%8D%A2%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E8%8A%82%E7%82%B9.html#%E7%AE%9......