139,445 - Pentesting SMB
Do you use Hacktricks every day? Did you find the book very useful? Would you like to receive extra help with cybersecurity questions? Would you like to find more and higher quality content on Hacktricks? Support Hacktricks through github sponsors so we can dedicate more time to it and also get access to the Hacktricks private group where you will get the help you need and much more!
If you want to know about my latest modifications/additions or you have any suggestion for HackTricks or PEASS, join the 💬telegram group, or follow me on Twitter 🐦@carlospolopm. If you want to share some tricks with the community you can also submit pull requests to https://github.com/carlospolop/hacktricks that will be reflected in this book and don't forget to give ⭐ on github to motivate me to continue developing this book.
Port 139
NetBIOS stands for Network Basic Input Output System. It is a software protocol that allows applications, PCs, and Desktops on a local area network (LAN) to communicate with network hardware and to transmit data across the network. Software applications that run on a NetBIOS network locate and identify each other via their NetBIOS names. A NetBIOS name is up to 16 characters long and usually, separate from the computer name. Two applications start a NetBIOS session when one (the client) sends a command to “call” another client (the server) over TCP Port 139. (extracted from here)
Port 445
While Port 139 is known technically as ‘NBT over IP’, Port 445 is ‘SMB over IP’. SMB stands for ‘Server Message Blocks’. Server Message Block in modern language is also known as Common Internet File System. The system operates as an application-layer network protocol primarily used for offering shared access to files, printers, serial ports, and other sorts of communications between nodes on a network.
For instance, on Windows, SMB can run directly over TCP/IP without the need for NetBIOS over TCP/IP. This will use, as you point out, port 445. On other systems, you’ll find services and applications using port 139. This means that SMB is running with NetBIOS over TCP/IP. (extracted from here)
IPC$ share
From book Network Security Assessment 3rd edition
With an anonymous null session you can access the IPC$ share and interact with services exposed via named pipes. The enum4linux utility within Kali Linux is particularly useful; with it, you can obtain the following:
Operating system information
Details of the parent domain
A list of local users and groups
Details of available SMB shares
The effective system security policy
What is NTLM
If you don't know what is NTLM or you want to know how it works and how to abuse it, you will find very insteresting this page about NTLM where is explained how this protocol works and how you can take advantage of it.
Enumeration
Scan a network searching for hosts:
SMB server version
To look for possible exploits to the SMB version it important to know which version is being used. If this information does not appear in other used tools, you can:
Use the MSF auxiliary module _auxiliary/scanner/smb/smb_version
**_Or this script**:
Search exploit
Possible Credentials
Username(s)
Common passwords
(blank)
(blank)
guest
(blank)
Administrator, admin
(blank), password, administrator, admin
arcserve
arcserve, backup
tivoli, tmersrvd
tivoli, tmersrvd, admin
backupexec, backup
backupexec, backup, arcada
test, lab, demo
password, test, lab, demo
Obtain information
Enumerating LSARPC and SAMR rpcclient
Pat of this section was extracted from book "Network Security Assesment 3rd Edition"
You can use the Samba rpcclient
utility to interact with RPC endpoints via named pipes. The following lists commands that you can issue to SAMR, LSARPC, and LSARPC-DS interfaces upon establishing a SMB session (often requiring credentials).
Users enumeration
List users:
querydispinfo
andenumdomusers
Get user details:
queryuser <0xrid>
Get user groups:
queryusergroups <0xrid>
GET SID of a user:
lookupnames <username>
Get users aliases:
queryuseraliases [builtin|domain] <sid>
Groups enumeration
List groups:
enumdomgroups
Get group details:
querygroup <0xrid>
Get group members:
querygroupmem <0xrid>
Aliasgroups enumeration
List alias:
enumalsgroups <builtin|domain>
Get members:
queryaliasmem builtin|domain <0xrid>
Domains enumeration
List domains:
enumdomains
Get SID:
lsaquery
Domain info:
querydominfo
More SIDs
Find SIDs by name:
lookupnames <username>
Find more SIDs:
lsaenumsid
RID cycling (check more SIDs):
lookupsids <sid>
Command
Interface
Description
queryuser
SAMR
Retrieve user information
querygroup
Retrieve group information
querydominfo
Retrieve domain information
enumdomusers
Enumerate domain users
enumdomgroups
Enumerate domain groups
createdomuser
Create a domain user
deletedomuser
Delete a domain user
lookupnames
LSARPC
lookupsids
lsaaddacctrights
Add rights to a user account
lsaremoveacctrights
Remove rights from a user account
dsroledominfo
LSARPC-DS
Get primary domain information
dsenumdomtrusts
Enumerate trusted domains within an AD forest
To understand better how the tools samrdump and rpcdump works you should read Pentesting MSRPC.
GUI connection from linux
In the terminal:
xdg-open smb://cascade.htb/
In file browser window (nautilus, thunar, etc)
smb://friendzone.htb/general/
List shared folders
It is always recommended to look if you can access to anything, if you don't have credentials try using null credentials/guest user.
Connect/List a shared folder
Manually enumerate windows shares and connect to them
It may be possible that you are restricted to display any shares of the host machine and when you try to list them it appears as if there aren't any shares to connect to. Thus it might be worth a short to try to manually connect to a share. To enumerate the shares manually you might want to look for responses like NT_STATUS_ACCESS_DENIED and NT_STATUS_BAD_NETWORK_NAME, when using a valid session (e.g. null session or valid credentials). These may indicate whether the share exists and you do not have access to it or the share does not exist at all.
Common share names for windows targets are
C$
D$
ADMIN$
IPC$
PRINT$
FAX$
SYSVOL
NETLOGON
(Common share names from Network Security Assessment 3rd edition)
You can try to connect to them by using the following command
or this script (using a null session)
examples
Mount a shared folder
Download files
Read previous sections to learn how to connect with credentials/Pass-the-Hash.
Commands:
mask: specifies the mask which is used to filter the files within the directory (e.g. "" for all files)
recurse: toggles recursion on (default: off)
prompt: toggles prompting for filenames off (default: on)
mget: copies all files matching the mask from host to client machine
(Information from the manpage of smbclient)
Read Registry
You may be able to read the registry using some discovered credentials. Impacket reg.py
allows you to try:
Local users
Enumerate local users with SID brute-forcing:
With Impacket
:
With Metasploit
:
Note: rpcclient
command lookupsids
only translates a SID to a username but doesn't allow enumeration via brute-forcing.
Authenticate using Kerberos
You can authenticate to kerberos using the tools smbclient and rpcclient:
Execute
crackmapexec
crackmapexec can execute commands abusing any of mmcexec, smbexec, atexec, wmiexec being wmiexec the default method. You can indicate which option you prefer to use with the parameter --exec-method
:
Both options will create a new service (using \pipe\svcctl via SMB) in the victim machine and use it to execute something (psexec will upload an executable file to ADMIN$ share and smbexec will point to cmd.exe/powershell.exe and put in the arguments the payload --file-less technique--). More info about psexec and smbexec. In kali it is located on /usr/share/doc/python3-impacket/examples/
Using parameter-k
you can authenticate against kerberos instead of NTLM
wmiexec/dcomexec
Stealthily execute a command shell without touching the disk or running a new service using DCOM via port 135. In kali it is located on /usr/share/doc/python3-impacket/examples/
Using parameter-k
you can authenticate against kerberos instead of NTLM
Execute commands via the Task Scheduler (using \pipe\atsvc via SMB). In kali it is located on /usr/share/doc/python3-impacket/examples/
Impacket reference
https://www.hackingarticles.in/beginners-guide-to-impacket-tool-kit-part-1/
Bruteforce users credentials
This is not recommended, you could block an account if you exceed the maximum allowed tries
SMB relay attack
This attack uses the Responder toolkit to capture SMB authentication sessions on an internal network, and relays them to a target machine. If the authentication session is successful, it will automatically drop you into a system shell. More information about this attack here.
SMB-Trap
The Windows library URLMon.dll automatically try to authenticaticate to the host when a page tries to access some contect via SMB, for example: img src="\\10.10.10.10\path\image.jpg"
This happens with the funcions:
URLDownloadToFile
URLDownloadToCache
URLOpenStream
URLOpenBlockingStream
Which are used by some browsers and tools (like Skype)
SMBTrap using MitMf
HackTricks Automatic Commands
Last updated