Enumeration & Exploitation & Hardening
Enumeration & Exploitation & Hardening
Dica: para localizar rapidamente o termo de pesquisa nesta página, pressione Ctrl+F ou ⌘-F (Mac) e use a barra de localização.
Page 1
SMB
Enumeration & Exploitation & Hardening
Anıl BAŞ
August 2020
Page 2
Table of Contents
Introduction ........................................................................................................................... 3
What is SMB? ................................................................................................................................... 3
References ............................................................................................................................ 17
Page 3
Introduction
What is SMB?
SMB (Server Message Block) is a network protocol for accessing files, printers and other devices
on the network. Server Message Block provides file sharing, network browsing, printing services,
and interprocess communication over a network. Most usage of SMB involves computers
running Microsoft Windows, where it was known as "Microsoft Windows Network" before the
introduction of Active Directory. SMB uses TCP 139 and TCP 445 ports by default. Latest SMB
version is SMBv3. SMB has been the subject of numerous vulnerabilities from past to present.
Lets talk about some of these.
CVE-2020-1206 (SMBleed)
This is the most recent SMB vulnerability was announced. An information disclosure vulnerability
published on Microsoft Server Message Block 3.1.1 (SMBv3). An attacker who successfully
exploited the vulnerability could obtain information to further compromise the user’s system. To
exploit a server, an unauthenticated attacker could send a specially crafted packet to a targeted
SMBv3 server. To exploit a client, an unauthenticated attacker would need to configure a
malicious SMBv3 server and convince a user to connect to it.
CVE-2020-0796 (SMBGhost)
A remote code execution vulnerability exists in the way that the Microsoft Server Message Block
3.1.1 (SMBv3) protocol handles certain requests. An attacker who successfully exploited the
vulnerability could gain the ability to execute code on the target server or client. To exploit the
vulnerability against a server, an unauthenticated attacker could send a specially crafted packet
to a targeted SMBv3 server. To exploit the vulnerability against a client, an unauthenticated
attacker would need to configure a malicious SMBv3 server and convince a user to connect to it.
Affected Versions
Page 4
MS17-010 (EternalBlue)
The most severe of the vulnerabilities could allow remote code execution if an attacker sends
specially crafted messages to a Microsoft Server Message Block 1.0 (SMBv1) server. On 2017,
WannaCry Ransomware which targeted computers running the Microsoft Windows operating
system by encrypting data and demanding ransom payments in the Bitcoin cryptocurrency.
WannaCry Ransomware propagated through EternalBlue (MS17-010).
MS08-67 (Conficker)
This is a remote code execution vulnerability. An attacker who successfully exploited this
vulnerability could take complete control of an affected system remotely. On Microsoft Windows
2000-based, Windows XP-based, and Windows Server 2003-based systems, an attacker could
exploit this vulnerability over RPC without authentication and could run arbitrary code.
SMB Enumeration
SMB is one of the most important service. So it is very important for a pentester. First things first,
we need get some information.
Gathering Hostname
Nmblookup is a tool in the Kali Linux distribution. Nmblookup collects NetBIOS over TCP/IP client
used to lookup NetBIOS names.
Page 5
nmblookup -A [ip]
Page 6
smbmap -H [ip]
smbclient -L \\\\[ip]
Page 7
smbmap -H [ip]
rpcclient -U “” -N [ip]
smbclient \\\\[ip]\\[sharename]
Page 8
Automated Enumeration
Enum4Linux is a great tool for SMB Scanning. Enum4Linux checks all SMB Enumeration types with
-A (do all enumeration) parameter. Enum4Linux checks for null session, share listing, domain info,
password policy and etc.
enum4linux -A [ip]
Page 9
Exploiting MS17-010
Now, we know how to enumerate SMB service. A computer with MS17-010 vulnerability was
detected using enumeration methods. So, let’s exploit it.
msfconsole
search ms17
Page 10
use exploit/Windows/smb/ms17_010_eternalblue
Every module on the metaspolit framework needs some parameters to exploit. So, we need to
set required parameters in the module options.
Page 11
After the setting, we can check the vulnerability is exists or we can try exploit the vulnerability
directly. Let’s check vulnerability for confirmation.
Now, we have privileged shell on the target computer. We can do everything on the target
computer.
Page 12
If target shares a folder without restrictions, we can read/write files over the SMB. So let’s check
the target for sharings.
As you can see in the above, there is a folder for sharing. We can check it out with smbclient.
There is an interesting file on the folder. Let’s get and read it.
We have obtained very critical information for an attacker. Well, reading is successful but what
about writing files? Let’s check for writing files.
Page 13
We can write a malicious code on the target. Let’s check it on the target.
Page 14
SMB Hardening
Disable SMBv1
SMBv1 is a very old version of SMB. This makes it insecure. When you use SMB1, we lose key
protections offered by later SMB protocol versions:
Starting in Windows 8.1 and Windows Server 2012 R2, removal of the SMB1 feature possible and
easy.
Remove-WindowsFeature FS-SMB1
Page 15
When using operating systems older than Windows 8.1 and Windows Server 2012 R2, we can’t
remove SMB1 but we can disable it.
For Windows 7, Windows Server 2008 R2, Windows Vista, and Windows Server 2008
Set-ItemProperty -Path
"HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" SMB1 -Type
DWORD -Value 0 –Force
1. Go to HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\LanManServer\Parameters
2. From the Edit menu select New - DWORD value
3. Add the following two values EnableSecuritySignature and RequireSecuritySignature if they do
not exist.
4. You should set to 0 for disable (the default) or 1 to enable. Enabling EnableSecuritySignature
means if the client also has SMB signing enabled then that is the preferred communication
method, but setting RequireSecuritySignature to enabled means SMB signing MUST be used and
so if the client is not SMB signature enabled then communication will fail.
Page 16
Restrict Access
SMB is one of the most important services. We must restrict access to SMB services.
Cut outbound SMB access at the corporate firewall with exceptions for specific IP ranges
It is extremely unlikely you’ll need to allow any outbound SMB to the Internet unless you’re using
it as part of a public cloud offering. With Azure Files SMB you could instead use a VPN. You should
be restricting that outbound traffic to only those service IP ranges.
Page 17
References
https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/CVE-2020-1206
https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/CVE-2020-0796
https://docs.microsoft.com/en-us/security-updates/SecurityBulletins/2017/ms17-
010?redirectedfrom=MSDN
https://support.microsoft.com/en-us/help/4013389/title
https://support.microsoft.com/en-us/help/958644/ms08-067-vulnerability-in-server-service-
could-allow-remote-code-execu
https://techcommunity.microsoft.com/t5/storage-at-microsoft/stop-using-smb1/ba-p/425858
https://docs.microsoft.com/en-us/windows-server/storage/file-server/troubleshoot/detect-enable-
and-disable-smbv1-v2-v3
https://www.itprotoday.com/security/how-do-i-enable-smb-signing
https://techcommunity.microsoft.com/t5/itops-talk-blog/beyond-the-edge-how-to-secure-smb-
traffic-in-windows/ba-p/1447159
https://medium.com/@arnavtripathy98/smb-enumeration-for-penetration-testing-e782a328bf1b
https://0xdf.gitlab.io/2018/12/02/pwk-notes-smb-enumeration-checklist-update1.html
https://social.technet.microsoft.com/Forums/windowsserver/en-US/52899d34-0033-41f5-b5e0-
2325dd827244/disabling-null-sessions-on-windows-server-20032008?forum=winserverGP
https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-
and-2008/dd349805(v=ws.10)?redirectedfrom=MSDN#BKMK_44