PDA

Ver la Versión Completa : Truco Antidebug con NtSetInformationThread no funciona


aguml
01-06-2020, 12:36:00
Hola amigos, estoy intentando añadir ese truco a un proyecto mio pero no detecta el debugger nunca. Estoy en Windows 10 x64 y lo tengo así:
bool __fastcall TMyThread2::QueryNtSetInformationThread(void)
{
HMODULE NtDll;
NTSTATUS ntStat;
bool check = false;
bool retval=false;
int ThreadHideFromDebugger = 0x11;

NtDll = LoadLibrary(L"ntdll.dll");
LONG (WINAPI *NtSetInformationThread)(HANDLE ThreadHandle, ULONG ThreadInformationClass, PVOID ThreadInformation, ULONG ThreadInformationLength);
LONG (WINAPI *NtQueryInformationThread)(HANDLE ThreadHandle, ULONG ThreadInformationClass, PVOID ThreadInformation, ULONG ThreadInformationLength, PULONG ReturnLength);
*(FARPROC *)&NtSetInformationThread = GetProcAddress(NtDll, "NtSetInformationThread");
*(FARPROC *)&NtQueryInformationThread = GetProcAddress(NtDll, "NtQueryInformationThread");

//invalid parameter
ntStat = NtSetInformationThread(NULL, ThreadHideFromDebugger, &check, sizeof(ULONG));
if (ntStat >= 0) //it must fail
{
//Detectado con metodo 1
return true;
}

//invalid handle
ntStat = NtSetInformationThread((HANDLE)0xFFFFF, ThreadHideFromDebugger, 0, 0);
if (ntStat >= 0) //it must fail
{
//Detectado con metodo 2
return true;
}

//En x32 si estamos depurandolo se cerrará directamente el proceso
ntStat = NtSetInformationThread(NULL, ThreadHideFromDebugger, 0, 0);

//only available >= VISTA
ntStat = NtQueryInformationThread(NULL, ThreadHideFromDebugger, &check, sizeof(bool), 0);
if (ntStat >= 0)
{
if (!check)
{
//Detectado con metodo 4
return true;
}
else
{
return false;
}
}
return retval;
}

¿Que hago mal?

aguml
01-06-2020, 15:18:47
El original era así:
bool __fastcall TMyThread2::QueryNtSetInformationThread(void)
{
HMODULE NtDll;
NTSTATUS ntStat;
bool check = false;
bool retval=false;
int ThreadHideFromDebugger = 0x11;

NtDll = LoadLibrary(L"ntdll.dll");
LONG (WINAPI *NtSetInformationThread)(HANDLE ThreadHandle, ULONG ThreadInformationClass, PVOID ThreadInformation, ULONG ThreadInformationLength);
LONG (WINAPI *NtQueryInformationThread)(HANDLE ThreadHandle, ULONG ThreadInformationClass, PVOID ThreadInformation, ULONG ThreadInformationLength, PULONG ReturnLength);
*(FARPROC *)&NtSetInformationThread = GetProcAddress(NtDll, "NtSetInformationThread");
*(FARPROC *)&NtQueryInformationThread = GetProcAddress(NtDll, "NtQueryInformationThread");

//invalid parameter
ntStat = NtSetInformationThread(NULL, ThreadHideFromDebugger, &check, sizeof(ULONG));
if (ntStat >= 0) //it must fail
{
//Detectado con metodo 1
return true;
}

//invalid handle
ntStat = NtSetInformationThread((HANDLE)0xFFFFF, ThreadHideFromDebugger, 0, 0);
if (ntStat >= 0) //it must fail
{
//Detectado con metodo 2
return true;
}

//En x32 si estamos depurandolo se cerrará directamente el proceso
ntStat = NtSetInformationThread(NULL, ThreadHideFromDebugger, 0, 0);

if (ntStat >= 0)
{
//only available >= VISTA
ntStat = NtQueryInformationThread(NULL, ThreadHideFromDebugger, &check, sizeof(bool), 0);
if (ntStat >= 0)
{
if (!check)
{
//Detectado con metodo 4
return true;
}
else
{
return false;
}
}
}else{
//Detectado por metodo 3
return true;
}

return retval;
}

Pero siempre me decía que me había detectado con el método 3 aunque no hubiese depurador :confused: