备份顶目
import os import re import hashlib import datetime from tkinter import * from tkinter import filedialog class VirusTester: def __init__(self, root): self.root = root self.create_widgets() self.vaccines = {} # 初始化疫苗字典 def create_widgets(self): self.create_virus_button = Button(text='创建病毒', command=self.create_virus) self.scan_virus_button = Button(text='扫描病毒', command=self.scan_virus) self.test_virus_button = Button(text='测试病毒 command=self.test_v) self.file_path_var = Entry(width=50) self.monitor_var = StringVar(value='欢迎使用病毒测试工具!为了确保安全,请勿将该工具用于非法用途。') self.monitor_result = Label(textvariable=self.monitor_var) self.create_virus_button.pack(side=LEFT, padx=5, pady=5) self.scan_virus_button.pack(side=LEFT, padx=5, pady=5) Label(text="病毒文件路径:").pack(side=LEFT, padx=5, pady=5) self.file_path_var.pack(side=LEFT, padx=5, pady=5) self.test_virus_button.pack(side=LEFT, padx=5, pady=5) Label(text='状态:').pack(side=LEFT, padx=5, pady=5) self.monitor_result.pack(side=LEFT, padx=5, pady=5) def create_virus(self): virus_name = hashlib.md5(os.urandom(32)).hexdigest() virus_content = f''' import os import hashlib virus_file = __file__ with open(virus_file, "rb") as f: content = f.read() hash = hashlib.md5(content).hexdigest() if hash != "{virus_name}": with open("{virus_file}", "wb") as f: f.write(content) os.system("start .\{virus_file}") ''' with open(f"{virus_name}.py", "w") as f: f.write(virus_content) self.monitor_var.set(f"病毒已创建:{virus_name}.py") def scan_virus(self): python_files = [os.path.join(root, file) for root, _, files os.walk(".") for file in files if file.endswith(".py")] if not python_files: self.monitor_var.set("当前目录下不存在Python文件。") return report = f"病毒扫描报告\n时间{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n" virus_files = [] for file in python_files: with open(file) as f: content = f.read() if "import os" in content and "import hashlib" in content and "__file__" in content and "start .\\" in content: virus_name = re.search(r'if\s+hash\s+!=\s+"(.+?)":', content).group(1) virus_files.append(file) # 收集病毒信息 file_stats = os.stat(file) virus_info = f"\n病毒文件:{file}\n文件大小:{file_stats.st_size} bytes\n最后一次修改时间:{datetime.datetime.fromtimestamp(file_stats.st_mtime).strftime('%Y-%m-%d %H:%M:%S')}\n病毒代码:\n{content}\n哈希值:{virus_name}\n" # 管理员通过分析病毒代码的来源,生成相应的疫苗 if virus_name not in self.vaccines: vaccine = hashlib.md5(virus_name.encode()).hexdigest() self.vaccines[virus_name] = vaccine self.monitor_var.set(f"已生成疫苗:{virus_name} -> {vaccine}") : vaccine = self.vaccines[virus_name] #