June 6, 2024HackTheBoxWindowsHardIDORMSSQLRBCD 15 min read
Freelancer starts with gaining access as an employer, then escalating to admin via an IDOR vulnerability in the QR-Code OTP login flow. From there, a SQL terminal exposes MSSQL commands allowing impersonation of sa and enabling xp_cmdshell for a reverse shell. After pivoting through users via credential files and a memory dump, the path to Domain Admin goes through Resource-Based Constrained Delegation (RBCD).
Full port scan reveals a Windows domain controller. Notable: MSSQL on port 55297 and WinRM on 5985.
nmap
SP1R4@kali)-[~]└$ nmap -sC -sV -p- -oN nmap_results.txt 10.129.159.108PORT STATE SERVICE VERSION
53/tcp open domain Simple DNS Plus
80/tcp open http nginx 1.25.5
88/tcp open kerberos-sec Microsoft Windows Kerberos
135/tcp open msrpc Microsoft Windows RPC
389/tcp open ldap Microsoft Windows Active Directory LDAP
445/tcp open microsoft-ds?
5985/tcp open http Microsoft HTTPAPI httpd 2.0
55297/tcp open ms-sql-s Microsoft SQL Server 2019 15.00.2000.00
| DNS_Domain_Name: freelancer.htb
| DNS_Computer_Name: DC.freelancer.htb
Service Info: Host: DC; OS: Windows
RPC & SMB — Access Denied
rpcclient / smbclient
SP1R4@kali)-[~]└$ rpcclient -U "" -N 10.10.11.5rpcclient $> enumdomusers
result was NT_STATUS_ACCESS_DENIEDSP1R4@kali)-[~]└$ smbclient -L 10.10.11.5Anonymous login successful
Unable to connect with SMB1 -- no workgroup available
Website — TCP 80
The site is a job board platform with Freelancer and Employer registration.
Register as a freelancer first. Nothing useful found when enumerating as freelancer.
Register as an employer next — but login fails immediately after registration:
Account recovery bypass
Use the Account Recovery form. The security questions accept trivially guessable answers (all set to the same value during registration). This reactivates the account and allows a password reset:
Now inside as employer bob:
IDOR — Insecure Direct Object Reference
QR-Code section
The QR-Code menu item generates an OTP login URL. Scanning reveals the token encodes the current user's numeric ID in base64:
OTP URL format: http://freelancer.htb/accounts/login/otp/<base64_uid>/<token>
Replacing the base64 value with any other user's encoded ID logs in as that user — classic IDOR.
Escalating to admin
Browse blog comments to find the admin username. Profile URL enumeration confirms admin has ID 2. Encode it: echo -n "2" | base64 → Mg==.
IDOR payload
# bob (ID 10011)http://freelancer.htb/accounts/login/otp/MTAwMTE=/e4ff26...# admin (ID 2)http://freelancer.htb/accounts/login/otp/Mgo=/e4ff26...
/admin — SQL Terminal
The admin panel exposes a SQL Terminal under Development Tools:
PS C:\Users\mikasaAckerman\Desktop> type mail.txt
Hello Mikasa,
Liza has requested me to generate a full memory dump on the DC.
The file is on the Desktop.
A memory dump (MEMORY.7z) is on the Desktop. Extract it, run Mimikatz to isolate lsass.exe, then extract lorra199's password from the SAM:
AD Recycle Bin has GenericWrite on the Domain Controller DC$:
GenericWrite on DC$ enables RBCD abuse — we can set the msDS-AllowedToActOnBehalfOfOtherIdentity attribute and impersonate any user including Administrator.