Foro de elhacker.net

Seguridad Informática => Análisis y Diseño de Malware => Mensaje iniciado por: lucasluks1004 en 25 Agosto 2011, 02:44 am



Título: Insertar codigo dentro de una sección del crypter
Publicado por: lucasluks1004 en 25 Agosto 2011, 02:44 am
Bien como dice el titulo estoy haciendo mi crypter el cual ya es funcional ,,pero me di cuenta (no es gran secreto jaja) q los avs detectan los extra data en el stub como codigo malicisos obviamente el codigo q pego a lo ultimo del stub esta encryptado ,,ahora mi pregunta es como hacer para q ese codigo q meto sea parte del exe osea q este dentro de la ultima sección por ejemplo encotre esto ** algo viejo pero aun no logro hacerlo ,,si alguien me puede dar una mano se lo agredeceria mucho! ,,saludos



** http://foro.elhacker.net/programacion_vb/crear_un_pe_editor_simple-t229389.0.html (http://foro.elhacker.net/programacion_vb/crear_un_pe_editor_simple-t229389.0.html)


Título: Re: Insertar codigo dentro de una sección del crypter
Publicado por: BlackZeroX en 25 Agosto 2011, 02:47 am
.
Debes realinear las secciones del formato PE, de tal manera que dicha estructura incluya los datos finales...

Dulces Lunas!¡.


Título: Re: Insertar codigo dentro de una sección del crypter
Publicado por: lucasluks1004 en 25 Agosto 2011, 02:52 am
BlackZeroX gracias por contestar tan rapidamente !!!,,no me puedes dar un empujon un poquito mayor jaja ,,realmente entiendo lo q me dices pero hacerlo realidad es otra cosa ..


Título: Re: Insertar codigo dentro de una sección del crypter
Publicado por: BlackZeroX en 25 Agosto 2011, 03:00 am
.
Traducelo esta en C (Son solo equivalencias...).

Código
  1.  
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #define ReadBinary "r+b"
  5.  
  6. /* Realing PE function
  7.    Programmer : The Swash
  8.    Thanks to  : Thor, Slek
  9.    Dedicated  : Thor, Psymera, [Zero], Steve10120, Karcrack, Cobein
  10. */
  11.  
  12. int PEFileSize(char * fPath);
  13. int AlingNum(int num, int aling);
  14. char * BytesAling(int number);
  15.  
  16. int main(void)
  17. {
  18.    printf("%i ",RealingPE("C:\\hi.exe"));
  19.    getchar();
  20.  
  21. }
  22.  
  23. int RealingPE(char * FilePath)
  24. {
  25.    int OriginalSize = 0;
  26.    int ActualSize = 0;
  27.    int iEOF = 0, iEOFAlingned = 0, iWrite = 0;
  28.    FILE * lpFile;
  29.    IMAGE_DOS_HEADER IDH;
  30.    IMAGE_NT_HEADERS INH;
  31.    IMAGE_SECTION_HEADER ISH;
  32.  
  33.    OriginalSize = PEFileSize(FilePath);
  34.  
  35.    if (OriginalSize != -1)
  36.    {
  37.                     lpFile = fopen(FilePath, ReadBinary);
  38.                     if (lpFile != NULL)
  39.                     {
  40.                                fseek(lpFile,0,SEEK_END);
  41.                                ActualSize = ftell(lpFile);
  42.                                if (ActualSize - OriginalSize > 0)
  43.                                {
  44.                                               rewind(lpFile);
  45.                                               fread(&IDH, sizeof(IDH), 1, lpFile);
  46.                                               fseek(lpFile, IDH.e_lfanew, SEEK_SET);
  47.                                               fread(&INH, sizeof(INH), 1, lpFile);
  48.                                               fseek(lpFile, IDH.e_lfanew + sizeof(INH) + (sizeof(ISH) * (INH.FileHeader.NumberOfSections-1)), SEEK_SET);
  49.                                               fread(&ISH, sizeof(ISH), 1, lpFile);
  50.                                               iEOF = ActualSize - OriginalSize;
  51.                                               iEOFAlingned = AlingNum(iEOF, INH.OptionalHeader.FileAlignment);
  52.                                               if (ISH.VirtualAddress == INH.OptionalHeader.DataDirectory[2].VirtualAddress)
  53.                                               {
  54.                                                                      ISH.SizeOfRawData += iEOFAlingned;
  55.                                                                      ISH.Misc.VirtualSize += iEOFAlingned;
  56.                                                                      INH.OptionalHeader.SizeOfImage += iEOFAlingned;
  57.                                                                      INH.OptionalHeader.DataDirectory[2].Size += iEOFAlingned;
  58.                                                                      fseek(lpFile, IDH.e_lfanew, SEEK_SET),
  59.                                                                      iWrite = fwrite(&INH, 1, sizeof(INH), lpFile);
  60.                                                                      fseek(lpFile, IDH.e_lfanew + sizeof(INH) + (sizeof(ISH) * (INH.FileHeader.NumberOfSections-1)), SEEK_SET);
  61.                                                                      iWrite = fwrite(&ISH, 1, sizeof(ISH), lpFile);
  62.                                                                      if (iEOFAlingned - iEOF > 0)
  63.                                                                      {
  64.                                                                                       fseek(lpFile, ActualSize, SEEK_SET);
  65.                                                                                       fwrite(BytesAling(iEOFAlingned - iEOF), iEOFAlingned - iEOF, 1, lpFile);
  66.                                                                      }                
  67.                                                                      fclose(lpFile);
  68.                                                                      return 0;
  69.                                               }
  70.                                               else
  71.                                               {
  72.                                                                      ISH.SizeOfRawData += iEOFAlingned;
  73.                                                                      ISH.Misc.VirtualSize += iEOFAlingned;
  74.                                                                      INH.OptionalHeader.SizeOfImage += iEOFAlingned;
  75.                                                                      fseek(lpFile, IDH.e_lfanew, SEEK_SET),
  76.                                                                      iWrite = fwrite(&INH, 1, sizeof(INH), lpFile);
  77.                                                                      fseek(lpFile, IDH.e_lfanew + sizeof(INH) + (sizeof(ISH) * (INH.FileHeader.NumberOfSections-1)), SEEK_SET);
  78.                                                                      fwrite(&ISH, sizeof(ISH), 1, lpFile);
  79.                                                                      if (iEOFAlingned - iEOF > 0)
  80.                                                                      {
  81.                                                                                       fseek(lpFile, ActualSize, SEEK_SET);
  82.                                                                                       fwrite(BytesAling(iEOFAlingned - iEOF), iEOFAlingned - iEOF, 1, lpFile);
  83.                                                                      }                                                                                      
  84.                                                                      fclose(lpFile);
  85.                                                                      return 0;
  86.                                               }
  87.  
  88.                                }
  89.                                else
  90.                                {
  91.                                    return 1;
  92.                                }
  93.                     }
  94.                     else
  95.                     {
  96.                         return -1;
  97.                     }
  98.    }
  99.    else
  100.    {
  101.        return -1;
  102.    }
  103. }
  104.  
  105.  
  106. int PEFileSize(char * fPath)
  107. {
  108.    IMAGE_DOS_HEADER IDH;
  109.    IMAGE_NT_HEADERS INH;
  110.    IMAGE_SECTION_HEADER ISH;
  111.    FILE * lpFile;
  112.    int sTemp = 0, i;
  113.  
  114.    lpFile = fopen(fPath,ReadBinary);
  115.    if (lpFile != NULL)
  116.    {
  117.               fseek(lpFile, 0, SEEK_SET); // Seek to begin of file
  118.               fread(&IDH, sizeof(IDH), 1, lpFile); // Read 64 bytes to IDH struct
  119.               if (IDH.e_magic == IMAGE_DOS_SIGNATURE) // If IDH.e_magic = (MZ)
  120.               {
  121.                               fseek(lpFile, IDH.e_lfanew, SEEK_SET); // Seek in file in begin of NT Headers (PE)
  122.                               fread(&INH, sizeof(INH), 1, lpFile); // Read in structure 248 bytes
  123.                               if (INH.Signature == IMAGE_NT_SIGNATURE) // If INH.Signature = (PE)
  124.                               {
  125.                                                 for (i = 0; i < INH.FileHeader.NumberOfSections; i++) // go for all sections
  126.                                                 {
  127.                                                     fseek(lpFile, IDH.e_lfanew + sizeof(INH) + sizeof(ISH)*i, SEEK_SET); // Seek in actual section
  128.                                                     fread(&ISH, sizeof(ISH), 1, lpFile); // Read section
  129.                                                     sTemp += ISH.SizeOfRawData; // Save sizeofrawdata of section
  130.                                                 }
  131.                                                 sTemp += INH.OptionalHeader.SizeOfHeaders;
  132.                                                 fclose(lpFile);
  133.                                                 return sTemp;
  134.                               }
  135.                               else
  136.                               {
  137.                                   return -1;
  138.                               }
  139.               }
  140.               else
  141.               {
  142.                   return -1;
  143.               }
  144.    }
  145.    else
  146.    {
  147.        return -1;
  148.    }
  149. }
  150.  
  151. int AlingNum(int num, int aling)
  152. {
  153.    if( (num % aling == 0) || (num < aling) )
  154.    {
  155.           return aling;
  156.    }
  157.    else
  158.    {
  159.        return (num / aling) * aling + aling;
  160.    }
  161. }
  162.  
  163. char * BytesAling(int number)
  164. {
  165.     char * sTemp = (char *) malloc(number + 1);
  166.     int i;
  167.     for (i=0; i<number; i++)
  168.     {
  169.         sTemp[i] = '\0';
  170.     }
  171.     return sTemp;
  172. }
  173.  
  174.  

Temibles Lunas!¡.


Título: Re: Insertar codigo dentro de una sección del crypter
Publicado por: lucasluks1004 en 25 Agosto 2011, 03:43 am
gracias de vuelta ,,estoy medio oxidado en C ,pero buen veremos si le puedo sacar provecho!