備份頂目
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='創(chuàng)建病毒', 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='狀態(tài):').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"病毒已創(chuàng)建:{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] ??????????#