Adhyan Agarwal logoadhyan agarwal
BACK TO ARCHIVE
HTB|2023.02.25

Escape — MSSQL to Active Directory Certificate Services

OS

Windows

Difficulty

Medium

Category

AD

Released

2023.02.25

Pulled MSSQL creds from a public SMB share, coerced and cracked an NTLMv2 hash via xp_dirtree, recovered Ryan.Cooper's password from a SQL error log, then exploited a vulnerable AD CS template (ESC1) with Certipy to forge an administrator certificate.

Want to try this box yourself?

Spoiler-free mode is on by default — every solution stays hidden behind a reveal. Peek the hints, attempt each step, then unlock the answer when you're stuck. Turn it off to read every solution inline.

Nmap

SMB Enumeration

We use nxc smb to check whether anonymous login is enabled, and it is.

nxc confirming anonymous SMB login

The guest account is also enabled on the machine.

nxc confirming the guest account is enabled

We are able to enumerate shares using the guest account.

Guest account listing available SMB shares

We still cannot enumerate users using the guest account.

Guest account unable to enumerate domain users

Looking at the Public share, we find a file.

smbclient downloading SQL Server Procedures.pdf from the Public share

The downloaded file is a guide on how to access the SQL server. In it, we find credentials to access the server.

The PDF containing SQL server access credentials

We use a tool from the Impacket suite called impacket-mssqlclient.

Successful MSSQL login as PublicUser

Using the credentials above, the login is successful.

Looking around the server, we do not find anything interesting, and we do not have permission to execute any commands. However, we can coerce an NTLMv2 hash using the following command:

We catch this with Responder:

We successfully capture a hash.

Listening for events...

[SMB] NTLMv2-SSP Client   : 10.10.11.202
[SMB] NTLMv2-SSP Username : sequel\sql_svc
[SMB] NTLMv2-SSP Hash     : sql_svc::sequel:c5a35807c57c9f9a:FA5C289D6168211C9C3B6E38926EA8C7:01010000000000000058B8897E68DC01BC4B8B9C219A42EE00000000020008003200420045005A0001001E00570049004E002D003600390035004800530057003300350036004E00370004003400570049004E002D003600390035004800530057003300350036004E0037002E003200420045005A002E004C004F00430041004C00030014003200420045005A002E004C004F00430041004C00050014003200420045005A002E004C004F00430041004C00070008000058B8897E68DC0106000400020000000800300030000000000000000000000000300000E1F22364850FE6DD64F17710281D727E997B8D26CEF3F6BE7DF9D6C106AF24900A0010000000000000000000000000000000000009001E0063006900660073002F00310030002E00310030002E00310036002E0034000000000000000000

Responder capturing the sql_svc NTLMv2 hash

We use hashcat to crack the hash.

It successfully cracks.

SQL_SVC::sequel:c5a35807c57c9f9a:fa5c289d6168211c9c3b6e38926ea8c7:01010000000000000058b8897e68dc01bc4b8b9c219a42ee00000000020008003200420045005a0001001e00570049004e002d003600390035004800530057003300350036004e00370004003400570049004e002d003600390035004800530057003300350036004e0037002e003200420045005a002e004c004f00430041004c00030014003200420045005a002e004c004f00430041004c00050014003200420045005a002e004c004f00430041004c00070008000058b8897e68dc0106000400020000000800300030000000000000000000000000300000e1f22364850fe6dd64f17710281d727e997b8d26cef3f6be7df9d6c106af24900a0010000000000000000000000000000000000009001e0063006900660073002f00310030002e00310030002e00310036002e0034000000000000000000:REGGIE1234ronnie

Hashcat cracking the hash to reveal REGGIE1234ronnie

We validate the credentials.

nxc validating the sql_svc credentials

We successfully enumerate users using the sql_svc account.

nxc enumerating the nine domain users as sql_svc

We clean up the list.

Password spraying shows no other accounts using the same password.

Kerberoasting

Kerberoasting did not work.

Bloodhound Scan

We run a BloodHound scan:

BloodHound did not reveal anything interesting.

Initial Foothold

From the above scans, we did not find anything, so we try to use the credentials to get a shell and see if they work.

It works, and we get a shell as sql_svc.

evil-winrm shell as sql_svc

Enumerating the system, we find another user.

Enumeration revealing another user on the box

After this, we were stuck, so we used the guided mode on HTB to find the next step, which pointed to a password in a log file.

In the root directory, there is one interesting directory.

A non-standard SQLServer directory in the root

SQLServer is a non-standard directory.

In that directory, there is a logs directory.

A logs directory inside SQLServer

In the logs directory, there is a .bak file.

A .bak log file inside the logs directory

We download the file and look at it.

In it, we see a logon failure for the user Ryan.Cooper.

Another interesting detail is the entry NuclearMosquito3. This does not match the username policy, so we suspect it is a password.

2022-11-18 13:43:07.44 Logon       Logon failed for user 'sequel.htb\Ryan.Cooper'. Reason: Password did not match that for the login provided. [CLIENT: 127.0.0.1]
2022-11-18 13:43:07.48 Logon       Error: 18456, Severity: 14, State: 8.
2022-11-18 13:43:07.48 Logon       Logon failed for user 'NuclearMosquito3'. Reason: Password did not match that for the login provided. [CLIENT: 127.0.0.1]

We try that against every username.

We get a hit for the user Ryan.Cooper.

Ryan.Cooper authenticating with the recovered password

We can use evil-winrm to get a shell, and we obtain the user flag.

Privilege Escalation

WinPEAS does not show anything interesting, so we look at the Active Directory mindmap, and the next step is to enumerate ADCS.

Using the tool certipy-ad, we can enumerate ADCS:

Looking at the output, it may be vulnerable to ESC1, ESC2, and ESC3.

We will start with ESC1.

ESC1

Using the command from the wiki:

Then, using the following command, we get what seems to be an NTLMv2 hash:

We have an admin shell.

evil-winrm shell as administrator

The root flag is in the desktop directory.

Root flag on the administrator desktop