Skip to main content

Overview

NTLM relay attacks allow an attacker to intercept NTLM authentication attempts and relay them to other services, gaining unauthorized access. Impacket’s ntlmrelayx.py is a comprehensive tool for performing these attacks. Location: examples/ntlmrelayx.py

How NTLM Relay Works

  1. Victim attempts to authenticate to attacker-controlled server
  2. Attacker captures NTLM authentication without completing it
  3. Attacker relays authentication to target server
  4. Target accepts authentication from victim’s credentials
  5. 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

  1. Enable SMB Signing: Require signing on all systems
  2. Disable NTLM: Use Kerberos exclusively where possible
  3. LDAP Signing: Enforce LDAP signing and channel binding
  4. Network Segmentation: Prevent lateral relay opportunities
  5. Monitor: Detect NTLM authentication anomalies
  6. 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

  1. Test in lab first: Relay attacks can disrupt production
  2. Understand target security: Check for signing requirements
  3. Use SOCKS mode: More flexible than direct relay
  4. Combine with coercion: PrinterBug, PetitPotam, DFSCoerce
  5. Clean up: Remove added computer accounts, reset ACLs
  6. 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)