HTB Unclaimed Writeup — Best Complete Season 12 Medium Windows Machine

HTB Unclaimed Writeup - Season 12 Medium Windows Machine

Platform: Hack The Box    Season: 12    OS: Windows (Build 26100)    Difficulty: Medium    Creator: amra13579    Result: User + Root — 50th solver globally

Introduction

This HTB Unclaimed Writeup covers one of the most creative Medium-difficulty Windows machines in Hack The Box Season 12. What makes Unclaimed stand out is its realistic attack scenario: a corporate baggage-tracking chatbot backed by a live SQL Server — vulnerable to prompt injection, SQL impersonation, and ultimately a full system compromise via SeBackupPrivilege.

This walkthrough covers the complete attack chain, from initial recon to root flag, including a subtle binary decryption bug that tripped up many solvers. Whether you’re preparing for OSCP, studying for HTB Pro Labs, or just sharpening your Windows privilege escalation skills, this machine is worth studying carefully. For more HTB writeups and offensive security content, check out our Hack The Box category.

Machine Info: HTB Unclaimed | Windows Build 26100 | Created by amra13579

Attack Chain Overview

Prompt Injection
  → Hidden support override discovered
  → Arbitrary SQL execution via chatbot
  → Impersonate sysadmin login (svc_reports)
  → Enable xp_cmdshell
  → RCE as UNCLAIMED\svc_sql
  → User flag
  → Decrypt SQL Agent credential (DATALENGTH fix)
  → Authenticate as UNCLAIMED\svc_wtbackup
  → SeBackupPrivilege (Backup Operators)
  → Copy Administrator root.txt via backup semantics
  → Root flag

The machine chains together five distinct techniques — each one clean, well-integrated, and grounded in real-world misconfigurations. Let’s break it down.

01 — Reconnaissance

Starting this HTB Unclaimed Writeup, an initial port scan revealed a minimal but interesting attack surface:

PORT      STATE SERVICE
80/tcp    open  http
135/tcp   open  msrpc
139/tcp   open  netbios-ssn
445/tcp   open  microsoft-ds
5985/tcp  open  wsman

Key observations:

  • SMB signing was enforced — this immediately rules out NTLM relay attacks, saving time later.
  • Port 5985 (WinRM) — a strong hint that WinRM would be used for foothold or lateral movement.
  • HTTP on port 80 redirected to unclaimed.htb, exposing a customer-facing chatbot called TracerBot — a branded airline baggage service interface.

All user interactions went through a POST /ask endpoint in JSON format. This was the entry point.

02 — Prompt Injection

TracerBot converted user questions into SQL queries, supposedly in a read-only context. A simple instruction override in the message body was enough to break that boundary. This technique is documented in depth in OWASP’s LLM Top 10 under prompt injection vulnerabilities.

The injection payload asked the bot to reveal its full system prompt. The hidden instructions disclosed:

  • The underlying database was WorldTracer — a real-world baggage tracking system used by airlines.
  • Application tables: dbo.Flights, dbo.Passengers, dbo.PIR, dbo.BagEvents
  • A secret support override code — when included in a message, it lifted the read-only restriction and allowed arbitrary SQL to be executed directly via run_baggage_query.

This is the core lesson of this HTB Unclaimed Writeup: LLM-based interfaces that front databases are injection surfaces just like any web application. The “instruction layer” is simply another trust boundary — and it can be crossed.

The chatbot’s system prompt was both the attack vector and the treasure map.

03 — SQL Login Impersonation

Without the override, queries ran as svc_tracer_ro — a low-privilege, read-only SQL login. Using SQL metadata queries through the unlocked chatbot, an important discovery appeared:

svc_tracer_ro held IMPERSONATE permission over svc_reports, which was a member of the sysadmin server role.

EXECUTE AS LOGIN='svc_reports';
SELECT SUSER_SNAME()            AS login_name,
       IS_SRVROLEMEMBER('sysadmin') AS is_sysadmin;

Output confirmed sysadmin context. The SQL Server was now fully owned.

This technique — SQL login impersonation — is often overlooked during SQL Server enumeration. Always check fn_my_permissions and sys.database_permissions for IMPERSONATE grants.

04 — OS Command Execution via xp_cmdshell

With sysadmin rights, enabling xp_cmdshell is a one-liner:

EXECUTE AS LOGIN='svc_reports';
EXEC sp_configure 'show advanced options', 1; RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;         RECONFIGURE;
EXEC xp_cmdshell 'whoami';
-- Result: unclaimed\svc_sql

SQL Server was running as UNCLAIMED\svc_sql. To get an interactive shell, a UTF-16LE Base64-encoded PowerShell reverse shell was generated and executed through xp_cmdshell, opening a callback to the attack host.

05 — User Flag

The service account had a standard desktop profile. The user flag was a direct read:

EXEC xp_cmdshell 'type C:\Users\svc_sql\Desktop\user.txt';

✅ User flag captured.

06 — SQL Agent Proxy Discovery

Switching to Windows-integrated SQL authentication, SQL Agent job enumeration revealed a scheduled task with a linked proxy:

FieldValue
JobPIR Nightly Archive
StepExport PIR
SubsystemCmdExec
Proxy ID1018
ProxyWTArchiveProxy
CredentialWTArchiveCred
IdentityUNCLAIMED\svc_wtbackup

Checking the account’s group memberships:

net user svc_wtbackup
Local Group Memberships:   *Backup Operators   *Remote Management Users

Backup Operators + Remote Management Users = classic privilege escalation path. The road to root was clear — the missing piece was the credential. This privilege combination is well-documented in the PowerUpSQL Wiki and many Windows pentesting resources.

07 — Recovering the SQL Credential

The credential password was encrypted inside msdb. PowerUpSQL‘s Get-MSSQLCredentialPasswords was used for decryption — but the first attempt returned a truncated password.

Root cause: The decryption script used LEN() to measure the ciphertext length. LEN() stops counting at null bytes (0x00), truncating the final encrypted block.

The fix: Replace LEN() with DATALENGTH(), which measures raw binary length regardless of embedded null bytes.

-- Wrong:
SELECT LEN(credential_identity) FROM msdb.dbo.sysproxies

-- Correct:
SELECT DATALENGTH(credential_identity) FROM msdb.dbo.sysproxies

With the corrected query, the full ciphertext was recovered, and the decrypted UTF-16LE byte stream yielded the complete password.

Pro tip: when extracting binary credential blobs from MSSQL, DATALENGTH() is always the right choice over LEN().

08 — WinRM as svc_wtbackup

After the account lockout timer expired, the credential was validated:

nxc winrm 10.129.23.139 -u svc_wtbackup -p '<password>' --local-auth
# UNCLAIMED\svc_wtbackup (Pwn3d!)

An Evil-WinRM session confirmed the token carried SeBackupPrivilege and SeRestorePrivilege — both enabled.

09 — Root via SeBackupPrivilege

Members of the Backup Operators group can bypass NTFS ACLs using the Windows Backup API. The /B flag on robocopy requests backup semantics, allowing the copy to succeed regardless of file permissions:

robocopy /B C:\Users\Administrator\Desktop C:\Users\svc_wtbackup\Documents root.txt
New File    34    root.txt
Copied: 1 / Failed: 0
Get-Content C:\Users\svc_wtbackup\Documents\root.txt

✅ Root flag captured. Machine fully solved. This completes the full HTB Unclaimed Writeup attack chain.

No HTB Unclaimed Writeup would be complete without mentioning the rabbit holes.

Dead Ends Worth Noting

NetNTLMv2 Coercion: SQL Server was coerced into authenticating to the attack host via sys.dm_os_file_exists(), capturing a hash for UNCLAIMED\svc_sql. SMB relay was blocked (signing required), WinRM and RPC relay both failed, and exhaustive password cracking across multiple wordlists returned nothing. Useful for confirming the SQL Server’s OS identity, but it was a dead end for exploitation.

Anonymous Enumeration: SMB, RID cycling, and SAMR all returned access denied. Nothing useful was exposed unauthenticated beyond the hostname.

SQL Agent Execution Without a Proxy: A temporary SQL Agent job executed as NT SERVICE\SQLSERVERAGENT. Its token lacked SeImpersonatePrivilege and couldn’t access the C:\ProgramData\Bagtrace directory — no direct SYSTEM path there.

Key Takeaways

This HTB Unclaimed Writeup demonstrates a sophisticated attack chain that mirrors real-world corporate security failures. Here’s the full technique breakdown:

TechniqueDetail
Prompt InjectionLLM chatbot disclosed its own system prompt and an operator-only override
SQL ImpersonationEXECUTE AS LOGIN with pre-granted IMPERSONATE permission elevated to sysadmin
xp_cmdshellStandard sysadmin → OS execution path on SQL Server
Binary Credential ExtractionDATALENGTH() vs LEN() — critical when ciphertext contains null bytes
SeBackupPrivilegerobocopy /B bypasses NTFS ACLs via Windows Backup API

FAQ

Q: What is the main vulnerability in HTB Unclaimed?
The entry point in this HTB Unclaimed Writeup is a prompt injection attack against an LLM-backed chatbot. The injected instruction reveals a hidden operator override that unlocks arbitrary SQL execution, leading to full SQL Server compromise.

Q: How is xp_cmdshell used in this machine?
After escalating to sysadmin via SQL login impersonation (EXECUTE AS LOGIN='svc_reports'), xp_cmdshell is enabled through sp_configure. This converts SQL execution into OS-level command execution as the SQL Server service account.

Q: Why did the first credential decryption fail?
The decryption script used SQL’s LEN() function, which truncates at null bytes (0x00). The encrypted credential blob contained embedded null bytes in its final block. Switching to DATALENGTH() — which counts raw binary bytes — recovered the complete ciphertext and yielded the correct password.

Q: What is SeBackupPrivilege and how is it abused?
SeBackupPrivilege is a Windows token privilege granted to Backup Operators. It allows processes to bypass NTFS ACL checks when using backup-aware APIs. The robocopy /B flag explicitly requests this mode, allowing files to be copied regardless of their permissions — including Administrator-owned files like root.txt.

Q: Is this machine suitable for OSCP preparation?
Yes. The SQL Server exploitation chain (impersonation → xp_cmdshell) and the SeBackupPrivilege escalation path are both directly relevant to real-world assessments and appear in OSCP-style environments. The prompt injection vector adds an additional layer that reflects emerging attack surfaces in AI-integrated applications. See also our CTF Writeups for more similar machines.

If this HTB Unclaimed Writeup helped you understand the machine, consider sharing it with your study group. More HTB writeups and offensive security content are published regularly on The Cyber Track. Follow along on GitHub for tools and projects.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top