🟨SMB
( TCP 445,139 )
ℹ️ Introduction
SMB functions as a request-response or client-server protocol. The only time that the protocol does not work in a response-request framework is when a client requests an opportunistic lock (oplock) and the server has to break an existing oplock because the current mode is incompatible with the existing oplock. Client computers using SMB connect to a supporting server using NetBIOS over TCP/IP, IPX/SPX, or NetBUI. Once the connection is established, the client computer or program can then open, read/write, and access files similar to the file system on a local computer.
The SMB protocol supports two levels of security. The first is the share level. The server is protected at this level and each share has a password.
Designed to run on top of NetBIOS (Network Basic Input Output System) over TCP/IP using port TCP 139 for identification and UDP 137/138 for file transfer.
Port TCP 445 is supported for using SMB without NetBIOS as a transport (SMB over IP).
Implemented on both Windows and Linux (Samba) OSs.
Windows SMB Versions
CIFS: The old version of SMB, which was included in Microsoft Windows NT 4.0 in 1996.
SMB 1.0 / SMB1: The version used in Windows 2000, Windows XP, Windows Server 2003 and Windows Server 2003 R2.
SMB 2.0 / SMB2: This version used in Windows Vista and Windows Server 2008.
SMB 2.1 / SMB2.1: This version used in Windows 7 and Windows Server 2008 R2.
SMB 3.0 / SMB3: This version used in Windows 8 and Windows Server 2012.
SMB 3.02 / SMB3: This version used in Windows 8.1 and Windows Server 2012 R2.
SMB 3.1: This version used in Windows Server 2016 and Windows 10.
☑️ Checklist
Quick Check
Enumeration
Service Detection
Hostname Enumeration
Shares Enumeration
Check for Null Sessions
Check for CVEs
Manual Inspection
remember to check pcap (packet capture) files for SMB authentication and credentials.
nmap scrips
Linux
Samba, a Linux-based implementation of the SMB/CIFS protocols, provides print and file sharing services for windows clients within an environment. Recent versions also seamlessly can be integrated with Active Directory domains
Samba can be found listening on the usual “NetBIOS” ports:
fix smbclient protocol negotiation failed error
you might face this error on some of the enumeration tools in kali or any other Pentesting distro so i though i should say something about this.
this is a config file for smb service on your hacking machine and might interfere with some other services remember to change the protocol version later.
Access Shares - smbclient
list shares
attempt to connect to smb service abd list smb files (we are after ADMIN$ usually smbclient \\[ip]\[file] (we can open a file or put a file like ftp)
Access Share
`` if you see any files of interest you can type the following
smbmap
installation:
usage:
enum4linux
open /etc/samba/smb.conf and add these under global section [global]
run:
cheat sheet:
nbtscan
if you then see something like ELS-WINXP <20> Unique Registered -- then there is a server or share
Windows
NetBIOS
NetBIOS stands for Network Basic Input Output System. Servers and clients use NetBIOS when viewing network shares on the local area network.
NetBIOS can supply some of the following information when querying a computer:
This block diagram represents the structure of NetBIOS
As you can see the NetBIOS layer sits between the application layer and the IP layer. UDP is used to perform NetBIOS name resolution and to carry other one-to-many datagram-based communications. By using NetBIOS datagrams, a host can send small messages to many other hosts. Heavy traffic, such as a file copy, relies on TCP by using NetBIOS sessions.
When an MS Windows machine browses a network, it uses NetBIOS:
A Windows machine can share a file or a directory on the network; this lets local and remote users access the resource and, possibly, modify it. Starting from Windows Vista, users can choose to share a single file or use the Public directory. When sharing a single file, they can choose local or remote users to share the file with. When using the Public directory, they can choose which local users can access the files on the share, but they can only allow everyone or no one in the network to access the share.
UNC Paths
An authorized user can access shares by using Universal Naming Convention paths (UNC paths).
The format of a UNC path is:
Administrative Shares
There are also some special default administrative shares which are used by system administrators and Windows itself:
• \ComputerName\C$ lets an administrator access a volume on the local machine. Every volume has a share (C$, D$, E$, etc.)
• \ComputerName\admin$ points to the windows installation directory
• \ComputerName\ipc$ is used for inter-process communication. You cannot browse it via Windows Explorer
You can test volume shares and the admin$ share on your computer by entering the following on your Windows Explorer address bar
SMB Login Brute Force
Symlink Directory Traversal
The vulnerability essentially allows an attacker to create a symbolic link to the root (/) partition from a writeable share ultimately allowing for read access to the entire file system outside of the share directory. Although this vulnerability can be exploited using a modified “smbclient,” Metasploit contains a module for exploitation, so we’ll use that for our purposes.
A pre-requisite to this particular vulnerability requires that the Samba server contains a writeable share and that the “widelinks” parameter in the smb.conf file is set with a value of “yes.” We can use the following “smbmap” command to determine shares available to us on a Samba server, in addition to determining whether or not we have read or write permissions to a given share.
If you got error authenticating upgrade impacket
Once we’ve determined a writeable share is available, in this case “tmp,”
we can use Metasploit’s “samba_symlink_traversal” auxiliary module to create the symlink to the root filesystem.
“tmp,”
we can use Metasploit’s “samba_symlink_traversal” auxiliary module to create the symlink to the root filesystem.We can see from the above output, that a new “rootfs” directory has been created within the “tmp” share.
Our next step is to use “smbclient,” as we’ve seen from previous sections, to access the share, change into the “rootfs” directory, and download or upload files to the system where and if possible. We can do this with the following command:
edit /etc/samba/smb.conf
From here, we can simply use smbclient to change into the rootfs directory, and begin post exploitation, downloading/uploading files, etc. using the smbclient “get”
Additionally, another useful command for data exfiltration when conducting post-exploitation tasks using smbclient is the “tar” command. With the tar command, we can create an archive of all files within a current directory, for local perusal later.
The above will create a tar archive of the /etc/ directory on the target system to our local systems’ /tmp directory.
We can then extract, and start enumerating files for sensitive content, passwords, etc.
From Writable Share to RCE
In certain situations where we have a fully patched Samba server, but have a writeable share available to us,we discover that a server we have enumerated is running a patched Samba server, and contains a share named “www,” which appears to be possibly configured to allow administrators to easily update an internal web applicationUsing our previous checks for Samba version and available shares using the Nmap smb-os-discovery NSE script, and smbmap, we have determined OS and Samba Version:
We have also determined any shares that are available to us, as well as seeing that Guest sessions to the shares are possible as well:
This finding is good news for us for a couple of reasons:
Web roots often contain files specific to a web server configuration, and can furthermore be used to obtain credentials to other services, .e.g, MySQL
Being able to write to a web root, is even better depending on the web server configuration; for instance, is PHP installed? Are there any other web server-interpreted languages we can use to our advantage? Can we upload any files to this directory, and how will the web server handle our files? Can we exploit that to obtain remote command execution?
Our first task is to connect to the share, and have a look at its contents, and secondly, we’ll want to determine if the Samba server has any HTTP ports listening, which might be serving the contents of the share.
Again, we’ll use smbclient to connect and have a look at any files within the “www” share.
We can connect to the share with smbclient and execute the Linux “ls” command to list files within the directory.
As the image above explains, the presence of a “.pl” extension indicates that the server is likely configured to process Perl (CGI) programs.
We can download the index.pl file with the “get” command, and take a look at its contents; perhaps we can gain some insight as to its purpose or function
Looking at the file, we can determine that index.pl is a script that simply prints some environment variables regarding the web server configuration, as well as confirming that the server is also interpreting Perl scripts.
We’ve learned a bit more about the server. We now know it’s likely configured to process CGI scripts (Perl), but just to make sure, let’s attempt to browse to the HTTP port (which we should have discovered about this server during information gathering and enumeration). Just to confirm, a quick Nmap scan against the target for open ports, confirms that port 80 is in-fact open:
Let’s point a browser at our target, to confirm that the index.pl script in the “www” share, is being served by the web server.
We also want to make sure that we do in-fact have WRITE permissions to the “www” share; again we’ll do this with smbclient, and the “put” command.
First, let’s create a file locally on your attacker system called “test.pl.” The contents of this file will execute the “id” Linux system command and will display your current UID and GID information when accessed with your browser.
test.pl:
Next, let’s connect to the “www” share with “smbclient” and issue the “put” command, along with our test.pl file:
Next, let’s point a browser to our test.pl file on the target system and confirm that the output of the “id” command is printed to the page. This will confirm for us that we can upload our own Perl scripts to the server and can execute remote operating system commands through our test script
Null Sessions
Null session attacks can be used to enumerate a lot of information. Attackers can steal information about:
Null sessions are remotely exploitable; this means that attackers can use their computers to attack a vulnerable Windows machine. Moreover, this attack can be used to call remote APIs and remote procedure calls. Because of these factors, null session attacks had a huge impact on Windows ecosystems. Nowadays Windows is configured to be immune from this kind of attack. However, legacy hosts can still be vulnerable! A null session attack exploits an authentication vulnerability for Windows Administrative Shares; this lets an attacker connect to a local or remote share without authentication We will go through the enumeration of windows shares and their exploitation by using various techniques and tools.
nbtstat
In Windows, the most common command to use when enumerating Windows shares is nbtstat. Nbtstat is a Windows command line tool that can display information about a target. You can check how to use it by passing it the /? parameter The most common use of nbtstat is "nbtstat -A [IP]" that displays information about a target
the first line tells us the name of the machine [OVERLORD] the record type 00 tells us that OVERLORD is a workstation. the type UNIQUE tells us that this computer must have only one IP address assigned. second line contains the workgroup or the domain the computer is joined to. type 20 record means that the file sharing service is up and running on the machine.
Once an attacker knows that a machine has the File Server service running, they can enumerate the shares by using the NET VIEW command.
This machine is sharing a directory; the share name is shares You can also perform shares enumeration from a Linux machine. You need to use the tools provided by the Samba suite. Samba tools are already installed in Kali Linux, but you can install them in nearly every Linux distribution. To perform the same operations of nbtstat, you can use nmblookup with the same command line switch:
Checking for Null Sessions
Once we have detected that the File and Printer Sharing service is active and we have enumerated the available shares on a target, it is time to check if a null session attack is possible To verify that, we will exploit the IPC$ administrative share by trying to connect to it without valid credentials.
from linux
from windows
This tells Windows to connect to the IPC$ share by using an empty password and an empty username!
metasploit modules
gain access to smb shares
Mounting Shares From Linux
Last updated