Overview
NTLM relay attacks allow an attacker to intercept NTLM authentication attempts and relay them to other services, gaining unauthorized access. Impacket’sntlmrelayx.py is a comprehensive tool for performing these attacks.
Location: examples/ntlmrelayx.py
How NTLM Relay Works
- Victim attempts to authenticate to attacker-controlled server
- Attacker captures NTLM authentication without completing it
- Attacker relays authentication to target server
- Target accepts authentication from victim’s credentials
- Attacker executes commands with victim’s privileges
Basic Usage
Simple SMB Relay
LDAP Relay
Protocol Support
Relay Servers (Listeners)
ntlmrelayx can listen on multiple protocols:- SMB (TCP 445)
- HTTP/HTTPS (TCP 80/443)
- LDAP (TCP 389)
- MSSQL (TCP 1433)
- IMAP/IMAPS (TCP 143/993)
- SMTP (TCP 25/587)
- RPC (TCP 135)
- WinRM (TCP 5985/5986)
Relay Clients (Targets)
Relay authentication to:- SMB: File shares, admin access
- LDAP/LDAPS: Directory services, privilege escalation
- HTTP/HTTPS: Web applications, APIs
- MSSQL: Database access
- RPC: Remote procedure calls
- SMTP: Email relay
- IMAP: Email access
Attack Techniques
1. SMB Relay for Code Execution
2. LDAP Relay for Privilege Escalation
3. SOCKS Proxy Mode
4. HTTP to SMB/LDAP Relay
5. ADCS (Active Directory Certificate Services) Attack
6. MSSQL Relay
Configuration Options
Target Selection
Attack Options
Server Options
Output Options
Programming with Relay Components
Custom Relay Server
Custom Attack Module
Custom LDAP Attack
Defenses Against Relay Attacks
SMB Signing
LDAP Signing and Channel Binding
LDAPS with channel binding prevents relay:EPA (Extended Protection for Authentication)
HTTP services with EPA enabled resist relay attacks.Mitigation Recommendations
- Enable SMB Signing: Require signing on all systems
- Disable NTLM: Use Kerberos exclusively where possible
- LDAP Signing: Enforce LDAP signing and channel binding
- Network Segmentation: Prevent lateral relay opportunities
- Monitor: Detect NTLM authentication anomalies
- Patch: Apply patches for coercion vulnerabilities (PrinterBug, PetitPotam)
Detection
Signs of relay attacks:- Multiple authentication attempts from single IP
- NTLM authentication from unexpected sources
- Privilege escalation without credential access
- Anonymous SMB connections
- Unusual LDAP modifications
- Event IDs: 4624 (Logon), 4672 (Special Privileges), 4738 (User Account Changed)
Common Attack Chains
1. Coerce + Relay + Escalate
2. SOCKS + Dump Secrets
3. ADCS Certificate Theft
Best Practices
- Test in lab first: Relay attacks can disrupt production
- Understand target security: Check for signing requirements
- Use SOCKS mode: More flexible than direct relay
- Combine with coercion: PrinterBug, PetitPotam, DFSCoerce
- Clean up: Remove added computer accounts, reset ACLs
- Document: Keep records of compromised accounts
References
- CVE-2019-1040: NTLM MIC bypass
- CVE-2019-1019: NTLM session security bypass
- PetitPotam (CVE-2021-36942)
- PrinterBug (MS-RPRN RpcRemoteFindFirstPrinterChangeNotification)
- Resource-Based Constrained Delegation (RBCD)
- Shadow Credentials (CVE-2021-42278, CVE-2021-42287)