LDAP and Kerberos on the Wire
In a Windows domain (and in many Linux and application environments) two protocols answer the questions "who is this user?" and "may they log in?": LDAP reads and writes the directory, and Kerberos proves identity with tickets. They are the backbone of Active Directory, which makes them the most valuable traffic on an internal network for attackers and defenders alike. This lesson stays at the network level: what each protocol puts on the wire, which settings make it safe or unsafe, and what to log. The attacks that use them (Kerberoasting, AS-REP roasting, relay, delegation abuse) are taught in depth in Windows and Active Directory Security.
LDAP
LDAP (RFC 4511) runs on TCP 389, or 636 for LDAPS (TLS from the start); 3268/3269 are the AD global catalog. Messages are encoded in ASN.1 BER: every element is a tag byte, a length, and a value. A client authenticates with a bind:
- anonymous bind: no credentials; some directories allow reading parts of the tree this way;
- simple bind: a distinguished name and a password, in cleartext unless the connection is protected by TLS;
- SASL bind (GSSAPI/Kerberos, NTLM): no password on the wire, and optional signing and sealing (integrity and encryption).
The program builds a simple bind request exactly as it would appear on port 389, then decodes it with a small BER reader, which is what a sensor (or an attacker with a capture) does.
def tlv(tag, value):
n = len(value)
length = bytes([n]) if n < 128 else bytes([0x81, n])
return bytes([tag]) + length + value
dn, password = b"cn=lab-user,ou=staff,dc=lab,dc=test", b"lab-only-pw"
bind = tlv(0x60, tlv(0x02, b"\x03") + tlv(0x04, dn) + tlv(0x80, password)) # [APPLICATION 0] BindRequest
message = tlv(0x30, tlv(0x02, b"\x01") + bind) # LDAPMessage, messageID 1
print("on the wire:", message.hex(" "))
def read(buf, off=0):
tag, n = buf[off], buf[off + 1]
off += 2
if n & 0x80:
k = n & 0x7F
n = int.from_bytes(buf[off:off + k], "big"); off += k
return tag, buf[off:off + n], off + n
_, body, _ = read(message)
_, msgid, off = read(body)
tag, req, _ = read(body, off)
_, ver, p = read(req)
_, name, p = read(req, p)
auth_tag, auth, _ = read(req, p)
kind = {0x80: "simple (cleartext password)", 0xA3: "SASL"}[auth_tag]
print(f"messageID {msgid[0]}, BindRequest (tag 0x{tag:02x}), version {ver[0]}")
print("bind DN:", name.decode())
print("authentication:", kind, "->", auth.decode())on the wire: 30 3a 02 01 01 60 35 02 01 03 04 23 63 6e 3d 6c 61 62 2d 75 73 65 72 2c 6f 75 3d 73 74 61 66 66 2c 64 63 3d 6c 61 62 2c 64 63 3d 74 65 73 74 80 0b 6c 61 62 2d 6f 6e 6c 79 2d 70 77
messageID 1, BindRequest (tag 0x60), version 3
bind DN: cn=lab-user,ou=staff,dc=lab,dc=test
authentication: simple (cleartext password) -> lab-only-pw
The password is right there after the 80 0b (context tag 0, 11 bytes). On a network where LDAP simple binds go over 389, every application server that checks a user's password against the directory is broadcasting it.
Detecting and fixing LDAP problems
- Detection: LDAP simple binds on 389 in IDS or Zeek's LDAP analyser; on Windows domain controllers, Directory Service event 2889 lists clients that performed unsigned SASL or cleartext simple binds (after enabling the diagnostic logging), and event 2887 summarises them daily; anonymous binds that read user lists; large LDAP queries for all users, groups and service principal names from a workstation (directory reconnaissance).
- Fix: LDAPS or StartTLS for every simple bind (or SASL/Kerberos instead); require LDAP signing and channel binding on domain controllers, which also stops NTLM relay to LDAP; disable anonymous access beyond the root DSE; give service accounts only the read rights they need.
Kerberos
Kerberos (RFC 4120) runs on TCP and UDP 88. A user never sends a password; instead the key distribution center (KDC, the domain controller in AD) hands out tickets encrypted with keys derived from passwords:
| Step | Message | What is encrypted with which key |
|---|---|---|
| 1 | AS-REQ (with pre-authentication: a timestamp encrypted with the user's key) | proves the user knows the password without sending it |
| 2 | AS-REP | the TGT, encrypted with the KDC's own key (krbtgt); a session key for the user, encrypted with the user's key |
| 3 | TGS-REQ | the TGT plus an authenticator, asking for a service ticket for an SPN such as cifs/fs1.lab.test |
| 4 | TGS-REP | the service ticket, encrypted with the service account's key |
| 5 | AP-REQ | the client presents the service ticket to the service |
The program models the checks a KDC makes on step 1, including the clock-skew limit (5 minutes by default), which exists because timestamps are what stop replay.
from datetime import datetime, timedelta
MAX_SKEW = timedelta(minutes=5)
kdc_now = datetime(2026, 1, 15, 10, 0, 0)
users = {"alice": {"preauth": True, "enc": "aes256-cts"}, "svc-legacy": {"preauth": False, "enc": "rc4-hmac"}}
def as_req(user, client_time, knows_password=True):
u = users[user]
if u["preauth"]:
if not knows_password:
return "KDC_ERR_PREAUTH_FAILED (event 4771)"
if abs(client_time - kdc_now) > MAX_SKEW:
return "KRB_AP_ERR_SKEW: clock skew too great"
note = "" if u["preauth"] else " <- no pre-auth: anyone can request this AS-REP (AS-REP roasting risk)"
weak = " <- RC4 ticket encryption" if u["enc"] == "rc4-hmac" else ""
return f"AS-REP with TGT, etype {u['enc']} (event 4768){note}{weak}"
print("alice, clock ok: ", as_req("alice", kdc_now + timedelta(seconds=40)))
print("alice, clock 7 min off: ", as_req("alice", kdc_now + timedelta(minutes=7)))
print("alice, wrong password: ", as_req("alice", kdc_now, knows_password=False))
print("svc-legacy, nobody: ", as_req("svc-legacy", kdc_now, knows_password=False))alice, clock ok: AS-REP with TGT, etype aes256-cts (event 4768)
alice, clock 7 min off: KRB_AP_ERR_SKEW: clock skew too great
alice, wrong password: KDC_ERR_PREAUTH_FAILED (event 4771)
svc-legacy, nobody: AS-REP with TGT, etype rc4-hmac (event 4768) <- no pre-auth: anyone can request this AS-REP (AS-REP roasting risk) <- RC4 ticket encryption
What the two flagged lines mean, briefly (the details are in the Windows course): parts of the AS-REP and the TGS-REP are encrypted with keys derived from account passwords, so whoever obtains them can try to guess those passwords offline. Without pre-authentication anyone can get an AS-REP for that account; any domain user can request a service ticket for any SPN. Weak service-account passwords and RC4 encryption make the guessing fast.
The Kerberos lab shows the whole exchange the table describes, plus the AP-REP, with each encrypted part coloured by its key. This setting matches the svc-legacy line: pre-authentication off and RC4 tickets, with the AS-REP roasting marker at message 2 (4768, pre-authentication type 0) and Kerberoasting rated "easy (RC4)". Turn pre-authentication on and AES tickets to see what the fixes below change.
Detecting and fixing Kerberos problems
- Detection: on domain controllers, 4768 (TGT requested), 4769 (service ticket requested), 4771 (pre-auth failed). Patterns: one account requesting service tickets for many SPNs in a short time, tickets requested with RC4 (
0x17) in an AES-only domain, AS-REQs for accounts without pre-authentication, bursts of 4771 (password guessing). On the wire, Zeek'skerberos.logrecords the client, service and cipher. - Fix: AES only (disable RC4 where possible); pre-authentication required for every account; long random passwords for service accounts, ideally group managed service accounts (gMSA) with long random passwords rotated automatically; synchronised clocks (NTP) everywhere; protect and periodically rotate the
krbtgtkey.
Pitfalls
- Allowing LDAP simple binds "only internally". Internal networks are where attackers spend their time after the first foothold.
- Treating Kerberos as encrypted transport. It authenticates; the application protocol still needs signing or encryption (SMB signing, LDAP sealing).
- Forgetting time. A domain whose clocks drift breaks Kerberos, and the "fix" of raising the skew limit weakens replay protection.
Practice
1. In the BER dump, what do the bytes 02 01 03 after 60 … mean?
An INTEGER (tag 02), length 1, value 3: the LDAP protocol version.
2. Why does a simple bind over LDAPS not have the problem shown above?
The same BER bytes travel inside TLS, so an observer sees only encrypted records. The server still receives the password in clear (it must check it), so the server and the client must be trusted.
3. In the Kerberos model, why is the 7-minute clock difference rejected even though the password is right?
Pre-authentication proves knowledge of the key with an encrypted timestamp. If old timestamps were accepted, a captured AS-REQ could be replayed later; the skew window limits how old one may be.
Test yourself
What does an LDAP simple bind over port 389 expose?
- Nothing; LDAP encrypts binds
- The bind DN and the password in cleartext
- Only the user's group membership
- The Kerberos TGT
Which key encrypts a Kerberos service ticket?
- The user's key
- The service account's key
- The client's TLS key
- No key; it is signed only
What stops replay of a captured Kerberos pre-authentication timestamp?
- DNSSEC
- The KDC's clock-skew limit (5 minutes by default) and replay caches
- SMB signing
- The TCP checksum
Which domain controller setting also stops NTLM relay to LDAP?
- Anonymous bind
- LDAP signing and channel binding
- Port 3268
- RC4 encryption
In the Kerberos lab, you set pre-authentication to required. What happens to AS-REP roasting?
- Nothing changes
- It is blocked: an AS-REQ without pre-authentication gets KDC_ERR_PREAUTH_REQUIRED
- It becomes Kerberoasting
- It only works with RC4