SMB
Pentesting SMB - TCP Ports 445,139
Theory
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.
#SmbClient
smbclient -U '' -N -L '\\<IP>\'
#NetExec
netexec smb <IP> -u '' -p '' --sharesThe 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
#SmbClient
smbclient -N -L '\\<IP>\'
smbclient -U 'a' -N -L '\\<IP>\'
#NetExec
netexec smb <IP> -u 'a' -p '' --sharesEnumerate
Version & Configuration
Tools like NetExec can be used to enumerate supported protocols, dialects and signing configuration of SMB.
Tools like nmap can be used to enumerate supported protocols, dialects and signing configuration of SMB.
Users
NetExec can be used to enumerate users over SMB.
nmap's smb-enum-users can be used to enumerate users over SMB.
Groups
NetExec can be used to enumerate groups over SMB.
nmap's smb-enum-groups can be used to enumerate groups over SMB.
Shares
SMBClient is a native tool that allow us to interact with SMB shares. We can use it to list shares as follow
NetExec can be used to enumerate SMB shares.
nmap's smb-enum-shares can be used to enumerate groups over SMB.
One useful tool for enumerating SMB shares from a Windows host is net view.
ACLs of Share's File/Folder
The smbcacls program allow us to get ACLs on an NT file or directory on a SMB file shares.
If you see a lot off files and folders, the following commands will make a recursive permissions check on each item
Sessions
NetExec can be used to enumerate active sessions and logged in users over SMB.
nmap's smb-enum-sessions can be used to enumerate active sessions over SMB.
Password Policy
NetExec can be used to enumerate various objects over SMB like the domain password policy.
Execute Remote Commands
SMB-basedVulnerabilities
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.
To exploit, we may use the Worawit PoC on GitHub
first, we have to edit
USERNAMEandPASSWORDat the begening of thezzz_exploit.pyscript.Second, generate a reverse shell
Third, we have to edit , he
smb_pwnfunction inzzz_exploit.py. This is the action taken with the exploit.
Fourth, trigger the exploit
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
USERNAMEandPASSWORDat the begening of thesend_and_execute.pyscriptSecond, generate a reverse shell
Third, trigger the exploit
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.
To exploit, we may use the jivoi PoC on GitHub.
First, generate a Python shellcode and utilize it to replace the current one in
ms08-067.py.
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
Exfiltration
Exfiltration Over SMBResources
Last updated
Was this helpful?