> Windows Syscalls
ntoskrnl.exeT1068T1559T1106

NtAlpcSendWaitReceivePort

Envoie un message ALPC sur un port et attend optionnellement une réponse ou le prochain message entrant.

Prototype

NTSTATUS NtAlpcSendWaitReceivePort(
  HANDLE                   PortHandle,
  ULONG                    Flags,
  PPORT_MESSAGE            SendMessage,
  PALPC_MESSAGE_ATTRIBUTES SendMessageAttributes,
  PPORT_MESSAGE            ReceiveMessage,
  PSIZE_T                  BufferLength,
  PALPC_MESSAGE_ATTRIBUTES ReceiveMessageAttributes,
  PLARGE_INTEGER           Timeout
);

Arguments

NameTypeDirDescription
PortHandleHANDLEinHandle vers un port ALPC (côté serveur ou client, port de communication ou de connexion).
FlagsULONGinALPC_MSGFLG_* (RELEASE_MESSAGE, SYNC_REQUEST, WAIT_USER_MODE, …) contrôlant la sémantique envoi/réception.
SendMessagePPORT_MESSAGEinMessage sortant optionnel ; NULL pour une réception pure.
SendMessageAttributesPALPC_MESSAGE_ATTRIBUTESinAttributs du message sortant (handle / contexte / vue / sécurité).
ReceiveMessagePPORT_MESSAGEoutReçoit la réponse entrante ou le prochain message en file.
BufferLengthPSIZE_Tin/outEn entrée, taille du buffer ReceiveMessage ; en sortie, taille du message reçu.
ReceiveMessageAttributesPALPC_MESSAGE_ATTRIBUTESin/outReçoit les méta-attributs attachés au message entrant.
TimeoutPLARGE_INTEGERinDélai d'attente optionnel (unités de 100 ns, négatif = relatif). NULL = attente infinie.

IDs de syscalls par version de Windows

Version de WindowsID de syscallBuild
Win10 15070x88win10-1507
Win10 16070x88win10-1607
Win10 17030x89win10-1703
Win10 17090x89win10-1709
Win10 18030x8Awin10-1803
Win10 18090x8Awin10-1809
Win10 19030x8Awin10-1903
Win10 19090x8Awin10-1909
Win10 20040x8Cwin10-2004
Win10 20H20x8Cwin10-20h2
Win10 21H10x8Cwin10-21h1
Win10 21H20x8Cwin10-21h2
Win10 22H20x8Cwin10-22h2
Win11 21H20x8Cwin11-21h2
Win11 22H20x8Cwin11-22h2
Win11 23H20x8Cwin11-23h2
Win11 24H20x8Ewin11-24h2
Server 20160x88winserver-2016
Server 20190x8Awinserver-2019
Server 20220x8Cwinserver-2022
Server 20250x8Ewinserver-2025

Module noyau

ntoskrnl.exeNtAlpcSendWaitReceivePort

APIs liées

NtAlpcConnectPortNtAlpcCreatePortNtAlpcAcceptConnectPortNtAlpcDisconnectPortNtAlpcCancelMessageRpcAsyncCompleteCall

Stub du syscall

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

Notes non documentées

`NtAlpcSendWaitReceivePort` est le cheval de trait d'ALPC : chaque appel RPC via `ncalrpc` finit par une ou plusieurs invocations de ce syscall. Il implémente quatre patterns haut niveau — send seul, receive seul, request/reply (synchrone), reply/wait-next (boucle serveur) — selon Flags et lesquels de SendMessage/ReceiveMessage sont non NULL. Le header `PORT_MESSAGE` est suivi d'un bloc optionnel `ALPC_MESSAGE_ATTRIBUTES` pouvant transporter des handles dupliqués, un contexte de sécurité, ou une vue de section partagée — ce sont précisément ces attributs qui font d'ALPC une cible LPE de choix.

Usage courant par les malwares

Deux patterns d'abus distincts : 1. **Exploitation LPE** : chaque chaîne d'exploit ALPC LPE se termine par un `SendMessage` forgé qui déclenche un chemin de code vulnérable côté serveur. CVE-2018-8440 envoyait un `ALPC_MESSAGE_ATTRIBUTE_HANDLE` falsifié au port ALPC du Task Scheduler ; CVE-2019-1322 (SVCMOVER) abusait services.exe via ALPC ; plusieurs PoC PrintNightmare atteignent l'endpoint ALPC du Print Spooler via ce syscall. 2. **C2 IPC furtif** : certains frameworks red team construisent des canaux implant↔implant au-dessus d'un port ALPC anonyme (créé avec `NtAlpcCreatePort` puis connecté via `NtAlpcConnectPort`) car ALPC est invisible à la télémétrie réseau Sysmon. Faible débit mais suffisant pour du command-and-control.

Opportunités de détection

Détection par appel impraticable — ce syscall feu des millions de fois par heure sur un host actif. Angles utiles : ETW `Microsoft-Windows-Kernel-ALPC` (quand activé) attribue chaque message à un nom de port et PID ; payloads `ALPC_MESSAGE_ATTRIBUTE_HANDLE` volumineux depuis des processus non privilégiés vers des services système sont suspects ; corrélation avec l'ETW `Microsoft-Windows-RPC` (qui se situe *au-dessus* d'ALPC) donne l'UUID d'interface RPC invoquée — un UUID inattendu depuis un binaire non Microsoft est le signal le plus fort. Les bugs ALPC LPE historiques ont tous été chassés post-divulgation en cherchant des attributs de handle pointant sur des objets appartenant à SYSTEM depuis des émetteurs en contexte utilisateur.

Exemples de syscalls directs

asmx64 direct stub (Win11 24H2)

; Direct syscall stub for NtAlpcSendWaitReceivePort (SSN 0x8E on Win11 24H2)
NtAlpcSendWaitReceivePort PROC
    mov  r10, rcx          ; PortHandle
    mov  eax, 8Eh          ; SSN — version-sensitive
    syscall
    ret
NtAlpcSendWaitReceivePort ENDP

cServer receive-reply loop

// Minimal ALPC server pump — receive, dispatch, reply.
#include <windows.h>
#include <winternl.h>

typedef NTSTATUS (NTAPI *pNtAlpcSendWaitReceivePort)(
    HANDLE, ULONG, PVOID, PVOID, PVOID, PSIZE_T, PVOID, PLARGE_INTEGER);

void ServerPump(HANDLE hPort) {
    pNtAlpcSendWaitReceivePort fn = (pNtAlpcSendWaitReceivePort)GetProcAddress(
        GetModuleHandleA("ntdll.dll"), "NtAlpcSendWaitReceivePort");
    BYTE recv[0x1000]; SIZE_T cb;
    BYTE reply[0x1000];
    for (;;) {
        cb = sizeof(recv);
        // Pure receive: SendMessage = NULL.
        if (fn(hPort, 0, NULL, NULL, recv, &cb, NULL, NULL) != 0) break;
        // ... build reply in 'reply' ...
        // Send reply, wait for next request: ALPC_MSGFLG_RELEASE_MESSAGE = 0x10000.
        cb = sizeof(recv);
        fn(hPort, 0x10000, reply, NULL, recv, &cb, NULL, NULL);
    }
}

cClient SYNC_REQUEST (sync RPC)

// Synchronous request/reply on an already-connected ALPC port.
#include <windows.h>
#include <winternl.h>
#define ALPC_MSGFLG_SYNC_REQUEST 0x20000

typedef NTSTATUS (NTAPI *pNtAlpcSendWaitReceivePort)(
    HANDLE, ULONG, PVOID, PVOID, PVOID, PSIZE_T, PVOID, PLARGE_INTEGER);

NTSTATUS Call(HANDLE hPort, PVOID req, SIZE_T reqLen, PVOID rsp, PSIZE_T rspLen) {
    pNtAlpcSendWaitReceivePort fn = (pNtAlpcSendWaitReceivePort)GetProcAddress(
        GetModuleHandleA("ntdll.dll"), "NtAlpcSendWaitReceivePort");
    LARGE_INTEGER to; to.QuadPart = -5LL * 10000000LL; // 5 s
    return fn(hPort, ALPC_MSGFLG_SYNC_REQUEST, req, NULL, rsp, rspLen, NULL, &to);
}

Mappings MITRE ATT&CK

Last verified: 2026-05-20