SkillPilotAI

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).
LDAP: Wiki app logs Asha in
  1. 1.Asha logs in to the Wiki app

  2. 2.Wiki sends bindRequest to LDAP server 192.168.157.10:389: dn uid=asha,ou=people,... + password (simple)

  3. 3.Server replies bind success

  4. 4.searchRequest base dc=lab,dc=local, filter (uid=asha), attrs cn mail title

  5. 5.Server returns Asha's entry: name, mail, title

137.3 Lab: OpenLDAP and ldapsearch

Terminal
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.ldif
Output
adding 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"
Terminal
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)'
Output
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

Terminal
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
Output
.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

Kerberos: TGT, service ticket, AP-REQ
  1. 1.AS-REQ to KDC 192.168.157.10:88: asha@LAB.LOCAL, pre-auth = timestamp encrypted with the password (no password sent)

  2. 2.AS-REP: TGT for krbtgt/LAB.LOCAL, valid 10 hours, + session key

  3. 3.TGS-REQ: show TGT + authenticator, want host/srv.lab.local

  4. 4.TGS-REP: service ticket encrypted with the file server's own key

  5. 5.AP-REQ: laptop hands the service ticket to srv.lab.local

  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)

ExchangeMessagesResult
AS (Authentication Service)AS-REQ / AS-REPTGT (Ticket Granting Ticket)
TGS (Ticket Granting Service)TGS-REQ / TGS-REPService ticket for one service
AP (Application)AP-REQ (/ AP-REP)Access to the service

137.6 Lab: MIT Kerberos, kinit, klist, kvno

Terminal
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.localklist
Output
Principal "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.LOCAL
Terminal
tshark -r /tmp/krb.pcap -Y kerberos \  -T fields -e ip.src -e ip.dst -e _ws.col.Info
Output
192.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).
Terminal
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.local
Output
real 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 = 1

137.8 Active Directory: DC = LDAP + Kerberos + DNS

Logging in to an AD domain
  1. 1.Office laptop pc1.lab.local asks DNS (53): where is the DC for lab.local?

  2. 2.Gets a TGT from Kerberos on DC01 (88)

  3. 3.Reads groups and policies from LDAP on DC01 (389)

  4. 4.Opens the file server: service ticket, file server (domain member) trusts the same DC

  5. 5.Time stays in sync with the DC via NTP (123)

Service on the DCPortJob
DNS53Find the DC (SRV records)
Kerberos88TGT and service tickets
LDAP / LDAPS389 / 636Users, groups, computers, policies
NTP123Time sync for Kerberos
Terminal
klist purgeklist get http/iisserver.contoso.com
Output
A 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.