networking, updated

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)
Specs
RFC 4511, RFC 4513, RFC 4515
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]
OperationPurpose
bindRequest / bindResponseLog in: anonymous, simple (DN + password in clear text) or SASL (GSSAPI = Kerberos, GSS-SPNEGO = NTLM or Kerberos)
searchRequest → searchResEntry … searchResDoneQuery: one entry per result, then a done message with the result code
modifyRequest, addRequest, delRequest, modDNRequestChange the directory
extendedRequestStartTLS (OID 1.3.6.1.4.1.1466.20037), password modify, “Who am I?”
unbindRequestClose the session
Result codeMeaning
0success
8strongerAuthRequired (signing or TLS needed)
32noSuchObject
49invalidCredentials (the AD sub-code in the message says why: 52e wrong password, 775 account locked)
50insufficientAccessRights

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

FilterShows
ldapLDAP over TCP 389 / 3268
cldapConnectionless LDAP (DC locator pings)
ldap.protocolOp == 0Bind requests
ldap.simpleSimple binds: clear-text passwords
ldap.resultCode == 49Failed logins
ldap.protocolOp == 3Search requests
ldap.present == "servicePrincipalName"SPN searches (Kerberoasting recon)
ldap.attributeDesc == "adminCount"Searches for privileged accounts
ldap.protocolOp == 6Modify requests (changes to AD)
tcp.port == 636LDAPS (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

References

§ home
~/knubertus/home/
1,1 Top