8.5 DebuggerPresent

发布时间 2023-09-27 09:21:19作者: lyshark

CheckRemoteDebuggerPresent 也是一个微软提供的反调试函数,该函数可以在本地或者远程进程中使用。函数接收两个参数进程句柄和一个指向布尔值的指针。如果指定的进程正在被调试,则函数会把指向布尔值的指针设为 TRUE,否则设为FALSE。

#include <stdio.h>
#include <windows.h>

// 定义指针
typedef BOOL(WINAPI *CHECK_REMOTE_DEBUG_PROCESS)(HANDLE, PBOOL);

BOOL CheckDebugger()
{
    BOOL bDebug = FALSE;
    CHECK_REMOTE_DEBUG_PROCESS CheckRemoteDebuggerPresent;

    HINSTANCE hModule = GetModuleHandle("kernel32");
    CheckRemoteDebuggerPresent = (CHECK_REMOTE_DEBUG_PROCESS)GetProcAddress(hModule, "CheckRemoteDebuggerPresent");

    HANDLE hProcess = GetCurrentProcess();

    CheckRemoteDebuggerPresent(hProcess, &bDebug);
    return bDebug;
}

int main(int argc, char *argv[])
{
    if (CheckDebugger())
    {
        printf("[-] 进程正在被调试 \n");
    }

    system("pause");
    return 0;
}