NtReplyWaitReceivePort
Primitiva LPC del lado servidor: responde atómicamente la petición previa y bloquea para la siguiente.
Prototipo
NTSTATUS NtReplyWaitReceivePort( HANDLE PortHandle, PVOID *PortContext, PPORT_MESSAGE ReplyMessage, PPORT_MESSAGE ReceiveMessage );
Argumentos
| Name | Type | Dir | Description |
|---|---|---|---|
| PortHandle | HANDLE | in | Handle al puerto servidor devuelto por NtCreatePort; el hilo bloquea en la cola de este puerto. |
| PortContext | PVOID* | out | Opcional; recibe el puntero de contexto por cliente almacenado en NtAcceptConnectPort. |
| ReplyMessage | PPORT_MESSAGE | in | Respuesta opcional a enviar para la petición previamente recibida (NULL en la primera llamada / sin respuesta pendiente). |
| ReceiveMessage | PPORT_MESSAGE | out | Búfer asignado por el llamante que recibe el siguiente PORT_MESSAGE entrante; debe ser ≥ MaxMessageLength. |
IDs de syscalls por versión de Windows
| Versión de Windows | ID de syscall | Build |
|---|---|---|
| Win10 1507 | 0xB | win10-1507 |
| Win10 1607 | 0xB | win10-1607 |
| Win10 1703 | 0xB | win10-1703 |
| Win10 1709 | 0xB | win10-1709 |
| Win10 1803 | 0xB | win10-1803 |
| Win10 1809 | 0xB | win10-1809 |
| Win10 1903 | 0xB | win10-1903 |
| Win10 1909 | 0xB | win10-1909 |
| Win10 2004 | 0xB | win10-2004 |
| Win10 20H2 | 0xB | win10-20h2 |
| Win10 21H1 | 0xB | win10-21h1 |
| Win10 21H2 | 0xB | win10-21h2 |
| Win10 22H2 | 0xB | win10-22h2 |
| Win11 21H2 | 0xB | win11-21h2 |
| Win11 22H2 | 0xB | win11-22h2 |
| Win11 23H2 | 0xB | win11-23h2 |
| Win11 24H2 | 0xB | win11-24h2 |
| Server 2016 | 0xB | winserver-2016 |
| Server 2019 | 0xB | winserver-2019 |
| Server 2022 | 0xB | winserver-2022 |
| Server 2025 | 0xB | winserver-2025 |
Módulo del kernel
APIs relacionadas
Stub del syscall
4C 8B D1 mov r10, rcx B8 0B 00 00 00 mov eax, 0x0B 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
NtReplyWaitReceivePort es el *bucle principal del servidor* canónico del LPC heredado: entrega atómicamente la respuesta a la petición tratada en la iteración previa y bloquea en la cola entrante hasta que llegue la siguiente petición. El parámetro de salida `PortContext` proporciona el puntero de contexto por cliente registrado en NtAcceptConnectPort, permitiendo a un hilo servidor multiplexar cualquier número de clientes. El SSN `0x0B` está congelado desde Windows 10 1507 — incluso más bajo que NtRequestWaitReplyPort porque las rutinas originales de dispatch LPC se ubicaron temprano en la tabla.
Uso común por malware
Un atacante invocará NtReplyWaitReceivePort solo tras levantar un servidor LPC custom vía NtCreatePort + NtAcceptConnectPort + NtCompleteConnectPort. Ese patrón es *muy raro* en malware moderno — la IPC práctica para implantes pasa por named pipes, ALPC o secciones compartidas. Interés histórico / académico únicamente: los rootkits user-mode pre-Vista usaban el bucle servidor LPC como etapa C2 intra-host de bajo ruido. Cualquier proceso no del SO bloqueado en NtReplyWaitReceivePort en Windows 10/11 merece investigación.
Oportunidades de detección
Sin proveedor ETW dedicado a LPC heredado; la detección requiere callbacks de kernel o hook de syscall a nivel driver. El enfoque blue-team más sólido es enumerar objetos `Port` vivos bajo `\RPC Control` y `\Sessions\<n>\Windows` (SystemInformer / WinObj) y marcar a los propietarios que no sean csrss, lsass, smss o el subsistema RPC. Un hilo user-mode permanentemente bloqueado en `ntdll!NtReplyWaitReceivePort` sin un binario Microsoft correspondiente en su pila es de alta señal.
Ejemplos de syscalls directos
asmx64 direct stub
; Direct syscall stub for NtReplyWaitReceivePort (SSN 0x0B, stable Win10 1507+)
NtReplyWaitReceivePort PROC
mov r10, rcx ; PortHandle
mov eax, 0Bh ; SSN
syscall
ret
NtReplyWaitReceivePort ENDPcMinimal LPC server loop
// Skeleton of a custom LPC server. Error handling elided for brevity.
#include <windows.h>
#include <winternl.h>
typedef NTSTATUS (NTAPI *pNtReplyWaitReceivePort)(
HANDLE, PVOID*, PVOID /*PPORT_MESSAGE*/, PVOID /*PPORT_MESSAGE*/);
void ServerLoop(HANDLE hServerPort) {
BYTE reqBuf[0x100], replyBuf[0x100];
PVOID ctx = NULL;
BOOL havePendingReply = FALSE;
pNtReplyWaitReceivePort fn = (pNtReplyWaitReceivePort)GetProcAddress(
GetModuleHandleA("ntdll.dll"), "NtReplyWaitReceivePort");
for (;;) {
NTSTATUS s = fn(hServerPort, &ctx,
havePendingReply ? replyBuf : NULL,
reqBuf);
if (s < 0) break;
// ... dispatch on reqBuf, populate replyBuf, set havePendingReply = TRUE ...
havePendingReply = TRUE;
}
}rustFFI declaration via ntapi
// Cargo: ntapi = "0.4"
use ntapi::ntlpcapi::NtReplyWaitReceivePort;
use winapi::shared::ntdef::{HANDLE, NTSTATUS, PVOID};
unsafe fn recv(port: HANDLE, ctx_out: *mut PVOID, reply: *mut u8, recv: *mut u8) -> NTSTATUS {
NtReplyWaitReceivePort(port, ctx_out, reply as *mut _, recv as *mut _)
}Mapeos MITRE ATT&CK
Last verified: 2026-05-20