elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
24 Mayo 2012, 17:26  


Tema destacado: [AIO elhacker.NET] Compilación herramientas análisis y desinfección malware

+  Foro de elhacker.net
|-+  Seguridad Informática
| |-+  Análisis y Diseño de Malware (Moderadores: Karcrack, [Zero])
| | |-+  reemplazar funcion en la IAT
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: reemplazar funcion en la IAT  (Leído 447 veces)
tig0

Desconectado Desconectado

Mensajes: 7


Ver Perfil
reemplazar funcion en la IAT
« en: 13 Septiembre 2011, 17:58 »

buenas, estoy teniendo un problemilla interceptando la llamada a una funcion de una dll cuando la cargo de forma dinamica mediante loadlibrary, getprocaddress y todo eso. este es el proceso en el que inyecto mi dll.

 
Código:
#include <windows.h>
#include <iostream>

using namespace std;

typedef int (WINAPI *MSGBX) (HWND,LPCSTR, LPCSTR,UINT);


int main(){

HMODULE hMod = LoadLibrary("User32.dll");
if (!hMod) return 1;

MSGBX mymsgbox = (MSGBX)GetProcAddress(hMod, "MessageBoxA");

if (!mymsgbox) return 1;

cout << "libreria cargada y funcion localizada, esperando el hook..." << endl;

cin.get();

mymsgbox(NULL, "no ok", "!!", 0);             // no interceptada
MessageBox(NULL, "no ok", "!!", 0);           // interceptada

return 0;

}

esto es lo que hace mi dll

Código:
case DLL_PROCESS_ATTACH:

CreateThread(0, 0, (LPTHREAD_START_ROUTINE)begin, 0, 0, 0);

Código:
LPTHREAD_START_ROUTINE begin()
{

HMODULE hMod = GetModuleHandle(0);
orig_box = (MSGBX) InterceptDllCall(hMod, "User32.dll", "MessageBoxA", (DWORD)&mymsgbox);
MessageBox(NULL, "Inyectado", "adasd", 0);

return 0;

}

y aqui la funcion (que no es mia) que sobreescribe la direccion de la funcion en la IAT

Código:
void *InterceptDllCall( HMODULE hModule, char *szDllName, char *szFunctionName, DWORD pNewFunction )
{
PIMAGE_DOS_HEADER pDosHeader;
PIMAGE_NT_HEADERS pNTHeader;
PIMAGE_IMPORT_DESCRIPTOR pImportDesc;
PIMAGE_THUNK_DATA pThunk;
DWORD dwOldProtect;
DWORD dwOldProtect2;
void *pOldFunction;

if( !( pOldFunction = (void*) GetProcAddress( GetModuleHandle( szDllName ), szFunctionName ) ) )
{
MessageBox(NULL, "GetProcAddress failed", "Error", 0);
return( NULL );
}

pDosHeader = ( PIMAGE_DOS_HEADER )hModule;
if( pDosHeader->e_magic != IMAGE_DOS_SIGNATURE )
{
MessageBox(NULL, "dos_header failed", "Error", 0);
return( NULL );
}

pNTHeader = MakePtr( PIMAGE_NT_HEADERS, pDosHeader, pDosHeader->e_lfanew );
if( pNTHeader->Signature != IMAGE_NT_SIGNATURE
|| ( pImportDesc = MakePtr( PIMAGE_IMPORT_DESCRIPTOR, pDosHeader, pNTHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress ) ) == ( PIMAGE_IMPORT_DESCRIPTOR )pNTHeader )
{
MessageBox(NULL, "PIMAGE_NT_HEADERS failed", "Error", 0);
return( NULL );
}

while( pImportDesc->Name )
{
char *szModuleName = MakePtr( char *, pDosHeader, pImportDesc->Name );
if( !stricmp( szModuleName, szDllName ) )
break;
pImportDesc++;
}
if( pImportDesc->Name == NULL )
{
MessageBox(NULL, "pImportDesc failed", "Error", 0);
return( NULL );
}

pThunk = MakePtr( PIMAGE_THUNK_DATA, pDosHeader, pImportDesc->FirstThunk );
while( pThunk->u1.Function )
{
if( pThunk->u1.Function == ( DWORD )pOldFunction )
{
VirtualProtect( ( void * )&pThunk->u1.Function, sizeof( DWORD ), PAGE_EXECUTE_READWRITE, &dwOldProtect );
pThunk->u1.Function = (DWORD)pNewFunction;
VirtualProtect( ( void * )&pThunk->u1.Function, sizeof( DWORD ), dwOldProtect, &dwOldProtect2 );
return( pOldFunction );
}
pThunk++;
}
return( NULL );
}

que deberia hacer para solucionarlo? habia pensado en hookear LoadLibrary y modificar la EAT para que apunte a mi funcion pero eso solo funcionaria si inyecto mi dll justo cuando el programa se ejecuta o bien abriendolo externamente, asi que estoy un poco perdido.

no veo forma de hacerlo sin el trampolin, pero esque no quiero usarlo xD
En línea
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
reemplazar form en vb
Programación General
4e,65,6f 2 421 Último mensaje 2 Marzo 2004, 14:11
por 4e,65,6f
Nuevo en el Sitio <Cadena de caracteres> <funcion strcmp> <funcion toupper>
Programación C/C++
magnavox 6 1,610 Último mensaje 15 Febrero 2006, 01:27
por Kanny
Funcion reemplazar en Visual basic 6.0
Programación Visual Basic
merlin 10 989 Último mensaje 4 Junio 2007, 07:57
por merlin
Skype bloquea función de intercambio de vídeo en función de chat
Noticias
wolfbcn 0 201 Último mensaje 24 Enero 2008, 20:31
por wolfbcn
Reemplazar palabra « 1 2 »
PHP
octavioxd 15 3,984 Último mensaje 17 Marzo 2010, 03:14
por Castg!
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines