![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
#8
|
||||
|
||||
|
amigo por el momento tengo otros problemas, te cuento.
He creado la dll la cual la inyecto y, si lo hago sobre el mismo programa funciona perfecto y parchea las apis que le indique con valores fijos para cada una (de momento solo parcheo y cuando haga correr bien la dll en cualquier funcion me lio con el tema de hooks). El problema está en si lo intento hacer sobre otra aplicacion ajena a la que hace la inyeccion, la aplicacion inyectora pasa todos los condicionales correctamente hasta crear el hilo pero parece ser que el hilo no se crea porque no me muestra mensajes que tengo puestos ni nada, es como si no existiese la dll en el proceso. El codigo lo he dejado asi: El inyector: Código:
void InjectDll( HANDLE hProcess, AnsiString DLL )
{
ULONG bytesWritten, TID;
HANDLE pThreadStartRoutine,hThread,Parameters;
//Creamos espacio en el proceso
Parameters = VirtualAllocEx(hProcess,NULL,DLL.Length()+1,MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if(Parameters != NULL)
{
WriteProcessMemory(hProcess,Parameters,DLL.c_str(),DLL.Length()+1, &bytesWritten);
if(bytesWritten == (ULONG)DLL.Length()+1)
{
pThreadStartRoutine = GetProcAddress(GetModuleHandle("kernel32.dll"),"LoadLibraryA");
if(pThreadStartRoutine != NULL)
{
hThread = CreateRemoteThread(hProcess,NULL,0,(LPTHREAD_START_ROUTINE)pThreadStartRoutine,Parameters,0,&TID);
if(hThread == NULL)
{
MessageBox(GetCurrentProcess(),"No se pudo crear el hilo.","Error",MB_OK);
}else{
WaitForSingleObject(hThread,INFINITE);
}
}else{
MessageBox(GetCurrentProcess(),"No se pudo obtener la direccion base de LoadLibraryA.","Error",MB_OK);
}
}else{
MessageBox(GetCurrentProcess(),"No se pudo parchear la API.","Error",MB_OK);
}
}else{
MessageBox(GetCurrentProcess(),"No se pudo obtener memoria para inyectar la dll.","Error",MB_OK);
}
}
Código:
#include <windows.h>
#include <UnitFunctions.h>
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
BYTE injertoZwSetInformationThread[] = {0x33,0xC0,0xC2,0x10,0x00};
BYTE injertoZwQueryInformationProcess[] = {0xC7,0x01,0x00,0x00,0x00,0x00,0x33,0xC0,0xC2,0x14,0x00};
ULONG len;
switch(reason)
{
case DLL_PROCESS_ATTACH:
if(lpReserved)
MessageBox(0,"Process has attached to DLL by static loading.","UnitEntryPoint.cpp",MB_OK);
else
//Parcheo ZwSetInformationThread
len = sizeof(injertoZwSetInformationThread);
PatchAPI(injertoZwSetInformationThread,len,"ntdll.dll","NtSetInformationThread");
//Parcheo ZwQueryInformationProcess
len = sizeof(injertoZwQueryInformationProcess);
PatchAPI(injertoZwQueryInformationProcess,len,"ntdll.dll","NtQueryInformationProcess");
MessageBox(0,"Process has attached to DLL by dinamic loading.","UnitEntryPoint.cpp",MB_OK);
break;
case DLL_THREAD_ATTACH:
MessageBox(0,"Thread has attached to DLL.","UnitEntryPoint.cpp",MB_OK);
break;
case DLL_THREAD_DETACH:
MessageBox(0,"Thread has detached from DLL.","UnitEntryPoint.cpp",MB_OK);
break;
case DLL_PROCESS_DETACH:
MessageBox(0,"Process has detached from DLL.","UnitEntryPoint.cpp",MB_OK);
break;
}
return 1;
}
Código:
#pragma hdrstop
#include "UnitFunctions.h"
//---------------------------------------------------------------------------
void PatchAPI(BYTE *injerto,ULONG len,char *nameDLL,char *nameAPI)
{
ULONG Dir;
ULONG nWrite;
ULONG oldProtect;
Dir = GetAddressAPI(nameDLL,nameAPI);
if(Dir == NULL)
{
MessageBox(NULL,"Error al obtener la direccion de NtSetInformationThread.","ERROR",MB_OK);
}else{
if(VirtualProtect((LPVOID)Dir,len,PAGE_WRITECOPY,&oldProtect) == 0)
{
char mensaje[] = "VirtualProtect ha fallado.\nNo se pudo injertar en ";
strcat(mensaje,nameAPI);
MessageBox(NULL,mensaje,"ERROR",MB_OK);
}else{
WriteProcessMemory(GetCurrentProcess(),(LPVOID)Dir,injerto,len,&nWrite);
if(VirtualProtect((LPVOID)Dir,len,oldProtect,&oldProtect) == 0)
{
char mensaje[] = "VirtualProtect ha fallado.\nNo se pudo restaurar los mermisos originales en ";
strcat(mensaje,nameAPI);
MessageBox(NULL,mensaje,"ERROR",MB_OK);
}
}
}
}
//---------------------------------------------------------------------------
ULONG GetAddressAPI(char* nameDLL,char* nameAPI)
{
HMODULE hMod;
hMod = LoadLibrary(nameDLL);
return (ULONG)GetProcAddress(hMod,nameAPI);
}
//---------------------------------------------------------------------------
#pragma package(smart_init)
Código:
#include <Windows.h>
#include <string.h>
#ifndef UnitFunctionsH
#define UnitFunctionsH
//---------------------------------------------------------------------------
/*
#ifdef __cplusplus
extern "C"
{
#endif
//Aqui se definen las funciones externas como en el siguiente ejemplo
__declspec(dllexport) const int GetAnswerOfLife();
#ifdef __cplusplus
}
#endif
*/
ULONG GetAddressAPI(char* nameDLL,char* nameAPI);
void PatchAPI(BYTE *injerto,ULONG len,char *nameDLL,char *nameAPI);
//---------------------------------------------------------------------------
#endif
a la victima la creo con: Código:
CreateProcess(PathFile.c_str(),NULL, NULL, NULL, FALSE, DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS, NULL, NULL, &si, &pi); Código:
AnsiString DLL = "DllHook.dll"; InjectDll(pi.hProcess, DLL); Código:
WaitForSingleObject(hThread,INFINITE); No entiendo donde puede estar el error. |
|
|
Temas Similares
|
||||
| Tema | Autor | Foro | Respuestas | Último mensaje |
| ¿como obtener direcciones de memoria...? | usuario87 | Varios | 3 | 07-08-2011 04:22:44 |
| Obtener direcciones de Imagenes y SWF | Deiv | HTML, Javascript y otros | 5 | 20-07-2007 09:50:31 |
| Problemas con funciones matematicas | jorgegetafe | Varios | 3 | 05-02-2007 17:43:09 |
| Problemas al definir UDF (Funciones en una DLL) | pcicom | Firebird e Interbase | 2 | 21-06-2006 05:49:15 |
| Problemas con Funciones | mauro | Internet | 2 | 04-07-2003 13:10:06 |
|