On this page 28 sections
- What SMB is
- Common SMB ports
- NetBIOS
- Initial SMB enumeration
- SMB protocol versions
- SMB security mode
- Enumerate shares
- Connect to a share
- Navigate an SMB share
- NULL sessions
- Guest access
- rpcclient
- smbmap
- Share permissions
- enum4linux
- enum4linux-ng
- nmblookup
- NetExec
- Enumerate users with NetExec
- Spider SMB shares
- Metasploit SMB version
- Metasploit SMB shares
- Metasploit SMB users
- Metasploit SMB login
- Workgroups and domains
- PsExec belongs separately
- Enumeration workflow
- Quick reference
What SMB is
SMB, or Server Message Block, is a network protocol commonly used by Windows systems for file sharing, printer sharing and access to network resources. SMB can also expose information about users, shares, domains and system configuration.
Common SMB ports
Modern SMB normally uses TCP port 445 directly. Older SMB deployments may operate through NetBIOS over TCP port 139.
NetBIOS
NetBIOS provides legacy naming and session services used by older Windows networking environments. SMB over NetBIOS is commonly associated with TCP 139 and UDP ports 137 and 138.
Initial SMB enumeration
Start by determining whether SMB is available, identifying the SMB implementation and collecting basic host information.
nmap -sV -p 139,445 <TARGET>nmap -sC -sV -p 139,445 <TARGET>SMB protocol versions
SMB has evolved through multiple versions. SMBv1 is legacy and insecure, while SMBv2 and SMBv3 provide major protocol and security improvements. Protocol-version enumeration is useful when assessing a host.
nmap -p 445 --script smb-protocols <TARGET>SMB security mode
Nmap can report SMB security characteristics such as whether message signing is enabled or required.
nmap -p 445 --script smb-security-mode <TARGET>nmap -p 445 --script smb2-security-mode <TARGET>Enumerate shares
Shares are one of the most important pieces of information exposed by SMB. A share may contain documents, configuration files, scripts, backups or other useful data.
smbclient -L //<TARGET>/ -Nsmbclient -L //<TARGET>/ -U <USERNAME>nmap -p 445 --script smb-enum-shares <TARGET>Connect to a share
Once a share is identified, smbclient can provide an interactive session similar to an FTP client.
smbclient //<TARGET>/<SHARE> -Nsmbclient //<TARGET>/<SHARE> -U <USERNAME>Navigate an SMB share
Inside smbclient, enumerate directories and files and download relevant content for offline analysis.
lscd <DIRECTORY>get <FILE>NULL sessions
A NULL session is an unauthenticated SMB or RPC session created without supplying normal user credentials. Older or misconfigured Windows and Samba systems may expose shares, users or other information through NULL sessions.
smbclient -L //<TARGET>/ -Nrpcclient -U "" -N <TARGET>Guest access
Guest access is different from a classic NULL session. A server may map unauthenticated or invalid users to a guest account and grant that account limited access to specific shares.
rpcclient
rpcclient can interact with Microsoft RPC services exposed through SMB and may enumerate users, groups and domain information when permissions allow it.
rpcclient -U "" -N <TARGET>enumdomusersenumdomgroupssmbmap
smbmap provides a quick overview of available shares and the permissions associated with them.
smbmap -H <TARGET>smbmap -H <TARGET> -u <USERNAME> -p <PASSWORD>Share permissions
During SMB enumeration, distinguish between shares that are inaccessible, readable or writable. Writable shares deserve additional attention because files can potentially be created or modified.
smbmap -H <TARGET> -u <USERNAME> -p <PASSWORD>enum4linux
enum4linux automates several SMB, NetBIOS and RPC enumeration techniques and can gather users, shares, groups and other information from compatible systems.
enum4linux <TARGET>enum4linux -a <TARGET>enum4linux-ng
enum4linux-ng is a newer implementation that provides structured SMB and RPC enumeration and is useful when available in the environment.
enum4linux-ng -A <TARGET>nmblookup
nmblookup queries NetBIOS names and can help identify legacy Windows or Samba naming information.
nmblookup -A <TARGET>NetExec
NetExec, invoked as nxc, can enumerate SMB hosts, validate credentials, list shares and perform other SMB-related tasks. CrackMapExec is the historical tool from which this workflow evolved.
nxc smb <TARGET>nxc smb <TARGET> -u <USERNAME> -p <PASSWORD>nxc smb <TARGET> -u <USERNAME> -p <PASSWORD> --sharesEnumerate users with NetExec
When the account has sufficient permissions, NetExec can request additional account information from an SMB target.
nxc smb <TARGET> -u <USERNAME> -p <PASSWORD> --usersSpider SMB shares
Share spidering recursively searches SMB shares for files and directories. It can help identify configuration files, scripts, backups and credential-related material in large shares.
nxc smb <TARGET> -u <USERNAME> -p <PASSWORD> --spider <SHARE>Metasploit SMB version
Metasploit provides multiple auxiliary scanners for SMB service and host enumeration.
use auxiliary/scanner/smb/smb_versionset RHOSTS <TARGET>runMetasploit SMB shares
The SMB share enumeration module can identify shares visible to the supplied authentication context.
use auxiliary/scanner/smb/smb_enumsharesMetasploit SMB users
Metasploit also provides modules for enumerating SMB users when the target configuration allows it.
use auxiliary/scanner/smb/smb_enumusersMetasploit SMB login
The SMB login scanner validates SMB username and password combinations during an authorised credential assessment.
use auxiliary/scanner/smb/smb_loginshow optionsWorkgroups and domains
SMB hosts may belong to a standalone workgroup or an Active Directory domain. Identifying this context helps interpret usernames, authentication formats and accessible resources.
nxc smb <TARGET>PsExec belongs separately
SMB can also support remote administrative techniques such as PsExec through administrative shares and service creation. That workflow is better treated separately as remote execution and lateral movement rather than basic SMB enumeration.
Enumeration workflow
Identify SMB versions and host information, test anonymous or guest access, enumerate shares and permissions, inspect accessible files, enumerate users and groups through SMB or RPC, then validate known credentials when authorised.
nmap -sC -sV -p 139,445 <TARGET>smbclient -L //<TARGET>/ -Nenum4linux -a <TARGET>nxc smb <TARGET>Quick reference
These are the SMB commands worth remembering for service enumeration.
nmap -sC -sV -p 139,445 <TARGET>smbclient -L //<TARGET>/ -Nsmbclient //<TARGET>/<SHARE> -Nsmbmap -H <TARGET>enum4linux -a <TARGET>rpcclient -U "" -N <TARGET>nmblookup -A <TARGET>nxc smb <TARGET>use auxiliary/scanner/smb/smb_versionuse auxiliary/scanner/smb/smb_enumshares