Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: mr.blood en 23 Enero 2013, 16:36 pm



Título: [C] Buscando una funcion de la IAT
Publicado por: mr.blood en 23 Enero 2013, 16:36 pm
Pues traigo un programa que busca X funcion en X libreria en su propia Import Address Table. No hay mucha explicacion. Esta bastante chapucero solo queria que pudieran ver un codigo sencillo que haga esto ya que yo no encontre nada estos dias.

Código
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4.  
  5. int main()
  6. {
  7.        const char libreria[]="KERNEL32.dll";
  8.        const char funcion[]="ExitProcess";
  9.        DWORD image_base=(DWORD)GetModuleHandleA(0);
  10.        PIMAGE_DOS_HEADER DOS;
  11.        PIMAGE_NT_HEADERS NT;
  12.        PIMAGE_IMPORT_DESCRIPTOR IT;
  13.        PIMAGE_IMPORT_BY_NAME *IMPORTED_FUNCTIONS;
  14.        PIMAGE_THUNK_DATA Funcion;
  15.        DWORD *IMPORTED_DLL_NAME;
  16.        DWORD *IMPORTED_FUNCTION_NAME;
  17.        unsigned int i=0;
  18.  
  19.        DOS=(PIMAGE_DOS_HEADER)image_base;
  20.        NT=(PIMAGE_NT_HEADERS)(DOS->e_lfanew + image_base);
  21.        IT=(PIMAGE_IMPORT_DESCRIPTOR)(NT->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress + image_base);
  22.        IMPORTED_DLL_NAME=(DWORD *)(IT->Name + image_base);
  23.  
  24.        while( (IT->Name) != 0 )
  25.        {
  26.                IMPORTED_DLL_NAME=(DWORD *)(IT->Name + image_base);
  27.                if(!strcmp((char *)IMPORTED_DLL_NAME, libreria))
  28.                {
  29.                        printf("%s\n", (char *)IMPORTED_DLL_NAME);
  30.                        break;
  31.                }
  32.                IT++;
  33.        }
  34.  
  35.        IMPORTED_FUNCTIONS=(PIMAGE_IMPORT_BY_NAME *)(IT->Characteristics + image_base);
  36.  
  37.        for(i=0;;i++)
  38.        {
  39.                IMPORTED_FUNCTION_NAME=(DWORD *)((*IMPORTED_FUNCTIONS)->Name + image_base);
  40.                if(((*IMPORTED_FUNCTIONS)!=0) && (!strcmp((char *)IMPORTED_FUNCTION_NAME, funcion)))
  41.                {
  42.                        printf("\t%s\n", (char *)IMPORTED_FUNCTION_NAME);
  43.                        break;
  44.                }
  45.                IMPORTED_FUNCTIONS++;
  46.        }
  47.  
  48.        Funcion=(PIMAGE_THUNK_DATA)(IT->FirstThunk + image_base);
  49.        Funcion+=i;
  50.        printf("\t\tDireccion funcion: %p \t Addr en IT: %p\n", *Funcion, Funcion);
  51.        getchar();
  52.        return 0;
  53. }
  54.  

Sa1uDoS


Título: Re: [C] Buscando una funcion de la IAT
Publicado por: ApOkAlizE en 25 Enero 2013, 13:17 pm
ˇGracias por la colaboración mr.blood!