Ver Mensaje Individual
  #1  
Antiguo 04-01-2021
Avatar de aguml
aguml aguml is offline
Miembro
 
Registrado: may 2013
Posts: 885
Reputación: 11
aguml Va por buen camino
Problemas con NtSetInformationThread

Buenas, estoy intentando aplicar unos trucos antidebug relacionados con esa Api de Windows pero no consigo que me funcionen.
Tengo esto:
Código PHP:
void __fastcall TForm1::QueryNtSetInformationThread(RETURN_DETECTION *Detection)
{
    
HMODULE NtDll;
    
NTSTATUS ntStat;
    
bool check false;
    
int ThreadHideFromDebugger 0x11;

    
Detection->NtSetInformationThread.isDebugger false;

    
NtDll LoadLibrary(L"ntdll.dll");
    
LONG (WINAPI *NtSetInformationThread)(HANDLE ThreadHandleULONG ThreadInformationClassPVOID ThreadInformationULONG ThreadInformationLength);

    *(
FARPROC *)&NtSetInformationThread GetProcAddress(NtDll"NtSetInformationThread");

    
//invalid parameter
    
ntStat NtSetInformationThread((HANDLE)Application->HandleThreadHideFromDebugger, &checksizeof(ULONG));
    if (
ntStat >= 0//it must fail
    
{
        
Detection->NtSetInformationThread.cadena "Detectado con SetInformationThread con parámetro inválido";
        
Detection->NtSetInformationThread.isDebugger true;
        return;
    }

    
//invalid handle
    
ntStat NtSetInformationThread((HANDLE)0xFFFFFThreadHideFromDebugger00);
    if (
ntStat >= 0//it must fail
    
{
        
Detection->NtSetInformationThread.cadena "Detectado con SetInformationThread con HANDLE inválido";
        
Detection->NtSetInformationThread.isDebugger true;
        return;
    }

    
ntStat NtSetInformationThread((HANDLE)Application->HandleThreadHideFromDebugger00);

    if (
ntStat >= 0)
    {
        
Detection->NtSetInformationThread.cadena "SetInformationThread pasado con éxito";
    }
    else
    {
        
Detection->NtSetInformationThread.cadena "Detectado con SetInformationThread con tercer método";
        
Detection->NtSetInformationThread.isDebugger true;
        return;
    }
}
//--------------------------------------------------------------------------- 
Se supone que cuando falla tiene que ocultar el hilo indicado por el Handle a esta Api del debugger con lo que el debugger falla.
La cosa es que por ejemplo en el primero me da la salida 0x80000002 que se supone que es lo que debe dar pero no oculta el hilo o algo hago mal porque el debugger lo sigue depurando sin problema.
En los 3 casos tendría que tener el mismo comportamiento pero en ninguno hace lo que se espera.
Responder Con Cita