LDAP
The Lightweight Directory Access Protocol reads and changes directory data: users, groups, computers and their attributes. In Windows networks it is how everything talks to Active Directory, and how attackers map it.
- OSI layer
- 7 Application
- Carried in
- TCP (UDP for CLDAP)
- Ports
- 389/tcp (LDAP, StartTLS), 636/tcp (LDAPS), 389/udp (CLDAP), 3268, 3269/tcp (AD Global Catalog)
- Wireshark filter
ldap || cldap- Encrypted
- no
Packet structure
LDAP has no fixed header: every message is an ASN.1 structure in BER encoding (tag, length, value), so field sizes vary. Wireshark decodes it as a tree; this is a search request:
LDAPMessage
├─ messageID: 7 ← matches the response to the request
└─ protocolOp: searchRequest (3)
├─ baseObject: "DC=corp,DC=example,DC=com"
├─ scope: wholeSubtree (2) ← baseObject (0), singleLevel (1)
├─ derefAliases: neverDerefAliases (0)
├─ sizeLimit: 0 ← 0 = server default
├─ timeLimit: 0
├─ typesOnly: false
├─ filter: (&(objectCategory=person)(servicePrincipalName=*))
└─ attributes: sAMAccountName, servicePrincipalName
[controls: optional, e.g. paged results 1.2.840.113556.1.4.319]
| Operation | Purpose |
|---|---|
bindRequest / bindResponse | Log in: anonymous, simple (DN + password in clear text) or SASL (GSSAPI = Kerberos, GSS-SPNEGO = NTLM or Kerberos) |
searchRequest → searchResEntry … searchResDone | Query: one entry per result, then a done message with the result code |
modifyRequest, addRequest, delRequest, modDNRequest | Change the directory |
extendedRequest | StartTLS (OID 1.3.6.1.4.1.1466.20037), password modify, “Who am I?” |
unbindRequest | Close the session |
| Result code | Meaning |
|---|---|
| 0 | success |
| 8 | strongerAuthRequired (signing or TLS needed) |
| 32 | noSuchObject |
| 49 | invalidCredentials (the AD sub-code in the message says why: 52e wrong password, 775 account locked) |
| 50 | insufficientAccessRights |
How it works
sequenceDiagram
participant C as Client
participant D as Directory server :389
C->>D: bindRequest (SASL GSS-SPNEGO, Kerberos ticket)
D->>C: bindResponse success
C->>D: searchRequest base=DC=corp,... filter=(sAMAccountName=alice)
D->>C: searchResEntry CN=Alice,OU=Staff,...
D->>C: searchResDone success
C->>D: unbindRequest
Everything in the directory is an entry with a distinguished name (CN=Alice,OU=Staff,DC=corp,DC=example,DC=com) and attributes. Searches use prefix-notation filters: (&(objectClass=user)(memberOf=CN=Domain Admins,CN=Users,DC=corp,DC=example,DC=com)).
In Active Directory, clients find domain controllers with DNS SRV records and a CLDAP ping on UDP 389, then use LDAP over TCP. With SASL signing (or “sealing”), the messages after the bind are signed or encrypted and Wireshark shows them as SASL GSS-API Privacy unless it has the keys.
In Wireshark
| Filter | Shows |
|---|---|
ldap | LDAP over TCP 389 / 3268 |
cldap | Connectionless LDAP (DC locator pings) |
ldap.protocolOp == 0 | Bind requests |
ldap.simple | Simple binds: clear-text passwords |
ldap.resultCode == 49 | Failed logins |
ldap.protocolOp == 3 | Search requests |
ldap.present == "servicePrincipalName" | SPN searches (Kerberoasting recon) |
ldap.attributeDesc == "adminCount" | Searches for privileged accounts |
ldap.protocolOp == 6 | Modify requests (changes to AD) |
tcp.port == 636 | LDAPS (TLS, content hidden) |
What normal looks like: domain members query their DC all the time with signed or encrypted Kerberos binds. Many searches from one workstation within seconds, over the whole directory, with paged-results controls, is collection by BloodHound/SharpHound, ADExplorer or similar. Simple binds on 389 from appliances (printers, VPNs, web apps) send passwords in the clear.
Security notes
- Clear-text credentials: simple bind on 389 without TLS exposes the service account password to anyone on the path. Use LDAPS (636) or StartTLS, or SASL with signing.
- NTLM relay to LDAP: a relayed NTLM login to a DC that does not require LDAP signing and channel binding lets the attacker change AD objects (add a computer account, set resource-based constrained delegation, grant DCSync rights). Enforce both on all DCs.
- Reconnaissance: any authenticated user can read most of AD: users, groups, SPNs (for Kerberoasting), accounts without Kerberos pre-auth (AS-REP roasting), ACLs, trusts. Watch for broad queries from unusual hosts.
- Anonymous access: null binds that can read the directory leak usernames for password spraying.
- Password spraying: many binds with one password across many accounts; result code 49 with sub-code
52e. - LDAP injection: web apps that build filters from user input (
*)(uid=*))(|(uid=*) can bypass logins or leak data. Escape input per RFC 4515. - Reflection DDoS: CLDAP on UDP 389 open to the internet amplifies about 50 to 70 times.
- Passback attacks: printers and other devices with a configurable LDAP server can be pointed at the attacker to receive the stored bind password.
Versions and related
- LDAPv3 (RFC 4510 to 4519) is the current version; v2 is obsolete.
- LDAPS (636) is LDAP inside TLS from the first byte; StartTLS upgrades a 389 connection.
- Active Directory adds the Global Catalog (3268/3269), CLDAP and AD-specific controls. OpenLDAP and 389 Directory Server are common on Linux.
- Logins use Kerberos or NTLM (see SMB); DCs are found via DNS SRV records. RADIUS servers often check passwords against LDAP.
References
- RFC 4511: LDAP protocol
- RFC 4513: Authentication methods and security
- RFC 4515: String representation of search filters
- Microsoft: LDAP signing and channel binding (ADV190023)