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

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  [VB+ASM][Snippet] Low Level Keyboard
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [VB+ASM][Snippet] Low Level Keyboard  (Leído 2,503 veces)
x64core


Desconectado Desconectado

Mensajes: 1.908


Ver Perfil
[VB+ASM][Snippet] Low Level Keyboard
« en: 14 Enero 2012, 02:31 am »

Trabajando a bajo nivel con hooks sobre el teclado, en el proceso no mostrar ninguna clase de msgbox.

module
Código
  1. Option Explicit
  2.  
  3.  
  4. '''''''''''''''''''''''''''''''''''''''''''''''''
  5. ' Autor: RHL
  6. ' Email: opRhl@hotmail.com
  7. ' Not remove this text
  8. '''''''''''''''''''''''''''''''''''''''''''''''''
  9.  
  10.  
  11.  
  12. Private Declare Sub RtlMoveMemory Lib "Kernel32.dll" (Dest As Any, Src As Any, ByVal ln As Long)
  13. Private Declare Function VirtualProtect Lib "kernel32" (lpAddress As Any, ByVal dwSize As Long, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long
  14. Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
  15. Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
  16. Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
  17. Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
  18.  
  19. Private Type KBDLLHOOKSTRUCT
  20.    vkCode              As Long
  21.    scanCode            As Long
  22.    flags               As Long
  23.    time                As Long
  24.    dwExtraInfo         As Long
  25. End Type
  26.  
  27. Private Const MSGTEXT                       As String = "DATA"
  28.    Private Const VKC                       As String = vbCrLf & "VKC: "
  29.    Private Const SCC                       As String = vbCrLf & "SCC: "
  30.    Private Const FLG                       As String = vbCrLf & "FLG: "
  31.    Private Const TME                       As String = vbCrLf & "TME: "
  32.    Private Const EXI                       As String = vbCrLf & "EXI: "
  33. Private Const MSGCaption                    As String = vbCrLf & "DATA"
  34.  
  35. Public Const WH_KEYBOARD_LL                 As Long = 13&
  36. Public Const SH                             As String = "558BEC5352578B450883F8007C3483F800752F8B550C81FA040100007D2781FA000100007522BFXXXXXXXX8B5D10558BEBB9050000008B4500890783C70483C504E2F35DE8XXXXXXXX8B15XXXXXXXXFF7510FF750CFF750852E8XXXXXXXX5F5A5B8BE55DC20C00"
  37. private KB                                  As KBDLLHOOKSTRUCT
  38. private hwHook                              As Long
  39. private runCode(108)                        As Byte
  40.  
  41.  
  42. Public Function Reghook(ByVal hw As Long) As Boolean
  43.    hwHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf FncVBASM, App.hInstance, 0)
  44.    If hwHook Then Reghook = True
  45. End Function
  46.  
  47. Public Sub UnHook(ByVal hw As Long)
  48.    UnhookWindowsHookEx hwHook
  49. End Sub
  50.  
  51. ' shellcode to execute
  52. 'MOV EAX,0B0
  53. 'PUSH EBP
  54. 'MOV EBP,ESP
  55. 'PUSH EBX
  56. 'PUSH EDX
  57. 'PUSH EDI
  58. 'MOV EAX,DWORD PTR SS:[EBP+8]
  59. 'CMP EAX,0
  60. 'JL  $+XX
  61. 'CMP EAX,0
  62. 'JNZ $+XX
  63. 'MOV EDX,DWORD PTR SS:[EBP+C]
  64. 'CMP EDX,104
  65. 'JGE $+XX
  66. 'CMP EDX,100
  67. 'JNZ $+XX
  68. 'MOV EDI,[Struct KB]
  69. 'MOV EBX,DWORD PTR SS:[EBP+10]
  70. 'PUSH EBP
  71. 'MOV EBP,EBX
  72. 'MOV ECX,5
  73. 'MOV EAX,DWORD PTR SS:[EBP]
  74. 'MOV DWORD PTR DS:[EDI],EAX
  75. 'ADD EDI,4
  76. 'ADD EBP,4
  77. 'LOOP $
  78. 'POP EBP
  79. 'CALL MSG
  80. 'MOV EDX,DWORD PTR DS:[hHook]
  81. 'PUSH DWORD PTR SS:[EBP+10]
  82. 'PUSH DWORD PTR SS:[EBP+C]
  83. 'PUSH DWORD PTR SS:[EBP+8]
  84. 'PUSH EDX
  85. 'CALL CallNextHookEx
  86. 'POP EDI
  87. 'POP EDX
  88. 'POP EBX
  89. 'MOV ESP,EBP
  90. 'POP EBP
  91. 'RETN 0C
  92.  
  93. Public Function FncVBASM(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  94.    FncVBASM = &H50
  95.    FncVBASM = FncVBASM + &H60
  96.    FncVBASM = FncVBASM + &H10
  97.    FncVBASM = FncVBASM + &H80
  98.    FncVBASM = FncVBASM + &H40
  99.    FncVBASM = FncVBASM + &H20
  100.    FncVBASM = FncVBASM + &H100
  101.    FncVBASM = FncVBASM - &H200
  102.    FncVBASM = FncVBASM * &H2
  103.    FncVBASM = FncVBASM - &H150
  104.    FncVBASM = FncVBASM + &H20
  105.    FncVBASM = FncVBASM + &H10
  106.    FncVBASM = FncVBASM + &H60
  107.    FncVBASM = FncVBASM + &H10
  108.    FncVBASM = FncVBASM + &H40
  109.    FncVBASM = FncVBASM + &H60
  110.    FncVBASM = FncVBASM + &H10
  111.    FncVBASM = FncVBASM + &H40
  112.    FncVBASM = FncVBASM + &H6
  113.    FncVBASM = FncVBASM + &H79
  114.    FncVBASM = FncVBASM + &H9
  115. End Function
  116.  
  117.  
  118. Public Function PreCodASM(lpFunctASM As Long) As Boolean
  119.    Dim Protect         As Long
  120.    Dim lsize           As Long
  121.    Dim i               As Long
  122.    Dim tLng            As Long
  123.    Dim tSC             As String
  124.    Dim addrMSG         As Long
  125.  
  126.    tSC = SH
  127.    addrMSG = Getaddrf(AddressOf MSG)
  128.    tLng = getAddrCNHE
  129.  
  130.    Mid(tSC, 79, 8) = Hex$(Invertlong(VarPtr(KB)))                                  
  131.    Mid(tSC, 139, 8) = Hex$(Invertlong(addrMSG - &H5 - (lpFunctASM + 73)))
  132.    Mid(tSC, 151, 8) = Hex$(Invertlong(VarPtr(hwHook)))                              
  133.    Mid(tSC, 181, 8) = Hex$(Invertlong(tLng - &H5 - (lpFunctASM + 94)))              
  134.  
  135.    lsize = Len(tSC) \ 2
  136.    For i = 0 To lsize - 1
  137.        runCode(i) = CLng("&H" & Mid$(tSC, i * 2 + 1, 2))
  138.    Next
  139.  
  140.    If 0 = VirtualProtect(ByVal lpFunctASM, lsize + 5, PAGE_EXECUTE_READWRITE, Protect) Then Exit Function
  141.    RtlMoveMemory ByVal lpFunctASM + &H5, ByVal VarPtr(runCode(0)), lsize
  142.    VirtualProtect ByVal lpFunctASM, lsize + 5, Protect, Protect
  143.    PreCodASM = True
  144. End Function
  145.  
  146. Private Function Invertlong(ByVal llng As Long) As Long
  147. Dim t               As Long
  148. t = (((llng And &HFF000000) \ &H1000000) And &HFF&) Or ((llng And &HFF0000) \ &H100&) Or ((llng And &HFF00&) * &H100&) Or ((llng And &H7F&) * &H1000000): If (llng And &H80&) Then t = t Or &H80000000
  149. Invertlong = t
  150. End Function
  151.  
  152. Private Function getAddrCNHE() As Long
  153.    Dim AddrUSER            As Long
  154.  
  155.    AddrUSER = GetModuleHandle("user32.dll")
  156.    getAddrCNHE = GetProcAddress(AddrUSER, "CallNextHookEx")
  157. End Function
  158.  
  159. Public Function Getaddrf(lp As Long) As Long
  160.    Getaddrf = lp
  161. End Function
  162.  
  163. Public Sub MSG()
  164. MsgBox MSGTEXT & VKC & KB.vkCode & SCC & KB.scanCode & FLG & KB.flags & TME & KB.time & EXI & KB.dwExtraInfo, 0, MSGCaption
  165. ' EAX = 0
  166. End Sub
  167.  
  168.  
  169. '''''''''''''''''''''''''''''''''''''''''''''''''
  170. ' Autor: RHL
  171. ' Email: opRhl@hotmail.com
  172. ' Not remove this text
  173. '''''''''''''''''''''''''''''''''''''''''''''''''
  174.  
  175.  

Example:
form
Código
  1.  
  2. '''''''''''''''''''''''''''''''''''''''''''''''''
  3. ' Autor: RHL
  4. ' Email: opRhl@hotmail.com
  5. ' Not remove this text
  6. '''''''''''''''''''''''''''''''''''''''''''''''''
  7. Option Explicit
  8. Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" ( _
  9.                                                                ByVal lpModuleName As String) As Long
  10.  
  11. Private Sub Form_Load()
  12.    If GetModuleHandle("VBA6") Then Debug.Print "only compiled": End
  13.    If Reghook(Me.hWnd) Then MsgBox "Hooked activate!"
  14.    If not PreCodASM(AddressOf FncVBASM) Then debug.print "error": end
  15. End Sub
  16.  
  17. Private Sub Form_Unload(Cancel As Integer)
  18.    UnHook (Me.hWnd)
  19. End Sub
  20.  

con esto me despido de vb...


« Última modificación: 14 Enero 2012, 02:42 am por RHL » En línea

Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: [VB+ASM][Snippet] Low Level Keyboard
« Respuesta #1 en: 16 Enero 2012, 13:10 pm »

Una lástima que te despidas de vb6... bueno, solo un apunte:
Código
  1. If GetModuleHandle("VBA6") Then Debug.Print "only compiled": End
Equivale a:
Código
  1. If App.LogMode = 0 Then Debug.Print "only compiled": End
Y sin APIs :)

No entiendo para que usas un shellcode aquí :P Pero te ha quedado bonito el código, aunque el ASM se podría aligerar.


« Última modificación: 16 Enero 2012, 13:12 pm por Karcrack » En línea

x64core


Desconectado Desconectado

Mensajes: 1.908


Ver Perfil
Re: [VB+ASM][Snippet] Low Level Keyboard
« Respuesta #2 en: 16 Enero 2012, 18:40 pm »

Gracias Karcrack, y si, estoy seguro que me falta que aprender sobre programacion
pero quiero seguir aprendiendolo en un lenguaje con el que quedare :P
y pues me intereso obtener la informacion de los punteros de la estructura nada mas era solo demostracion :)
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
hacer un Irda Keyboard
Electrónica
rieju 1 2,926 Último mensaje 17 Noviembre 2004, 06:41 am
por rieju
ayuda con keyboard de laptop hp
Hardware
dulfo 4 3,390 Último mensaje 7 Agosto 2010, 18:39 pm
por dulfo
ayuda con keyboard de laptop hp
Hardware
wicho_2_99 4 2,151 Último mensaje 28 Octubre 2010, 01:27 am
por Aprendiz-Oscuro
Level-23
Foro Libre
chacKos 0 2,943 Último mensaje 24 Mayo 2011, 16:35 pm
por chacKos
Become a SOC Analyst - Level 1
Tutoriales - Documentación
ehn@ 0 444 Último mensaje 7 Noviembre 2023, 13:42 pm
por ehn@
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines