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

 

 


Tema destacado: Introducción a Git (Primera Parte)


+  Foro de elhacker.net
|-+  Seguridad Informática
| |-+  Análisis y Diseño de Malware (Moderador: fary)
| | |-+  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 2,359 veces)
tig0

Desconectado Desconectado

Mensajes: 7


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

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
Funcion reemplazar en Visual basic 6.0 « 1 2 »
Programación Visual Basic
merlin 10 8,398 Último mensaje 4 Junio 2007, 07:57 am
por merlin
Reemplazar funciones
PHP
WHK 9 7,820 Último mensaje 11 Diciembre 2008, 16:49 pm
por SaXo
Reemplazar la función free por una propia.
Programación C/C++
NOB2014 6 2,819 Último mensaje 26 Abril 2016, 02:51 am
por NOB2014
Reemplazar palabras individuales que contienen un punto decimal - Función Regx php
PHP
OssoH 7 7,704 Último mensaje 18 Julio 2022, 16:35 pm
por OssoH
Esta función de Word te permite reemplazar palabras automáticamente
Noticias
El_Andaluz 0 1,818 Último mensaje 24 Enero 2023, 21:56 pm
por El_Andaluz
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines