Directory and authentication: LDAP, Kerberos, Active Directory
LDAP is the central directory where all users live, Kerberos is the ticket system that checks a password once and then hands out tickets, and an Active Directory Domain Controller runs both (plus DNS) together. This is how one office login opens the Wiki, file server, VPN and mail.
137.1 Why is it used?
- 10 apps with 10 separate password lists: when Asha leaves, the admin must delete her in 10 places; missing one is a security hole.
- LDAP keeps all users in one central directory.
- Kerberos: the password is checked once, then apps accept tickets instead of passwords.
- Active Directory combines LDAP + Kerberos + DNS on every Domain Controller.
137.2 How LDAP works
- Lightweight Directory Access Protocol, TCP 389 (LDAPS on 636).
- The directory is a tree (DIT): root dc=lab,dc=local -> ou=people -> uid=asha.
- DN = full address of an entry: uid=asha,ou=people,dc=lab,dc=local.
- Search = base (where to start) + filter (what to find), e.g. base dc=lab,dc=local, filter (uid=asha).
- Bind = login: anonymous (no login), simple (DN + password), SASL (strong methods like Kerberos/GSSAPI).
- Step 1
1.Asha logs in to the Wiki app
- Step 2
2.Wiki sends bindRequest to LDAP server 192.168.157.10:389: dn uid=asha,ou=people,... + password (simple)
- Step 3
3.Server replies bind success
- Step 4
4.searchRequest base dc=lab,dc=local, filter (uid=asha), attrs cn mail title
- Step 5
5.Server returns Asha's entry: name, mail, title
137.3 Lab: OpenLDAP and ldapsearch
slapd -f /etc/openldap/slapd.conf \ -h ldap:///ldapadd -x -H ldap://localhost \ -D cn=admin,dc=lab,dc=local \ -w admin-lab-123 -f /tmp/tree.ldifadding new entry "dc=lab,dc=local"adding new entry "ou=people,dc=lab,dc=local"adding new entry "ou=groups,dc=lab,dc=local"adding new entry "uid=asha,ou=people,dc=lab,dc=local"adding new entry "uid=ravi,ou=people,dc=lab,dc=local"ldapsearch -x -H ldap://192.168.157.10 \ -b dc=lab,dc=local -LLL dnldapsearch -x -H ldap://192.168.157.10 \ -D uid=asha,ou=people,dc=lab,dc=local \ -w asha-lab-123 -b dc=lab,dc=local \ -LLL '(uid=asha)' cn mail titleldapsearch -x -H ldap://192.168.157.10 \ -D uid=asha,ou=people,dc=lab,dc=local \ -w wrong-pass -b dc=lab,dc=local \ '(uid=asha)'dn: dc=lab,dc=localdn: ou=people,dc=lab,dc=localdn: ou=groups,dc=lab,dc=localdn: uid=asha,ou=people,dc=lab,dc=localdn: uid=ravi,ou=people,dc=lab,dc=local dn: uid=asha,ou=people,dc=lab,dc=localcn: Asha Vermamail: asha@lab.localtitle: Network Engineer ldap_bind: Invalid credentials (49)- -x = simple bind, -D = bind DN, -w = password, -b = search base, -LLL = plain LDIF output.
- Wrong password -> result code 49 Invalid credentials.
137.4 Simple bind sends the password in clear text
tcpdump -i eth0 -U -w /tmp/ldap.pcap 'tcp port 389' &tshark -r /tmp/ldap.pcap -Y ldap \ -T fields -e ip.src -e ip.dst -e _ws.col.Infotshark -r /tmp/ldap.pcap \ -Y ldap.bindRequest_element \ -T fields -e ldap.name -e ldap.simple.20 .10 bindRequest(1) "uid=asha,ou=people,..." simple.10 .20 bindResponse(1) success.20 .10 searchRequest(2) "dc=lab,dc=local" wholeSubtree.10 .20 searchResEntry(2) "uid=asha,ou=people,...".10 .20 searchResDone(2) success [1 result].20 .10 unbindRequest(3) uid=asha,ou=people,dc=lab,dc=local asha-lab-123- The lab password is visible in the capture: on a real network run simple bind only inside LDAPS (636) or StartTLS.
137.5 How Kerberos works
- Step 1
1.AS-REQ to KDC 192.168.157.10:88: asha@LAB.LOCAL, pre-auth = timestamp encrypted with the password (no password sent)
- Step 2
2.AS-REP: TGT for krbtgt/LAB.LOCAL, valid 10 hours, + session key
- Step 3
3.TGS-REQ: show TGT + authenticator, want host/srv.lab.local
- Step 4
4.TGS-REP: service ticket encrypted with the file server's own key
- Step 5
5.AP-REQ: laptop hands the service ticket to srv.lab.local
- Step 6
6.File server decrypts it with its own key and grants access, without asking the KDC
Like a cinema: buy one entry pass (TGT), then get a ticket per hall (service)
| Exchange | Messages | Result |
|---|---|---|
| AS (Authentication Service) | AS-REQ / AS-REP | TGT (Ticket Granting Ticket) |
| TGS (Ticket Granting Service) | TGS-REQ / TGS-REP | Service ticket for one service |
| AP (Application) | AP-REQ (/ AP-REP) | Access to the service |
137.6 Lab: MIT Kerberos, kinit, klist, kvno
kdb5_util create -s -r LAB.LOCAL \ -P master-lab-123krb5kdckadmin.local -q \ 'addprinc -pw asha-krb-123 +requires_preauth asha'kadmin.local -q \ 'addprinc -randkey host/srv.lab.local'# clientkinit ashakvno host/srv.lab.localklistPrincipal "asha@LAB.LOCAL" created.Principal "host/srv.lab.local@LAB.LOCAL" created. Password for asha@LAB.LOCAL:host/srv.lab.local@LAB.LOCAL: kvno = 1Ticket cache: FILE:/tmp/krb5cc_0Default principal: asha@LAB.LOCALValid starting Expires Service principal11/09/26 04:10:57 11/09/26 14:10:57 krbtgt/LAB.LOCAL@LAB.LOCAL11/09/26 04:10:57 11/09/26 14:10:57 host/srv.lab.local@LAB.LOCALtshark -r /tmp/krb.pcap -Y kerberos \ -T fields -e ip.src -e ip.dst -e _ws.col.Info192.168.157.20 192.168.157.10 AS-REQ192.168.157.10 192.168.157.20 KRB Error: KRB5KDC_ERR_PREAUTH_REQUIRED192.168.157.20 192.168.157.10 AS-REQ192.168.157.10 192.168.157.20 AS-REP192.168.157.20 192.168.157.10 TGS-REQ192.168.157.10 192.168.157.20 TGS-REP- The first AS-REQ gets PREAUTH_REQUIRED; the second carries the encrypted timestamp. The password never crosses the wire.
137.7 Clock skew: why time sync matters
- Every request carries a timestamp; the KDC allows max 5 minutes difference so old captured tickets cannot be replayed.
- Laptop 10 minutes ahead -> KRB_AP_ERR_SKEW. Every domain machine syncs time with NTP (UDP 123).
LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1 \ FAKETIME=+10m kvno host/srv.lab.localLD_PRELOAD=/usr/lib/faketime/libfaketime.so.1 \ FAKETIME=+2m kvno host/srv.lab.localreal clock 04:11:04fake clock 04:21:04kvno: Clock skew too great while getting credentials for host/srv.lab.local@LAB.LOCAL.20 .10 TGS-REQ.10 .20 KRB Error: KRB5KRB_AP_ERR_SKEW $ FAKETIME=+2m kvno host/srv.lab.localhost/srv.lab.local@LAB.LOCAL: kvno = 1137.8 Active Directory: DC = LDAP + Kerberos + DNS
- Step 1
1.Office laptop pc1.lab.local asks DNS (53): where is the DC for lab.local?
- Step 2
2.Gets a TGT from Kerberos on DC01 (88)
- Step 3
3.Reads groups and policies from LDAP on DC01 (389)
- Step 4
4.Opens the file server: service ticket, file server (domain member) trusts the same DC
- Step 5
5.Time stays in sync with the DC via NTP (123)
| Service on the DC | Port | Job |
|---|---|---|
| DNS | 53 | Find the DC (SRV records) |
| Kerberos | 88 | TGT and service tickets |
| LDAP / LDAPS | 389 / 636 | Users, groups, computers, policies |
| NTP | 123 | Time sync for Kerberos |
klist purgeklist get http/iisserver.contoso.comA ticket to http/iisserver.contoso.com has been retrieved successfully.Cached Tickets: (2)#0> Client: John @ CONTOSO.COM Server: krbtgt/CONTOSO.COM @ CONTOSO.COM KerbTicket Encryption Type: AES-256-CTS-HMAC-SHA1-96 Kdc Called: DCA.contoso.com#1> Client: John @ CONTOSO.COM Server: http/iisserver.contoso.com @ CONTOSO.COM Kdc Called: DCA.contoso.com- Windows klist is built in (example output from Microsoft docs): #0 is the TGT, #1 a service ticket; Kdc Called shows which DC issued it.
137.9 Common mistakes
- Thinking Kerberos sends the password: only an encrypted timestamp goes on the wire.
- Running LDAP simple bind on plain 389: the password is clear text; use LDAPS or StartTLS.
- Ignoring time sync: more than 5 minutes skew breaks every Kerberos login.
- Thinking the service must ask the KDC to verify a ticket: it decrypts it with its own key.
137.10 Interview tips
- Kerberos flow: AS exchange (encrypted timestamp -> TGT), TGS exchange (TGT -> service ticket), AP exchange (ticket -> service).
- No password on the wire, tickets are time-limited, skew max 5 minutes.
- LDAP: tree of entries, DN, base + filter, bind types (anonymous, simple, SASL); 389 / 636.
- An AD DC = LDAP + Kerberos + DNS (+ time); clients find it through DNS.