Using SIEM to Catch Misconfigured LDAP Exfiltration Attempts

Misconfigured LDAP Exfiltration: A SIEM‑First Approach

Modern enterprises still rely on LDAP for authentication, directory lookups, and policy distribution. When the directory server is misconfigured—open ports, weak ACLs, or unencrypted traffic—an attacker can harvest sensitive attributes (emails, group memberships, even passwords if the schema exposes them). Detecting such exfiltration early is a matter of correlating LDAP traffic patterns with anomalous outbound data flows. A SIEM that ingests both network flow logs and LDAP audit logs can surface these events before data leaves the perimeter.


1. Why LDAP is a “Hidden” Exfil Vector

  • Default ports (389 for LDAP, 636 for LDAPS) are often left open on all internal interfaces. Attackers can pivot from a compromised host to the directory server without hitting a firewall.
  • Schema mis‑exposure: Many installations expose the userPassword attribute or the pwdPolicy object class. Even if passwords are hashed, the hash can be valuable.
  • ACL gaps: A common mis‑configuration is granting Read access to all users on the entire directory tree. This allows enumeration of every account and group.
  • Unencrypted traffic: LDAP over plain TCP is susceptible to man‑in‑the‑middle attacks. Even when LDAPS is enabled, weak TLS ciphers or expired certificates can defeat the protection.

Because LDAP queries are lightweight, an attacker can issue thousands of requests in minutes, making detection by simple rate‑limiting ineffective. The real challenge is distinguishing legitimate bulk queries (e.g., a provisioning script) from malicious enumeration.


2. SIEM Data Sources to Watch

Source What to Capture Typical Log Format
NetFlow / sFlow Source IP, destination IP, port, bytes src_ip dst_ip src_port dst_port bytes
Windows Event Logs LDAP audit events (4624, 4625, 4662) XML or CSV
Linux auditd auditd logs for open, read, write on /etc/openldap /var/log/audit/audit.log
Firewall logs Connection attempts to 389/636 src_ip dst_ip port action
Endpoint EDR Process activity performing LDAP queries (ldapsearch, ldapmodify) Process name, command line

A robust SIEM ingest pipeline should normalize these into a common schema (e.g., event_type, user, src_ip, dst_ip, bytes, timestamp). The normalization step is critical for correlation rules that span multiple data sources.


3. Baseline LDAP Traffic

Before writing alerts, establish a baseline:

# NetFlow export from the internal router
tcpdump -i eth0 -nn -s0 -l port 389 or port 636 | \
  awk '{print $3,$5,$7}' | \
  grep -Eo '([0-9]+\.){3}[0-9]+' | \
  sort | uniq -c | sort -nr | head

The output gives you the top talkers. Legitimate services (e.g., adfs, samba, sssd) will dominate. Any host that suddenly appears in the top 5 for LDAP traffic is a candidate for investigation.


4. Correlation Rule Design

Below is a practical Splunk‑style query that surfaces anomalous LDAP exfil attempts. Adapt it to your SIEM’s query language.

index=netflow OR index=ldap_audit
| eval proto=if(port==389,"LDAP",if(port==636,"LDAPS","OTHER"))
| where proto=="LDAP" OR proto=="LDAPS"
| stats sum(bytes) as total_bytes, count as req_count by src_ip, dst_ip, proto
| eventstats avg(total_bytes) as avg_bytes, stdev(total_bytes) as sd_bytes
| where total_bytes > avg_bytes + 3*sd_bytes
| table src_ip, dst_ip, proto, total_bytes, req_count

Explanation

  1. Filter for LDAP ports.
  2. Aggregate per source/destination pair.
  3. Compute the mean and standard deviation of traffic volume.
  4. Flag any pair exceeding mean + 3 σ (a common outlier threshold).

This rule surfaces hosts that send unusually large amounts of LDAP data to the directory server. Combine it with a second rule that checks the content of the LDAP queries (e.g., ldapsearch with -x and -b on the root DSE).


5. Content‑Level Detection

If your SIEM can parse LDAP query strings, look for patterns that indicate enumeration:

Pattern Why It Matters
ldapsearch -x -b "" Full directory enumeration
ldapsearch -x -b "dc=corp,dc=local" -s sub "(objectClass=*)" Bulk object retrieval
ldapmodify with -x Potential write operations

A simple regex rule:

ldapsearch.*-b\s+\"\"|ldapmodify.*-x

When matched, trigger an alert and correlate with the source IP’s recent authentication events. If the same host also performed a failed login burst, the likelihood of malicious activity rises.


6. Real‑World Example

Scenario: A Windows workstation in the Finance domain was compromised via a phishing email. The attacker used ldapsearch to pull all userPassword attributes.

SIEM Flow

  1. NetFlow: The workstation (10.10.5.23) sends 1.2 GB of LDAP traffic to the domain controller (10.10.0.5) over port 389 in a 5‑minute window.
  2. Audit Log: audit.log shows 4,500 ldapsearch commands executed by malicious_user.
  3. Alert: The correlation rule fires, flagging the host and the user.
  4. Investigation: The incident response team checks the workstation’s EDR logs. A scheduled task running ldapsearch every 15 minutes is discovered.
  5. Remediation: The task is disabled, the workstation is isolated, and the LDAP ACLs are tightened to restrict Read access to userPassword to administrators only.

7. Trade‑offs and Caveats

Trade‑off Detail Mitigation
False positives Legitimate bulk syncs (e.g., backup software) may trigger alerts Whitelist known services; add a suppression rule for sssd or adfs
Encrypted LDAP LDAPS traffic is opaque; size‑based detection still works, but content inspection is impossible Deploy an LDAP proxy that logs queries before encryption
High‑volume environments Large directories generate many legitimate queries Use percentile‑based thresholds (e.g., 95th percentile) instead of fixed σ
Log volume Capturing every LDAP query can overwhelm the SIEM Aggregate at the source (e.g., forward only audit events, not raw packets)

Balancing sensitivity and noise is the core of any detection strategy. Start with conservative thresholds, then iterate based on analyst feedback.


8. Hardening LDAP Before Detection

Detection is a safety net; prevention is the first line of defense.

  1. Enforce LDAPS: Disable plain LDAP (port 389) on all interfaces. Use TLS 1.2+ with strong ciphers.
  2. Restrict ACLs: Grant Read on userPassword only to the Domain Admins group. Use the access directive in slapd.conf or cn=config.
  3. Enable Audit: In Windows, enable Audit Directory Service Changes and Audit Directory Service Access. In OpenLDAP, set loglevel to 256 for access logging.
  4. Network Segmentation: Place the LDAP server in a DMZ or a dedicated VLAN with strict egress rules. Only allow outbound traffic on port 443 to a secure LDAP proxy.
  5. Certificate Pinning: Clients should pin the LDAP server’s certificate to prevent MITM.

9. Post‑Detection Response

When an alert fires:

  1. Contain: Immediately isolate the source host if possible.
  2. Validate: Confirm that the LDAP traffic is not part of a scheduled job or legitimate sync.
  3. Inspect: Pull the raw LDAP queries from the audit logs. Look for ldapsearch with -b "" or -s sub.
  4. Remediate: Patch the host, revoke compromised credentials, and adjust ACLs.
  5. Review: Update the SIEM rule to reduce future false positives.

Document each step in the incident ticket. The evidence (NetFlow, audit logs, EDR snapshots) will be invaluable for post‑mortem analysis and compliance reporting.


10. Tooling Checklist

Tool Purpose Notes
Zeek Network flow analysis, LDAP module Zeek’s ldap.log provides query details
Splunk Enterprise Security Correlation engine Use search head for real‑time alerts
Elastic Stack (ELK) Log aggregation Beats can ship auditd logs
OpenLDAP slapd Server audit loglevel 256 for access logs
Windows Event Forwarding Centralized audit Configure Security logs to forward to SIEM

11. Keeping the SIEM Updated

LDAP protocols evolve. In 2025, the community adopted the ldapv3 extension for password policy control. Ensure your SIEM’s LDAP parser is updated to recognize new OIDs. Regularly review the NIST Special Publication 800‑53 controls for guidance on directory service hardening.


See also