Skip to content
Tutorials Center
My learning

Topics

Lesson 25 of 38 ยท Authentication: Kerberos

Kerberos Exchanges Step by Step: AS, TGS and AP

Follow the three Kerberos exchanges in Active Directory: AS-REQ and AS-REP, TGS-REQ and TGS-REP, then AP-REQ and AP-REP, with pre-authentication, the PAC and who can read each message.

Kerberos looks like magic until you see the actual messages. There are only three exchanges, each a request and a reply, and one rule explains everything: each message part is encrypted with a key that only the intended reader holds. If you know who holds which key, you can predict what every party can and cannot do, and you will understand most attacks and most errors.

The real protocol uses real cryptography; the example below is a deliberately simple toy that uses a hash-based stream cipher to show the structure. It is not secure and not Kerberos wire format. It is a stand-in so you can run the flow and see the key logic.

Exchange 1: AS-REQ and AS-REP (get a TGT)

  1. AS-REQ. The client sends its principal name and, in modern domains, pre-authentication data: the current timestamp encrypted with a key derived from the user's password. Pre-authentication (enabled by default since Windows Server 2003) means the KDC only answers someone who already knows the password. Without it, an attacker could request a reply for any user and crack it offline (AS-REP roasting, possible for accounts flagged Do not require Kerberos preauthentication).
  2. AS-REP. The KDC checks the timestamp against the user's key, which it holds. It returns two things:
    • The TGT, encrypted with the krbtgt key. The client cannot read it.
    • A session key for talking to the TGS, encrypted with the user's key. Only someone who knows the password can read it.

The TGT includes the PAC, the user's SID and group SIDs, signed by the KDC.

Exchange 2: TGS-REQ and TGS-REP (get a service ticket)

  1. TGS-REQ. The client sends the TGT, the name of the wanted service (an SPN such as cifs/files.example.com), and an authenticator: client name plus timestamp, encrypted with the TGS session key. This proves the sender holds the session key and is not replaying a stolen TGT.
  2. TGS-REP. The KDC decrypts the TGT with krbtgt's key, verifies the authenticator, finds the account that owns the SPN and returns:
    • The service ticket, encrypted with the service account's key.
    • A new service session key, encrypted with the TGS session key.

Note the attack consequence: anyone can request a service ticket for any SPN, and the ticket is encrypted with the service account's password-derived key. If that password is weak, the ticket can be cracked offline. This is Kerberoasting, discussed in errors and NTLM and hardening.

Exchange 3: AP-REQ and AP-REP (use the service)

  1. AP-REQ. The client sends the service ticket and a fresh authenticator (encrypted with the service session key) to the server.
  2. The server decrypts the ticket with its own key, learns the client name, group SIDs and the session key, and checks the authenticator.
  3. AP-REP (optional): the server returns the timestamp from the authenticator encrypted with the session key. Only a real service could have decrypted the ticket, so this gives mutual authentication.
sequenceDiagram
  participant C as Client
  participant K as KDC (domain controller)
  participant S as Service
  C->>K: AS-REQ (name, timestamp encrypted with user key)
  K->>C: AS-REP (TGT under krbtgt key, session key under user key)
  C->>K: TGS-REQ (TGT, SPN, authenticator)
  K->>C: TGS-REP (service ticket under service key, session key)
  C->>S: AP-REQ (service ticket, authenticator)
  S->>C: AP-REP (timestamp under session key)

Six messages complete one first-time access to a service; later accesses reuse cached tickets.

Who can read what

Item Encrypted with Readable by
Pre-auth timestamp User key KDC, user
TGT krbtgt key KDC only
TGS session key (in AS-REP) User key Client, KDC
Service ticket Service account key Service, KDC
Service session key (in TGS-REP) TGS session key Client, KDC
Authenticator Session key Whoever holds that session key

A toy implementation

The program below follows the three exchanges with a toy cipher built from SHA-256 and XOR. It shows that the client can open only what is meant for it and that a ticket for the wrong service fails to decrypt.

Python Toy Kerberos flow (insecure stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The line that says "client can read it?" prints None twice: the client holds the ticket but cannot open it. Only the KDC can read the TGT, and only the service can read the service ticket. That is the whole security model in two printed lines.

Cross-domain and cross-forest authentication

When a client in child.example.com wants a service in other.example.com, the KDC cannot issue a ticket for a service in another realm. Instead it returns a referral ticket (a TGT for the next domain along the trust path, encrypted with the shared inter-realm trust key). The client takes that to the other domain's KDC, which issues the real service ticket. Within a forest the trust path follows the domain tree transitively; across forests an explicit forest trust is required, and selective authentication can restrict who may cross it.

Other pieces worth knowing

  • PAC validation. A service may ask the KDC to verify the PAC signature, defending against tampering.
  • S4U extensions. Service-for-User protocols let a service obtain tickets on behalf of a user (the basis of constrained delegation, see SPNs and delegation).
  • FAST (Kerberos armoring) wraps the AS exchange in a protected channel so offline guessing of pre-auth data is harder.
  • Transport. Kerberos uses port 88 (UDP, falling back to TCP for large tickets) and kpasswd on 464 for password changes.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does Kerberos pre-authentication prove in the AS-REQ?

    The encrypted timestamp proves knowledge of the user's key, so the KDC does not hand out roastable replies to anonymous requesters.
  2. 2. The service ticket is encrypted with the key of which account?

    Only the service (and the KDC) can read the ticket; this is also why weak service account passwords are attackable offline.
  3. 3. Who can read the contents of the TGT?

    The TGT is opaque to the client; it is encrypted with the krbtgt key.
  4. 4. What gives the client confidence that the server is real (mutual authentication)?

    The server proves it could decrypt the service ticket by returning the authenticator timestamp under the session key.

Summary

  • Three exchanges: AS (TGT), TGS (service ticket), AP (use the service).
  • Each part is encrypted for exactly one reader: user key, krbtgt key, service key or a session key.
  • Pre-authentication blocks anonymous requests; weak service passwords allow Kerberoasting.
  • Cross-domain access uses referral tickets along the trust path.

Next: SPNs, Delegation and Managed Service Accounts