1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| import os,sys,psutil import yara import base64 import threading from tkinter import * from tkinter.ttk import * from tkinter import filedialog import tkinter as tk
process_name = ["工具.exe","test.exe"] rules_string = ''' YARA规则 ''' class RedirectText: def __init__(self, text_widget): self.text_widget = text_widget self.text_widget.tag_configure("green", foreground="green") self.text_widget.tag_configure("red", foreground="red")
def write(self, string, color="black"): self.text_widget.insert(tk.END, string, (color,)) self.text_widget.see(tk.END) def flush(self): pass
def start_task(path): thread = threading.Thread(target=filesScan(path)) thread.start()
def kill_process_by_name(process_name): for proc in psutil.process_iter(attrs=['pid', 'name']): try: if proc.info['name'] in process_name: redirected_text.write(f"找到进程: {proc.info['name']}, PID: {proc.info['pid']}\n", color="red") proc.kill() redirected_text.write(f"成功杀死进程: {proc.info['name']}, PID: {proc.info['pid']}\n", color="red") text_box.update() except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): pass
def filesScan(path): sum=0 matchessum=0 matchesfiles=[] path = os.path.normpath(path) rules = yara.compile(source=rules_string) for root, dirs, files in os.walk(path): for file in files: mapath = os.path.join(root, file) sum+=1 try: with open(mapath, 'rb') as fp: redirected_text.write(f'扫描文件: {mapath}\n') text_box.update() matches = rules.match(data=fp.read()) if matches: redirected_text.write(f'警告:{matches}\n', color="red") matchessum+=1 matchesfiles.append([mapath,matches]) except : redirected_text.write(f'访问失败:{file}\n', color="red") redirected_text.write(f'扫描完成\n', color="green") redirected_text.write(f"扫描总文件:{sum};可疑文件:{matchessum}\n", color="green") for file in matchesfiles: redirected_text.write(f'{file[0]} {file[1]} \n', color="red")
def Folderpath(): path = filedialog.askdirectory() E.delete(0, END) E.insert(0, str(path))
def check_command1(entry,button): entry.config(state='disabled') button.config(state='disabled') def check_command2(entry,button): entry.config(state='normal') button.config(state='normal')
def startKill(): text_box.delete(1.0, tk.END) text_box.config(state='normal') kill_process_by_name(process_name) if CheckVar.get(): print("开始C盘扫描......") start_task("C:/") elif os.path.exists(E.get()): print("开始扫描指定路径"+E.get()) start_task(E.get()) else: print("请选择合法的路径!!!") text_box.config(state='disabled')
root = tk.Tk()
screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight() width = 1000 height = 450 root_size = f'{width}x{height}+{round((screen_width - width) / 2)}+{round((screen_height - height) / 2)}' root.geometry(root_size) root.resizable(height=False, width=False) root.title('查杀工具')
temp = open('temp.ico', 'wb+') base64_str = '' imagedata = base64.b64decode(base64_str) temp.write(imagedata) temp.close() root.iconbitmap('temp.ico') os.remove('temp.ico')
Label(root, text='').grid(row=0, column=0, padx=20, pady=30) Label(root, text='查杀路径:').grid(row=0, column=1) E = Entry(root, width=100) E.grid(row=0, column=2, columnspan=4) btn = Button(root, text='选择', command=Folderpath) btn.grid(row=0, column=6) CheckVar = IntVar() C = Checkbutton(root, text="C盘扫描", variable=CheckVar, command=lambda: check_command1(E,btn) if CheckVar.get() else check_command2(E,btn)) C.grid(row=0, column=7) Label(root, text='输出:').grid(row=1, column=1) text_box = Text(root,width=100) text_box.config(state='disabled') text_box.grid(row=1, column=2,rowspan=10)
scrollbar = tk.Scrollbar(root, command=text_box.yview) scrollbar.grid(row=1, column=3, rowspan=10, sticky='ns')
text_box['yscrollcommand'] = scrollbar.set
redirected_text = RedirectText(text_box) sys.stdout = redirected_text btn1 = tk.Button(root, text='开始查杀',width=10,height=18,command=startKill) btn1.grid(row=1, column=6) root.mainloop()
|