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
userPasswordattribute or thepwdPolicyobject class. Even if passwords are hashed, the hash can be valuable. - ACL gaps: A common mis‑configuration is granting
Readaccess 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
- Filter for LDAP ports.
- Aggregate per source/destination pair.
- Compute the mean and standard deviation of traffic volume.
- 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
- 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.
- Audit Log:
audit.logshows 4,500ldapsearchcommands executed bymalicious_user. - Alert: The correlation rule fires, flagging the host and the user.
- Investigation: The incident response team checks the workstation’s EDR logs. A scheduled task running
ldapsearchevery 15 minutes is discovered. - Remediation: The task is disabled, the workstation is isolated, and the LDAP ACLs are tightened to restrict
Readaccess touserPasswordto 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.
- Enforce LDAPS: Disable plain LDAP (port 389) on all interfaces. Use TLS 1.2+ with strong ciphers.
- Restrict ACLs: Grant
ReadonuserPasswordonly to theDomain Adminsgroup. Use theaccessdirective inslapd.conforcn=config. - Enable Audit: In Windows, enable
Audit Directory Service ChangesandAudit Directory Service Access. In OpenLDAP, setloglevelto256for access logging. - 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.
- Certificate Pinning: Clients should pin the LDAP server’s certificate to prevent MITM.
9. Post‑Detection Response
When an alert fires:
- Contain: Immediately isolate the source host if possible.
- Validate: Confirm that the LDAP traffic is not part of a scheduled job or legitimate sync.
- Inspect: Pull the raw LDAP queries from the audit logs. Look for
ldapsearchwith-b ""or-s sub. - Remediate: Patch the host, revoke compromised credentials, and adjust ACLs.
- 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
- How ML and Behavioral Analysis Are Changing WAFs
- Detecting API Abuse in Real-Time Using Honeypot Endpoints
- Designing SIEM Alerts That Actually Stop the Noise Before It Spreads
- When OAuth Refresh Tokens Live Forever: How to Force Short Expiry in Production
- Auditing Unmanaged Service Accounts: Preventing Silent Privilege Escalation
- Using Attack Trees to Spot OAuth Token Leakage in Microservices