Source CTF and HTB Academy

  • Usually on ports 137, 138, 139, 445

Server Message Block (SMB) is a client-server protocol that regulates access to files and entire directories and other network resources such as printers, routers, or interfaces released for the network. With the free software project Samba, there is also a solution that enables the use of SMB in Linux and Unix distributions and thus cross-platform communication via SMB. Access rights are defined by Access Control Lists (ACL). They can be controlled in a fine-grained manner based on attributes such as execute, read, and full access for individual users or user groups. The ACLs are defined based on the shares and therefore do not correspond to the rights assigned locally on the server.


Samba implements the Common Internet File System (CIFS) network protocol. CIFS is a "dialect" of SMB. CIFS is the extension of the SMB protocol. So when we pass SMB commands over Samba to an older NetBIOS service, it usually connects to the Samba server over TCP ports 137, 138, 139, but CIFS uses TCP port 445 only. With version 3, the Samba server gained the ability to be a full member of an Active Directory domain. With version 4, Samba even provides an Active Directory domain controller. It contains several so-called daemons for this purpose - which are Unix background programs. The SMB server daemon (smbd) belonging to Samba provides the first two functionalities, while the NetBIOS message block daemon (nmbd) implements the last two functionalities. The SMB service controls these two background programs.

Default configuration

  • cat /etc/samba/smb.conf | grep -v "#\|\;" see default configuration



The name of the network share.


Workgroup that will appear when clients query.

path = /path/here/

The directory to which user is to be given access.

server string = STRING

The string that will show up when a connection is initiated.

unix password sync = yes

Synchronize the UNIX password with the SMB password?

usershare allow guests = yes

Allow non-authenticated users to access defined shared?

map to guest = bad user

What to do when a user login request doesn't match a valid UNIX user?

browseable = yes

Should this share be shown in the list of available shares?

guest ok = yes

Allow connecting to the service without using a password?

read only = yes

Allow users to read files only?

create mask = 0700

What permissions need to be set for newly created files?

Dangerous Settings


browseable = yes

Allow listing available shares in the current share?

read only = no

Forbid the creation and modification of files?

writable = yes

Allow users to create and modify files?

guest ok = yes

Allow connecting to the service without using a password?

enable privileges = yes

Honor privileges assigned to specific SID?

create mask = 0777

What permissions must be assigned to the newly created files?

directory mask = 0777

What permissions must be assigned to the newly created directories?

logon script =

What script needs to be executed on the user's login?

magic script =

Which script should be executed when the script gets closed?

magic output = script.out

Where the output of the magic script needs to be stored?

Enumerate SMB


  • sudo nmap -sV -sC -p139,445

  • You can use dedicated smb scripts


  • rpcclient -U ""



Server information.


Enumerate all domains that are deployed in the network.


Provides domain, server, and user information of deployed domains.


Enumerates all available shares.

netsharegetinfo <share>

Provides information about a specific share.


Enumerates all domain users.

queryuser <RID>

Provides information about a specific user.

querygroup <RID>

Provides information about a specific group.

  • Sometimes not all commands are available.

  • for i in $(seq 500 1100);do rpcclient -N -U "" -c "queryuser 0x$(printf '%x\n' $i)" | grep "User Name\|user_rid\|group_rid" && echo "";done bruteforce userid

Impacket Samrdump


Enum with Metasploit

  • msfconsole

  • use auxiliary/scanner/smb/smb_version

  • options

  • set RHOSTS IP-ADD (in my example instead of IP-ADD I will put

  • We see the version of Samba so it is something that is going to be worth writing down in our notes.


  • Tool that will help us to list shares or see useful info

  • smbclient -L \\ list shares

  • Connect anonymously smbclient --no-pass \\\\\\SHARE or smbclient //

  • Use -N option in smbclient to suppress the password prompt

  • smbclient -U user \\\\\\SHARENAME




sudo apt install samba-client
sudo apt-get install samba-common-bin
git clone
cd enum4linux-ng
python3 -m venv .
pip3 install -r requirements.txt
source bin/activate


  • enum4linux -a output all sorts of info


  • crackmapexec smb --shares -u '' -p ''

Password attack


  • hydra -L user.list -P password.list smb://

Pass attack with Metasploit

use auxiliary/scanner/smb/smb_login
set user_file user.list
set pass_file password.list
set rhosts

What to try

  • smbclient --no-pass \\\\\\SHARE connect to a share anonymously

  • You might find interesting files this way

  • Check out the win version to see if it is vulnerable to anything (eternal blue for example)

  • We can also try this command smbclient //

  • !<cmd> run local system command even if connected to smb (exanple: !ls)

  • get Download a file from smb

  • smbstatus check connections on smb server


A little guide to SMB Enumeration
Pentesting SMB - Hacktricks

Last updated