> Windows Syscalls
ntoskrnl.exeT1622T1106

NtDebugActiveProcess

Engancha un DebugObject existente a un proceso en ejecución — la cara kernel de DebugActiveProcess.

Prototipo

NTSTATUS NtDebugActiveProcess(
  HANDLE ProcessHandle,
  HANDLE DebugObjectHandle
);

Argumentos

NameTypeDirDescription
ProcessHandleHANDLEinHandle al proceso objetivo. Requiere PROCESS_SUSPEND_RESUME | PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE.
DebugObjectHandleHANDLEinHandle a un DebugObject creado previamente con NtCreateDebugObject (requiere DEBUG_PROCESS_ASSIGN).

IDs de syscalls por versión de Windows

Versión de WindowsID de syscallBuild
Win10 15070xBFwin10-1507
Win10 16070xC2win10-1607
Win10 17030xC5win10-1703
Win10 17090xC6win10-1709
Win10 18030xC7win10-1803
Win10 18090xC8win10-1809
Win10 19030xC9win10-1903
Win10 19090xC9win10-1909
Win10 20040xCDwin10-2004
Win10 20H20xCDwin10-20h2
Win10 21H10xCDwin10-21h1
Win10 21H20xCEwin10-21h2
Win10 22H20xCEwin10-22h2
Win11 21H20xD3win11-21h2
Win11 22H20xD4win11-22h2
Win11 23H20xD4win11-23h2
Win11 24H20xD6win11-24h2
Server 20160xC2winserver-2016
Server 20190xC8winserver-2019
Server 20220xD2winserver-2022
Server 20250xD6winserver-2025

Módulo del kernel

ntoskrnl.exeNtDebugActiveProcess

APIs relacionadas

DebugActiveProcessDebugActiveProcessStopNtCreateDebugObjectNtRemoveProcessDebugNtWaitForDebugEventNtDebugContinueCheckRemoteDebuggerPresent

Stub del syscall

4C 8B D1            mov r10, rcx
B8 D6 00 00 00      mov eax, 0xD6
F6 04 25 08 03 FE 7F 01   test byte ptr [0x7FFE0308], 1
75 03               jne short +3
0F 05               syscall
C3                  ret
CD 2E               int 2Eh
C3                  ret

Notas no documentadas

Llama internamente a DbgkpSetProcessDebugObject, que recorre el EPROCESS, comprueba que DebugPort sea NULL y guarda atómicamente el puntero al DebugObject. Esa comprobación NULL es el origen del límite de un solo depurador: si el proceso ya está siendo depurado (DebugPort != NULL) la llamada devuelve STATUS_PORT_ALREADY_SET (0xC0000048). Pasar un DebugObjectHandle NULL (o sin DEBUG_PROCESS_ASSIGN) da STATUS_INVALID_HANDLE / STATUS_ACCESS_DENIED. Tras el attach, cada acción primaria del objetivo (carga de imagen, creación/salida de hilo, excepción, breakpoint) se encauza vía DbgkSendApiMessage hacia la cola de eventos del DebugObject para que el depurador propietario la consuma.

Uso común por malware

Empareje con NtCreateDebugObject para el anti-attach clásico por auto-depuración: el loader engancha su propio PID a un DebugObject suyo, ocupando el único puerto de depuración permitido. A veces se ve la variante inversa: el malware engancha un depurador lanzado por un EDR o analista a un DebugObject falso (muy raro, requiere PROCESS_ALL_ACCESS sobre el EDR — solo en PoC). Algunos loaders también enganchan a un hijo recién lanzado suspendido a un DebugObject para interceptar las excepciones del stub de desempaquetado del hijo — un depurador userland que conduce su propio esquema de protección.

Oportunidades de detección

El proveedor ETW Microsoft-Windows-Threat-Intelligence levanta un evento al adjuntar un proceso para depuración — EtwTiLogDebugActiveProcess. Defender for Endpoint, Elastic Endpoint Security y CrowdStrike Falcon lo consumen. El pivote de alta fidelidad es `parent_pid == child_pid` (auto-depuración) o `actor_image` fuera de una pequeña lista blanca de depuradores legítimos. Sysmon no registra esto directamente, pero Sysmon ProcessAccess Event 10 con GrantedAccess que incluya PROCESS_SUSPEND_RESUME|PROCESS_CREATE_THREAD desde una imagen no depurador es un proxy razonable cuando ETW no está disponible.

Ejemplos de syscalls directos

cAnti-attach via self-debug

// Plug-in to InstallSelfDebug() — see NtCreateDebugObject example.
// External DebugActiveProcess() against us now returns 0xC0000048.
typedef NTSTATUS(NTAPI* fnNtDebugActiveProcess)(HANDLE, HANDLE);

BOOL OccupyDebugPort(HANDLE hDebugObject) {
    HMODULE n = GetModuleHandleA("ntdll.dll");
    fnNtDebugActiveProcess pAttach = (fnNtDebugActiveProcess)
        GetProcAddress(n, "NtDebugActiveProcess");
    NTSTATUS s = pAttach((HANDLE)-1 /* current process */, hDebugObject);
    return s == 0; // anything else (incl. 0xC0000048) means a debugger beat us to it
}

asmx64 direct stub (Win11 24H2 SSN)

; SSN 0xD6 on win11-24h2 / winserver-2025.
NtDebugActiveProcess PROC
    mov  r10, rcx
    mov  eax, 0D6h
    syscall
    ret
NtDebugActiveProcess ENDP

rustDetect a pre-existing attached debugger

// If NtDebugActiveProcess returns STATUS_PORT_ALREADY_SET (0xC0000048),
// something is already debugging us — anti-debug check.
use std::ffi::c_void;
use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress};

type NtDebugActiveProcess = unsafe extern "system" fn(p: isize, d: isize) -> i32;

pub unsafe fn already_debugged(self_handle: isize, dbg: isize) -> bool {
    let n = GetModuleHandleA(b"ntdll.dll\0".as_ptr());
    let addr = GetProcAddress(n, b"NtDebugActiveProcess\0".as_ptr()).unwrap();
    let f: NtDebugActiveProcess = std::mem::transmute(addr);
    f(self_handle, dbg) as u32 == 0xC000_0048
}

fn _unused(_: *mut c_void) {}

Mapeos MITRE ATT&CK

Last verified: 2026-05-20