What is SMB?
SMB (Server Message Block) is how Windows machines share files, printers, and other resources over a network.
When you map a network drive or browse shared folders in Windows, that’s SMB. It’s the backbone of Windows file sharing.
It’s also one of the most attacked protocols in history. From EternalBlue to null sessions to unauthenticated access, SMB has a long track record of security problems.
How It Works
SMB vs NetBIOS
These are two separate protocols that often run together.
| Protocol | Port | Purpose |
|---|---|---|
| SMB | TCP 445 | File sharing (modern, direct) |
| NetBIOS | TCP 139 | Session layer for older LAN communication |
| NetBIOS | UDP 137 | Name resolution |
| NetBIOS | UDP 138 | Datagram service |
Modern SMB works fine without NetBIOS (just port 445). But for backward compatibility, many systems still run both. NetBIOS over TCP (NBT) is the glue that keeps them together.
Always scan both ports 139 and 445. If one is open, the other often is too. Together they give you the full picture.
Finding SMB Hosts
Sweep a subnet for SMB and NetBIOS ports:
nmap -v -p 139,445 -oG smb.txt 10.10.10.0/24This quickly identifies which hosts in the range have SMB/NetBIOS exposed.
NetBIOS Enumeration with nbtscan
nbtscan queries the NetBIOS name service on UDP port 137. It returns NetBIOS names, which are often very descriptive.
sudo nbtscan -r 10.10.10.0/24The names tell you a lot about the host’s role:
| NetBIOS Name | What it likely is |
|---|---|
| DC01 | Domain controller |
| FILESERV | File server |
| SQLPROD | Production SQL server |
| WEBDEV | Development web server |
NetBIOS names are chosen by humans. They often reveal the host’s purpose, which helps you prioritize targets.
NSE Scripts for SMB
Nmap has many SMB scripts in /usr/share/nmap/scripts/smb*:
smb-os-discovery- OS version, computer name, domain, forestsmb-enum-shares- list available sharessmb-enum-users- list user accountssmb-enum-groups- list groupssmb-enum-sessions- active sessionssmb-vuln-*- vulnerability checks
OS Discovery
nmap -v -p 139,445 --script smb-os-discovery 10.10.10.50This returns:
- OS version (Windows 10 Pro, Windows Server 2019, etc.)
- Computer name and NetBIOS name
- Domain and forest name
- FQDN (fully qualified domain name)
- System time
This is richer than basic Nmap OS fingerprinting (-O). It also generates less suspicious traffic because SMB queries blend in with normal Active Directory activity.
Share Enumeration
nmap --script smb-enum-shares 10.10.10.50Lists all shares, their types, and access permissions. Look for shares that allow anonymous read or guest access.
SMB from Windows
On a Windows machine, use net view:
net view \dc01 /allThe /all flag shows administrative shares (the ones ending with $):
| Share | What it is |
|---|---|
| ADMIN$ | Remote admin (maps to C:\Windows) |
| C$ | Default share for the C: drive |
| IPC$ | Inter-Process Communication (used for null sessions) |
| NETLOGON | Logon scripts |
| SYSVOL | Group Policy files |
IPC$ is the gateway for null sessions. If you can connect to IPC$ without credentials, you can often enumerate users, groups, and shares.
NetExec (nxc)
NetExec is the go-to tool for SMB enumeration in modern pentesting. It replaced CrackMapExec and does everything in one tool.
Check if SMB is open
nxc smb 10.10.10.0/24Sweeps the subnet and returns hostnames, domains, OS versions, and SMB signing status in one shot.
Null session enumeration
nxc smb 10.10.10.50 -u '' -p ''Try connecting with empty credentials. If it says [+], null sessions are allowed.
List shares
nxc smb 10.10.10.50 -u '' -p '' --sharesShows all shares and your access level (READ, WRITE, or no access).
Enumerate users
nxc smb 10.10.10.50 -u '' -p '' --usersReturns local user accounts. With valid credentials, also try --groups and --sessions.
With credentials
Once you have a username and password, nxc becomes even more powerful:
nxc smb 10.10.10.50 -u admin -p 'Password123' --shares
nxc smb 10.10.10.50 -u admin -p 'Password123' --users
nxc smb 10.10.10.50 -u admin -p 'Password123' --sessionsnxc is the Swiss Army knife for SMB. One tool for enumeration, credential testing, command execution, and lateral movement. Learn it well.
Null Sessions
A null session is an unauthenticated connection to IPC$. If the server allows it, you can enumerate significant information without any credentials at all.
This was extremely common on Windows 2000 and XP. Modern Windows disables it by default, but misconfigured systems still exist.