NtQueryVirtualMemory
Obtiene información sobre las páginas del espacio de direcciones virtuales de un proceso objetivo.
Prototipo
NTSTATUS NtQueryVirtualMemory( HANDLE ProcessHandle, PVOID BaseAddress, MEMORY_INFORMATION_CLASS MemoryInformationClass, PVOID MemoryInformation, SIZE_T MemoryInformationLength, PSIZE_T ReturnLength );
Argumentos
| Name | Type | Dir | Description |
|---|---|---|---|
| ProcessHandle | HANDLE | in | Handle al proceso cuyo espacio VA se consulta. Requiere PROCESS_QUERY_INFORMATION. |
| BaseAddress | PVOID | in | Dirección dentro de la región a consultar. No necesita estar alineada a página. |
| MemoryInformationClass | MEMORY_INFORMATION_CLASS | in | Clase de información a retornar (MemoryBasicInformation, MemoryMappedFilenameInformation, MemoryRegionInformation, MemoryWorkingSetExInformation, ...). |
| MemoryInformation | PVOID | out | Búfer asignado por el llamador que recibe la estructura consultada. |
| MemoryInformationLength | SIZE_T | in | Tamaño del búfer de salida en bytes. |
| ReturnLength | PSIZE_T | out | Opcional. Recibe el número de bytes escritos o requeridos. |
IDs de syscalls por versión de Windows
| Versión de Windows | ID de syscall | Build |
|---|---|---|
| Win10 1507 | 0x23 | win10-1507 |
| Win10 1607 | 0x23 | win10-1607 |
| Win10 1703 | 0x23 | win10-1703 |
| Win10 1709 | 0x23 | win10-1709 |
| Win10 1803 | 0x23 | win10-1803 |
| Win10 1809 | 0x23 | win10-1809 |
| Win10 1903 | 0x23 | win10-1903 |
| Win10 1909 | 0x23 | win10-1909 |
| Win10 2004 | 0x23 | win10-2004 |
| Win10 20H2 | 0x23 | win10-20h2 |
| Win10 21H1 | 0x23 | win10-21h1 |
| Win10 21H2 | 0x23 | win10-21h2 |
| Win10 22H2 | 0x23 | win10-22h2 |
| Win11 21H2 | 0x23 | win11-21h2 |
| Win11 22H2 | 0x23 | win11-22h2 |
| Win11 23H2 | 0x23 | win11-23h2 |
| Win11 24H2 | 0x23 | win11-24h2 |
| Server 2016 | 0x23 | winserver-2016 |
| Server 2019 | 0x23 | winserver-2019 |
| Server 2022 | 0x23 | winserver-2022 |
| Server 2025 | 0x23 | winserver-2025 |
Módulo del kernel
APIs relacionadas
Stub del syscall
4C 8B D1 mov r10, rcx B8 23 00 00 00 mov eax, 0x23 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
NtQueryVirtualMemory mantiene el SSN `0x23` en todos los builds de Windows 10 / 11 / Server. Es el lado kernel de VirtualQuery / VirtualQueryEx pero expone una superficie de información mucho más rica: MemoryBasicInformation (estado, tipo, protección), MemoryMappedFilenameInformation (la imagen / archivo de respaldo como ruta NT), MemoryRegionInformation (info del subárbol VAD completo desde Win10 1803), MemoryImageInformation, MemoryWorkingSetExInformation (bits por página válida / locked / shared / shareable). Cada clase corresponde a una rama distinta de MmQueryVirtualMemory.
Uso común por malware
Herramienta de reconocimiento básica. Enumerar el espacio de direcciones para (a) localizar el mapping de AMSI/ETWTI en el proceso host antes de parchearlos, (b) encontrar encabezados PE limpios de ntdll/kernel32 para unhooking estilo `Perun's Fart`, (c) barrer un proceso remoto buscando regiones RWX o RW asignadas recientemente, (d) confirmar que la sección de una imagen mapeada manualmente no fue desmapeada por un EDR. MemoryMappedFilenameInformation también permite identificar las DLL de EDR cargadas en el host sin tocar la lista de loader del PEB.
Oportunidades de detección
Tasas altas de llamadas son normales — depuradores, profilers e incluso Defender recorren los espacios de direcciones continuamente. Telemetría interesante: consultas cross-process (ProcessHandle != actual) desde binarios no instrumentales, sobre todo seguidas en milisegundos por NtProtectVirtualMemory o NtWriteVirtualMemory sobre el mismo objetivo. El proveedor ETW Threat Intelligence (`Microsoft-Windows-Threat-Intelligence`) emite eventos ProtectVirtualMemory y AllocVirtualMemory para acciones cross-process; correlacionar query-luego-write es una heurística de inyección fuerte.
Ejemplos de syscalls directos
asmx64 direct stub
; Direct syscall stub for NtQueryVirtualMemory (SSN 0x23, all builds)
NtQueryVirtualMemory PROC
mov r10, rcx ; syscall convention
mov eax, 23h ; SSN
syscall
ret
NtQueryVirtualMemory ENDPcAMSI mapping locator
// Walk the host VA space and locate amsi.dll's image mapping using
// MemoryMappedFilenameInformation -> AmsiScanBuffer can then be patched.
#include <windows.h>
#define MemoryMappedFilenameInformation 2
typedef NTSTATUS (NTAPI *pNtQueryVirtualMemory)(
HANDLE, PVOID, ULONG, PVOID, SIZE_T, PSIZE_T);
PVOID FindAmsi(void) {
pNtQueryVirtualMemory NtQueryVirtualMemory =
(pNtQueryVirtualMemory)GetProcAddress(
GetModuleHandleA("ntdll.dll"), "NtQueryVirtualMemory");
BYTE buf[1024];
SIZE_T ret;
for (ULONG_PTR addr = 0x10000; addr < 0x7FFFFFFFFFFF; addr += 0x10000) {
if (NtQueryVirtualMemory((HANDLE)-1, (PVOID)addr,
MemoryMappedFilenameInformation, buf, sizeof buf, &ret) == 0) {
UNICODE_STRING *us = (UNICODE_STRING*)buf;
if (wcsstr(us->Buffer, L"\\amsi.dll"))
return (PVOID)addr;
}
}
return NULL;
}rustMEMORY_BASIC_INFORMATION sweep
// Cargo: windows-sys = "0.59" (Win32_System_Memory, Win32_Foundation)
use windows_sys::Win32::System::Memory::*;
use windows_sys::Win32::Foundation::HANDLE;
// Find RWX regions in a remote process — implant validation, EDR audit, or victim recon.
pub unsafe fn find_rwx(proc_handle: HANDLE) -> Vec<usize> {
let mut out = Vec::new();
let mut addr: usize = 0;
let mut mbi: MEMORY_BASIC_INFORMATION = core::mem::zeroed();
while VirtualQueryEx(proc_handle, addr as _, &mut mbi,
core::mem::size_of_val(&mbi)) != 0 {
if mbi.State == MEM_COMMIT && mbi.Protect == PAGE_EXECUTE_READWRITE {
out.push(mbi.BaseAddress as usize);
}
addr = mbi.BaseAddress as usize + mbi.RegionSize;
}
out
}Mapeos MITRE ATT&CK
Last verified: 2026-05-20