githubEdit

Resource-Based Constrained Delegation (RBCD)

Resource-Based Constrained Delegation (RBCD)

Object: msDS-AllowedToActOnBehalfOfOtherIdentity

Tools: rbcd.py , rubeus.exe , getST , addcomputer.py

With RBCD, this is the resource machine (the machine that receives delegation) which has a list of services that can delegate to it. This list is specified in the attribute msds-allowedtoactonbehalfofotheridentity and the computer can modified its own attribute (really usefull in NTLM relay attack scenario).

Requirements

  1. The DC has to be AT LEAST a Windows Server 2012 and later

  2. Domain users can create some machine, ms-ds-machineaccountquota MUST NOT be 0!

  3. GenericAll or GenericWrite on Domain Controller

To verify

Get-DomainObject -Identity "dc=domain,dc=local" -Domain domain.local

3) Write rights on the target machine (GenericAll, GenericWrite, AllExtendedRights)

  1. Target computer, object must NOT have the attribute msds-allowedtoactonbehalfofotheridentity set

    Get-NetComputer ws01 | Select-Object -Property name, msds-allowedtoactonbehalfofotheridentity

Standard RBCD

The attacker has compromised ServiceA and wants to compromise ServiceB. He also has sufficient rights to configure msds-allowedtoactonbehalfofotheridentity on ServiceB.

1) Add RBCD from ServiceA to ServiceB

2) Verify property

3) Get ServiceA TGT and then S4U

Linux

1) Add RBCD from ServiceA to ServiceB

2) Verify property

###Get ServiceA TGT and then S4U

With machine account creation

1) Add a fake machine account in the domain

2) Add it to the msds-allowedtoactonbehalfofotheridentity attribute of the target machine

Creds if needed, to run as another user

Check requirements

Add the fake machine as a resource + get its SID

Create the new raw security descriptor

Add the new raw SD to msds-allowedtoactonbehalfofotheridentity

Check if well added

Linux

Create a new Machine Account

Set the msDS-AllowedToActOnBehalfOfOtherIdentity on our new machine account

Get the Administrator service ticket

Authenticate with psexec

3) Use the S4USelf function with the fake machine (on an arbitrary SPN) to create a forwardable ticket for a wanted user (not protected)

4) Use the S4UProxy function to obtain a ST for the impersonated user for the wanted service on the target machine

Calculate hash

S4U attack

Skip S4U2Self

Attacker has compromised Service A, has sufficient ACLs against Service B to configure RBCD, and wants to attack Service B By social engineering or any other solution, an interesting victim authenticates to Service A with a ST Attacker dumps the ST on Service A (sekurlsa::tickets) Attacker configures RBCD from Service A to Service B as above Attacker performs S4UProxy and bypass S4USelf by providing the ST as evidence

Linux

Reflective RBCD

With a TGT or the hash of a service account, an attacker can configure an RBCD from the service to itself, a run a full S4U to access the machine on behalf of another user.

Linux

Impersonate protected user via S4U2Self request

It is possible to impersonate a protected user with the S4USelf request if we have a TGT (or the creds) of the target machine (for example from an Unconstrained Delegation).

With the target TGT it is possible to realise a S4USelf request for any user and obtain a ST for the service. In case where the needed user is protected against delegation, S4USelf will still work, but the ST is not forwardable (so no S4UProxy possible) and the specified SPN is invalid...however, the SPN is not in the encrypted part of the ticket. So it is possible to modify the SPN and retrieve a valid ST for the target service with a sensitive user (and the ST PAC is well signed by the KDC).

Linux

Bypass Constrained Delegation restrictions with RBCD

Attacker compromises ServiceA and ServiceB ServiceB is allowed to delegate to time/ServiceC (the target) without protocol transition (no S4USelf) Attacker configures RBCD from ServiceA to ServiceB and performs a full S4U attack to obtain a forwardable ST for the Administrator to ServiceB Attacker reuses this forwardable ST as evidence to realise a S4UProxy attack from ServiceB to time/ServiceC Since the service is not protected in the obtained ticket, the attacker can change the ST from the previous S4UProxy execution to cifs/ServiceC

RBCD from A to B

S4UProxy from B to C with the obtained ST as evidence

Linux

RBCD from A to B

S4UProxy from B to C with the obtained ST as evidence

U2U RBCD with SPN-less accounts

In case where you have sufficient rights to configure an RBCD on a machine (for example with an unsigned authentication coerce via HTTP) but ms-ds-machineaccountquota equals 0, there is no ADCS with the HTTP endpoint and the Shadow Credentials attack is not possible (domain level to 2012 for example), you can realize a RBCD from a SPN-less user account.

1) Configure the machine account to trust the user account you control (NTLM Relay, with the machine account's creds,...)

2) Obtain a TGT for the user via pass-the-hash:

3) Request a Service Ticket via U2U (S4USelf request) with the previous TGT specified in /tgs: (additional ticket added to the request body identifying the target user account) and /ticket: (authentication). If U2U is not used, the KDC cannot find the account's LT key when a UPN is specified instead of a SPN. The account to impersonate via the future S4U request is also present:

4) Retrieve the TGT session key in HEX format

6) Now, change the user's long term key (his RC4 NT hash actually) to be equal to the TGT session key. The ST sent in the S4UProxy is encrypted with the session key, but the KDC will try to decipher it with the user's long term key, this is why the LT key must be equal to the session key (WARNING !!! The user's password is now equal to an unknown value, you have to use a sacrificial account to realise this attack).

7) Realize the S4UProxy request with the previous S4USelf U2U ticket (ciphered with the session key) as additional ticket and the original TGT as ticket:

8) Finally, use this ticket to do whatever you want!

Linux

1) Configure the machine account to trust the user account you control (NTLM Relay, with the machine account's creds,...). Obtain a TGT for the user via pass-the-hash and extract the session key from it with this

2) ow, change the user's long term key (his RC4 NT hash actually) to be equal to the TGT session key. The ST sent in the S4UProxy will be encrypted with the session key, but the KDC will try to decipher it with the user's long term key, this is why the LT key must be equal to the session key (WARNING !!! The user's password is now equal to an unknown value, you have to use a sacrificial account to realise this attack).

3) Realize the S4USelf request with a U2U request. If U2U is not used, the KDC cannot find the account's LT key when a UPN is specified instead of a SPN. Then, use the ticket obtained in the U2U S4USelf request (ciphered with the session key), to perform a S4UProxy request.

Finally, use the obtained ST to dump the machine LSA and SAM registers with secretsdump.

RBCD from MSSQL Server

If we have sufficient access to a MSSQL server we can use the xp_dirtree in order to leak the Net-NTLM hash of the machine account. Additionally, the Web Service client must be running on the machine in order to trick the authentication from SMB to HTTP and avoid the NTLM signature (authentication must be sent to @80):

1) Create a DNS record in order to be able to leak the NTLM hash externally

2) Use the xp_dirtree (or xp_fileexist) function to the created DNS record on @80. This will force the authentication and leak the hash

3) Relay the machine hash to the LDAP server to add a controlled account (with a SPN for the further S4USelf request) to the msDS-AllowedToActOnBehalfOfOtherIdentity of the target machine

4) Now we can ask a ST for a user we want to impersonate for a service on the machine

Add the DNS

On our machine, waiting for the leak

#https://gist.github.com/3xocyte/4ea8e15332e5008581febdb502d0139c

ON the MSSQL server

After the attack, ask for a ST with full S4U

Linux

Add the DNS

On our machine, waiting for the leak

#https://gist.github.com/3xocyte/4ea8e15332e5008581febdb502d0139c

ON the MSSQL server

After the attack, ask for a ST with full S4U

1) addcomputer.py

2) Rubeus

3) rbcd.py

4) Powermad

Create a new raw security descriptor for the FAKE01 computer principal

Apply the security descriptor bytes to the target machine

Then use Rubeus or getST to impersonate an account on our target computer of our choice

Last updated