On this page 28 sections
  1. What SMB is
  2. Common SMB ports
  3. NetBIOS
  4. Initial SMB enumeration
  5. SMB protocol versions
  6. SMB security mode
  7. Enumerate shares
  8. Connect to a share
  9. Navigate an SMB share
  10. NULL sessions
  11. Guest access
  12. rpcclient
  13. smbmap
  14. Share permissions
  15. enum4linux
  16. enum4linux-ng
  17. nmblookup
  18. NetExec
  19. Enumerate users with NetExec
  20. Spider SMB shares
  21. Metasploit SMB version
  22. Metasploit SMB shares
  23. Metasploit SMB users
  24. Metasploit SMB login
  25. Workgroups and domains
  26. PsExec belongs separately
  27. Enumeration workflow
  28. Quick reference
01

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.

02

Common SMB ports

Modern SMB normally uses TCP port 445 directly. Older SMB deployments may operate through NetBIOS over TCP port 139.

03

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.

04

Initial SMB enumeration

Start by determining whether SMB is available, identifying the SMB implementation and collecting basic host information.

SMB service detection
nmap -sV -p 139,445 <TARGET>
Default SMB enumeration
nmap -sC -sV -p 139,445 <TARGET>
05

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.

Enumerate SMB protocols
nmap -p 445 --script smb-protocols <TARGET>
06

SMB security mode

Nmap can report SMB security characteristics such as whether message signing is enabled or required.

SMB security mode
nmap -p 445 --script smb-security-mode <TARGET>
SMB2 security mode
nmap -p 445 --script smb2-security-mode <TARGET>
07

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.

List shares without password
smbclient -L //<TARGET>/ -N
List shares with user
smbclient -L //<TARGET>/ -U <USERNAME>
Nmap share enumeration
nmap -p 445 --script smb-enum-shares <TARGET>
08

Connect to a share

Once a share is identified, smbclient can provide an interactive session similar to an FTP client.

Anonymous or guest connection
smbclient //<TARGET>/<SHARE> -N
Authenticated connection
smbclient //<TARGET>/<SHARE> -U <USERNAME>
09

Navigate an SMB share

Inside smbclient, enumerate directories and files and download relevant content for offline analysis.

List files
ls
Change directory
cd <DIRECTORY>
Download file
get <FILE>
10

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.

NULL smbclient session
smbclient -L //<TARGET>/ -N
RPC NULL session
rpcclient -U "" -N <TARGET>
11

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.

12

rpcclient

rpcclient can interact with Microsoft RPC services exposed through SMB and may enumerate users, groups and domain information when permissions allow it.

Connect without credentials
rpcclient -U "" -N <TARGET>
Enumerate domain users
enumdomusers
Enumerate domain groups
enumdomgroups
13

smbmap

smbmap provides a quick overview of available shares and the permissions associated with them.

Guest or anonymous enumeration
smbmap -H <TARGET>
Authenticated enumeration
smbmap -H <TARGET> -u <USERNAME> -p <PASSWORD>
14

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.

Check share permissions
smbmap -H <TARGET> -u <USERNAME> -p <PASSWORD>
15

enum4linux

enum4linux automates several SMB, NetBIOS and RPC enumeration techniques and can gather users, shares, groups and other information from compatible systems.

Basic enumeration
enum4linux <TARGET>
Run broad enumeration
enum4linux -a <TARGET>
16

enum4linux-ng

enum4linux-ng is a newer implementation that provides structured SMB and RPC enumeration and is useful when available in the environment.

Enumerate target
enum4linux-ng -A <TARGET>
17

nmblookup

nmblookup queries NetBIOS names and can help identify legacy Windows or Samba naming information.

NetBIOS lookup
nmblookup -A <TARGET>
18

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.

Basic SMB information
nxc smb <TARGET>
Validate credentials
nxc smb <TARGET> -u <USERNAME> -p <PASSWORD>
Enumerate shares
nxc smb <TARGET> -u <USERNAME> -p <PASSWORD> --shares
19

Enumerate users with NetExec

When the account has sufficient permissions, NetExec can request additional account information from an SMB target.

Enumerate users
nxc smb <TARGET> -u <USERNAME> -p <PASSWORD> --users
20

Spider 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.

Spider a share with NetExec
nxc smb <TARGET> -u <USERNAME> -p <PASSWORD> --spider <SHARE>
21

Metasploit SMB version

Metasploit provides multiple auxiliary scanners for SMB service and host enumeration.

SMB version scanner
use auxiliary/scanner/smb/smb_version
Set target
set RHOSTS <TARGET>
Run scanner
run
22

Metasploit SMB shares

The SMB share enumeration module can identify shares visible to the supplied authentication context.

Share scanner
use auxiliary/scanner/smb/smb_enumshares
23

Metasploit SMB users

Metasploit also provides modules for enumerating SMB users when the target configuration allows it.

User scanner
use auxiliary/scanner/smb/smb_enumusers
24

Metasploit SMB login

The SMB login scanner validates SMB username and password combinations during an authorised credential assessment.

SMB login scanner
use auxiliary/scanner/smb/smb_login
Show options
show options
25

Workgroups 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.

NetExec host information
nxc smb <TARGET>
26

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.

27

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.

Initial enumeration
nmap -sC -sV -p 139,445 <TARGET>
List shares
smbclient -L //<TARGET>/ -N
Broad enum4linux scan
enum4linux -a <TARGET>
NetExec
nxc smb <TARGET>
28

Quick reference

These are the SMB commands worth remembering for service enumeration.

Nmap
nmap -sC -sV -p 139,445 <TARGET>
List shares
smbclient -L //<TARGET>/ -N
Connect share
smbclient //<TARGET>/<SHARE> -N
Permissions
smbmap -H <TARGET>
enum4linux
enum4linux -a <TARGET>
RPC
rpcclient -U "" -N <TARGET>
NetBIOS
nmblookup -A <TARGET>
NetExec
nxc smb <TARGET>
Metasploit version
use auxiliary/scanner/smb/smb_version
Metasploit shares
use auxiliary/scanner/smb/smb_enumshares