Kerberos Delegation: Unconstrained, Constrained and RBCD
A user opens an intranet web application on WEB01, and the application shows the user's files from FS01. To read those files as the user, the web server must authenticate to FS01 on the user's behalf. Kerberos calls that delegation, and AD offers three ways to allow it. They differ in one thing: how far the trust given to the front-end service reaches. Get it wrong and a single compromised web server can act as any user, including domain admins, against any service. This lesson models the three kinds, the ways each one is abused, the events that reveal it, and the settings that contain it.
The exchanges themselves are in Kerberos: AS, TGS and AP Exchanges.
The three kinds
| Kind | Configured on | How it works | What a compromised front end can do |
|---|---|---|---|
| Unconstrained | the front-end account: TRUSTED_FOR_DELEGATION (0x80000) |
clients send the front end a copy of their TGT inside the AP-REQ; the front end keeps it in memory and can request tickets for any service | act as every user who connects, to any service, for the TGT's lifetime |
| Constrained (S4U2Proxy) | the front-end account: msDS-AllowedToDelegateTo = list of SPNs |
the front end sends the KDC the user's service ticket and asks for a ticket to one listed SPN | act as connecting users, only to the listed SPNs |
| constrained with protocol transition (S4U2Self) | additionally TRUSTED_TO_AUTH_FOR_DELEGATION (0x1000000) |
the front end asks the KDC for a ticket to itself as any user, without the user authenticating, then uses S4U2Proxy | act as any user, without them connecting, to the listed SPNs |
| Resource-based (RBCD) | the back-end account: msDS-AllowedToActOnBehalfOfOtherIdentity = list of front-end accounts |
the back end says who may delegate to it | act as any user (S4U2Self + S4U2Proxy) to the back end |
Two protections apply to all kinds: an account marked "Account is sensitive and cannot be delegated" (NOT_DELEGATED, 0x100000) or a member of Protected Users is never delegated, and the KDC refuses.
A delegation model
The program encodes the lab's delegation settings and asks, for a compromised front end, which identities it can use against which services. It follows the KDC's rules above, simplified (it ignores ticket forwardability details and cross-domain cases).
accounts = {
"WEB01quot;: {"unconstrained": False, "allowed_to": ["cifs/fs01.corp.lab.test"], "protocol_transition": False},
"APP01quot;: {"unconstrained": False, "allowed_to": ["mssqlsvc/sql01.corp.lab.test"], "protocol_transition": True},
"PRINT01quot;: {"unconstrained": True, "allowed_to": [], "protocol_transition": False},
"FS01quot;: {"rbcd_from": ["WEB02quot;]}, # FS01 lets WEB02 delegate to it
"DC01quot;: {"rbcd_from": []},
}
services = {"cifs/fs01.corp.lab.test": "FS01quot;, "mssqlsvc/sql01.corp.lab.test": "SQL01quot;, "cifs/dc01.corp.lab.test": "DC01quot;}
users = {"alice": {"sensitive": False}, "it-admin": {"sensitive": False}, # it-admin: Domain Admins, not protected
"da-admin": {"sensitive": True}, "DC01quot;: {"sensitive": False}}
connected = {"WEB01quot;: ["alice"], "PRINT01quot;: ["alice", "DC01quot;]} # who authenticates to the front end
def reach(front):
a = accounts.get(front, {})
out = []
for spn, owner in services.items():
for user, u in users.items():
if u["sensitive"]:
continue # NOT_DELEGATED / Protected Users
if a.get("unconstrained") and user in connected.get(front, []):
out.append((user, spn, "unconstrained: holds the user's TGT"))
elif spn in a.get("allowed_to", []):
if a["protocol_transition"]:
out.append((user, spn, "constrained + protocol transition: user need not connect"))
elif user in connected.get(front, []):
out.append((user, spn, "constrained: only users who connect"))
elif front in accounts.get(owner, {}).get("rbcd_from", []):
out.append((user, spn, "RBCD: allowed by the back end"))
return out
for front in ["WEB01quot;, "APP01quot;, "PRINT01quot;, "WEB02quot;]:
rows = reach(front)
print(f"{front} can act as:")
for user, spn, why in rows:
print(f" {user:8} -> {spn:30} ({why})")
if not rows:
print(" nobody")
accounts["DC01quot;]["rbcd_from"].append("YOURPCquot;) # someone with write access on DC01's object
print("after a write to DC01's msDS-AllowedToActOnBehalfOfOtherIdentity:")
for user, spn, why in reach("YOURPCquot;):
print(f" {user:8} -> {spn}")WEB01$ can act as:
alice -> cifs/fs01.corp.lab.test (constrained: only users who connect)
APP01$ can act as:
alice -> mssqlsvc/sql01.corp.lab.test (constrained + protocol transition: user need not connect)
it-admin -> mssqlsvc/sql01.corp.lab.test (constrained + protocol transition: user need not connect)
DC01$ -> mssqlsvc/sql01.corp.lab.test (constrained + protocol transition: user need not connect)
PRINT01$ can act as:
alice -> cifs/fs01.corp.lab.test (unconstrained: holds the user's TGT)
DC01$ -> cifs/fs01.corp.lab.test (unconstrained: holds the user's TGT)
alice -> mssqlsvc/sql01.corp.lab.test (unconstrained: holds the user's TGT)
DC01$ -> mssqlsvc/sql01.corp.lab.test (unconstrained: holds the user's TGT)
alice -> cifs/dc01.corp.lab.test (unconstrained: holds the user's TGT)
DC01$ -> cifs/dc01.corp.lab.test (unconstrained: holds the user's TGT)
WEB02$ can act as:
alice -> cifs/fs01.corp.lab.test (RBCD: allowed by the back end)
it-admin -> cifs/fs01.corp.lab.test (RBCD: allowed by the back end)
DC01$ -> cifs/fs01.corp.lab.test (RBCD: allowed by the back end)
after a write to DC01's msDS-AllowedToActOnBehalfOfOtherIdentity:
alice -> cifs/dc01.corp.lab.test
it-admin -> cifs/dc01.corp.lab.test
DC01$ -> cifs/dc01.corp.lab.test
What the output says, one front end at a time:
WEB01$is the intended design: only users who connect, only to the file server.APP01$has protocol transition, so it can act as anyone (except protected accounts) to SQL01 without them ever connecting. If SQL01 trusts that identity for admin work, compromising APP01 is compromising SQL01.PRINT01$has unconstrained delegation, andDC01$connected to it, so PRINT01 holds a DC's TGT, which carries replication rights. In real attacks the DC is made to connect by coercion (asking the DC's Print Spooler or another RPC service to authenticate to the attacker's machine; NTLM Relay, Coercion and Signing), and the captured TGT is then used for DCSync. This is why unconstrained delegation outside DCs is a critical finding.WEB02$is trusted by FS01 through RBCD.- The last lines show the RBCD abuse: anyone who can write the attribute on a computer object, and who controls some account with an SPN, can make that account trusted for delegation to it. Any domain user can create such an account by default, because
ms-DS-MachineAccountQuotalets every user join up to 10 computers. The attacker then acts as any non-protected user against that machine: in the model that includesit-admin, a domain admin nobody marked sensitive, so the result is administrative access to DC01. Write access on computer objects is common: whoever joined the machine to the domain owns its object.
da-admin appears nowhere because it is marked sensitive, while it-admin, also a domain admin, appears wherever protocol transition or RBCD is involved. That one flag removes an admin from every delegation scenario above.
How it is detected
- Configuration: the LDAP audit queries for
TRUSTED_FOR_DELEGATION(excluding DCs),TRUSTED_TO_AUTH_FOR_DELEGATIONand non-emptymsDS-AllowedToDelegateTo/msDS-AllowedToActOnBehalfOfOtherIdentity; attack-path tools draw these as edges. - Changes: 5136 on
msDS-AllowedToActOnBehalfOfOtherIdentity(any write outside a change ticket is an alert), onmsDS-AllowedToDelegateToand onuserAccountControladding the delegation bits; 4742 (computer account changed) and 4738 (user account changed) show the same fields. - New computer accounts created by ordinary users: 4741 where the creator isn't a provisioning account or the help desk.
- S4U in use: 4769 with a populated
Transited Servicesfield (S4U2Proxy), and 4769 where the requesting account and the service are the same account with the client being another user (S4U2Self). Baseline the front ends that legitimately do this. - Unconstrained hosts receiving DC TGTs: 4624 on a non-DC host for a DC computer account (
DC01$) logging on over the network, especially right after a remote RPC call to the DC's spooler.
How it is fixed or prevented
- No unconstrained delegation outside domain controllers. Replace it with constrained delegation or RBCD to the exact services needed.
- Avoid protocol transition unless the application really needs it (for example non-Kerberos front-end authentication); then list as few SPNs as possible.
- Mark every privileged account sensitive and cannot be delegated, and add admins to Protected Users.
- Set
ms-DS-MachineAccountQuotato 0 and give machine-join rights to a dedicated group; remove write rights on computer objects from the users who joined them. - Disable the Print Spooler on DCs and servers that don't print; patch and block coercion paths.
- Enable the "no TGT delegation across forest trusts" setting (default on current systems).
Pitfalls
- Forgetting computer accounts. Delegation is configured mostly on computer accounts; reviews that only list users miss it.
- Treating RBCD as "safer" by default. It is safer only if writes to the attribute are controlled; a single GenericWrite on a server object is enough.
- Sensitive flag without Protected Users still allows NTLM and cached credentials for the admin; use both.
- Leaving old
msDS-AllowedToDelegateToentries for decommissioned services that might be re-created by someone else.
Practice
1. Why does marking DC01$ itself "sensitive" not make sense, and what protects DC TGTs instead?
Computer accounts of DCs must authenticate normally; the protection is to have no unconstrained delegation outside DCs (so no host can hold their TGTs) and to block coercion. Some organisations also add DC accounts to restrictions on where they may authenticate.
2. In the model, remove protocol_transition from APP01. Who can APP01 act as now?
Nobody, because no user connects to APP01 in the connected table; with plain constrained delegation it can only forward users who authenticate to it.
3. A 5136 shows msDS-AllowedToActOnBehalfOfOtherIdentity written on FS01$ by bob, a minute after a 4741 created YOURPC$ by bob. What happened and what do you do?
The two steps of RBCD abuse against FS01. Remove the attribute value and the new computer account, check 4769 for S4U requests from YOURPC$, reset credentials that may have been used on FS01, find where bob's write right on FS01 came from, and set the machine account quota to 0.
Test yourself
With unconstrained delegation, what does a client send to the front-end service?
- Its password
- A copy of its TGT
- Only a service ticket
- Nothing
Where is resource-based constrained delegation configured?
- On the front-end account (msDS-AllowedToDelegateTo)
- On the back-end resource (msDS-AllowedToActOnBehalfOfOtherIdentity)
- In the krbtgt account
- In DNS
Which setting makes an account immune to all forms of delegation?
- DONT_EXPIRE_PASSWORD
- 'Account is sensitive and cannot be delegated' (or Protected Users membership)
- SMARTCARD_REQUIRED
- adminCount=1
What is the default ms-DS-MachineAccountQuota, and why does it matter for RBCD abuse?
- 0; it doesn't matter
- 10; any user can create computer accounts with SPNs to use as the delegating account
- 100; for performance
- 1; only admins