> Windows Syscalls
ntoskrnl.exeT1068T1134.001T1106

NtAlpcImpersonateClientOfPort

Primitiva principal de impersonación de un servidor ALPC — asume el contexto de seguridad del cliente que envió un mensaje.

Prototipo

NTSTATUS NtAlpcImpersonateClientOfPort(
  HANDLE                    PortHandle,
  PPORT_MESSAGE             Message,
  PALPC_IMPERSONATE_INFO    Flags
);

Argumentos

NameTypeDirDescription
PortHandleHANDLEinHandle al puerto de comunicación ALPC del lado servidor devuelto por NtAlpcAcceptConnectPort.
MessagePPORT_MESSAGEinEl PORT_MESSAGE recién recibido del cliente cuyo token debe impersonarse. Builds pre-Win10 aceptaban NULL.
FlagsPALPC_IMPERSONATE_INFOinALPC_IMPERSONATE_INFO con el nivel de impersonación solicitado (anonymous / identify / impersonate / delegate) y banderas de token requeridas. NULL = usa la QoS suministrada en el connect.

IDs de syscalls por versión de Windows

Versión de WindowsID de syscallBuild
Win10 15070x82win10-1507
Win10 16070x82win10-1607
Win10 17030x83win10-1703
Win10 17090x83win10-1709
Win10 18030x84win10-1803
Win10 18090x84win10-1809
Win10 19030x84win10-1903
Win10 19090x84win10-1909
Win10 20040x86win10-2004
Win10 20H20x86win10-20h2
Win10 21H10x86win10-21h1
Win10 21H20x86win10-21h2
Win10 22H20x86win10-22h2
Win11 21H20x86win11-21h2
Win11 22H20x86win11-22h2
Win11 23H20x86win11-23h2
Win11 24H20x88win11-24h2
Server 20160x82winserver-2016
Server 20190x84winserver-2019
Server 20220x86winserver-2022
Server 20250x88winserver-2025

Módulo del kernel

ntoskrnl.exeNtAlpcImpersonateClientOfPort

APIs relacionadas

ImpersonateNamedPipeClientRpcImpersonateClientRpcRevertToSelfRevertToSelfNtAlpcAcceptConnectPortNtAlpcSendWaitReceivePort

Stub del syscall

4C 8B D1            mov r10, rcx
B8 88 00 00 00      mov eax, 0x88
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

`NtAlpcImpersonateClientOfPort` es el análogo ALPC de `ImpersonateNamedPipeClient`: el hilo servidor que acaba de recibir un mensaje asume temporalmente el token primario del cliente, realiza una operación privilegiada por cuenta de él y luego llama a `RevertToSelf`. El nivel de impersonación está acotado por el `SECURITY_QUALITY_OF_SERVICE.ImpersonationLevel` del cliente al hacer connect, pero un servidor que pide *Impersonate* sin override QoS del cliente es el predeterminado para casi todos los servicios de Windows. Toda llamada Win32 / RPC `RpcImpersonateClient` sobre un binding `ncalrpc` termina aquí. Implementación: `AlpcpImpersonateClient` en `ntoskrnl.exe`, que llama a `SeImpersonateClientEx`.

Uso común por malware

**Es el syscall ALPC de mayor valor para escalada de privilegios** — pero, crucialmente, el bug está casi siempre en el *llamante*, no en el syscall mismo. El patrón: un servicio que corre como SYSTEM expone un endpoint ALPC, acepta conexión de un cliente sin privilegios, lo impersona para hacer un access check («¿este usuario puede borrar este archivo?»), y luego **olvida revertir** antes de la acción privilegiada — o hace el check sobre un objeto distinto del que actúa (TOCTOU). CVE-2018-8440 (LPE Task Scheduler ALPC de SandboxEscaper), CVE-2019-1130 (impersonación UMPS), CVE-2020-0668 (LPE Windows Service Tracing) y varias variantes PrintNightmare de Print Spooler dependen todas de este tipo de abuso de impersonación. El malware no suele *invocar* este syscall — envía el mensaje ALPC adecuado en el momento adecuado para engañar a un servicio SYSTEM que sí lo hace.

Oportunidades de detección

Lado *llamante*: el syscall lo invoca prácticamente cada servidor RPC de Windows en cada mensaje — inútil como señal primaria. Lado *exploit*: enfocarse en las consecuencias. Sysmon Event ID 1 (Process Create) con `ParentImage=services.exe` / `spoolsv.exe` / `taskschd.exe`, `User=SYSTEM` pero un token cuyo `IntegrityLevel` no encaja con lo esperado es señal fuerte. Ráfagas ETW `Microsoft-Windows-Security-Auditing` Event ID 4624 (logon) tipo 9 (NewCredentials) desde un service host son sospechosas. Las mitigaciones a nivel kernel (familia `ImpersonateCheck` de Microsoft, `RpcServerRegisterAuthInfoExW` con SIDs restringidos) reducen la exposición más fiablemente que las reglas de detección.

Ejemplos de syscalls directos

asmx64 direct stub (Win11 24H2)

; Direct syscall stub for NtAlpcImpersonateClientOfPort (SSN 0x88 on Win11 24H2)
NtAlpcImpersonateClientOfPort PROC
    mov  r10, rcx          ; PortHandle
    mov  eax, 88h          ; SSN — drifts per build
    syscall
    ret
NtAlpcImpersonateClientOfPort ENDP

cALPC server-side impersonation (the canonical SAFE pattern)

// The bug class lives in callers that forget RevertToSelf, or that
// perform the privileged work on a different object than the one checked.
#include <windows.h>
#include <winternl.h>

typedef struct _ALPC_IMPERSONATE_INFO {
    SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
    ULONG Flags;
    ULONG RequiredImpersonationLevel;
} ALPC_IMPERSONATE_INFO, *PALPC_IMPERSONATE_INFO;

typedef NTSTATUS (NTAPI *pNtAlpcImpersonateClientOfPort)(
    HANDLE, PPORT_MESSAGE, PALPC_IMPERSONATE_INFO);

NTSTATUS DoAsClient(HANDLE hCommPort, PPORT_MESSAGE pMsg,
                    NTSTATUS (*work)(void)) {
    pNtAlpcImpersonateClientOfPort imp = (pNtAlpcImpersonateClientOfPort)
        GetProcAddress(GetModuleHandleA("ntdll.dll"),
                       "NtAlpcImpersonateClientOfPort");
    NTSTATUS st = imp(hCommPort, pMsg, NULL /* default QoS */);
    if (!NT_SUCCESS(st)) return st;
    st = work();              // ALL privileged work happens here
    RevertToSelf();           // NEVER skip — exploit class is forgetting this
    return st;
}

cNote: typical CVE pattern (illustration only, not a working exploit)

// Real ALPC LPE chains (CVE-2018-8440, CVE-2020-0668, PrintNightmare variants)
// trick a privileged service into calling NtAlpcImpersonateClientOfPort against
// an attacker-controlled message, then performing FS / registry I/O AFTER the
// impersonation has either been reverted or never applied to the right object.
// The syscall itself behaves correctly — the vulnerability lives in the service.
// This file documents the syscall only; PoCs belong with the CVE references.

Mapeos MITRE ATT&CK

Last verified: 2026-05-20