root@thehacksparrow:~/writeups$ SYSTEM ONLINE
root@sparrow:~/writeups$ cat lightweight.md
// writeups

Lightweight

8 Dec 2018 · 17 min read · root access
Lightweight - maquina de Hack The Box

Executive summary — Lightweight is an exercise in plaintext OpenLDAP combined with Linux capabilities as a privilege primitive. Initial access requires guessing no credential at all: the web application itself provisions an SSH account whose username and password are the visitor's IP address. From there, a tcpdump binary carrying cap_net_raw allows sniffing the LDAP bind the web app performs on every page load, leaking a service account's password in the clear; an encrypted backup in its home directory reveals the source code that in turn leaks a second user's credential, and that user owns a copy of openssl with every capability — including cap_setuid — enough to run arbitrary code as root through a malicious engine.

PlatformHack The Box
Operating systemCentOS 7 (Linux)
DifficultyMedium
StatusRetired
Target IP10.129.95.236

Attack map

[HTTP] user.php creates an SSH account -- username=password=<YOUR_IP>
   |
   v
[SSH] low-privilege shell -- tcpdump has cap_net_raw without being root
   |  sniffs 389/loopback while status.php performs a bind
   v
[LDAP] plaintext simple bind captured -> ldapuser2 : 8bc8251332abe1d7f105d3e53ad39ac2
   |  su ldapuser2 -> user.txt + backup.7z (7zAES, password "delete" via rockyou)
   v
[backup.7z] status.php source leaks ldapuser1's credential
   |  su ldapuser1
   v
[CAPABILITIES] custom openssl with "=ep" (incl. cap_setuid) -> malicious .so engine
   v
[ROOT] setuid(0) in the engine's constructor -> SUID bash -> root.txt

1. Reconnaissance

The response TTL (63, i.e. 64 minus one hop) points at Linux before touching a single service.

sudo nmap -p- --min-rate 3000 -T4 -Pn -oN nmap-allports.txt 10.129.95.236

Only three open ports, but one of them is unusual for a Linux box:

PortServiceNote
22OpenSSH 7.4Standard
80Apache 2.4.6 (CentOS, PHP/5.4.16)"Lightweight slider evaluation page"
389OpenLDAP 2.2.X–2.3.XThe directory service, exposed straight to the outside — the pivot point of the whole box
sudo nmap -p22,80,389 -sCV -Pn -oN nmap-services.txt 10.129.95.236
22/tcp  ssh   OpenSSH 7.4
80/tcp  http  Apache 2.4.6 ((CentOS) ... PHP/5.4.16) — title: "Lightweight slider evaluation page - slendr"
389/tcp ldap  OpenLDAP 2.2.X - 2.3.X
| ssl-cert: Subject: commonName=lightweight.htb

Every other port answers host-prohibited — the signature of firewalld on RHEL/CentOS, and, as it turns out shortly, a firewall that does more than just filter ports.

echo "10.129.95.236 lightweight.htb" | sudo tee -a /etc/hosts
🔒 Clearance required

This content is Root Access only. Everything else on the site — the free tier, the whole public library — stays open.

See Root Access plans

No account? Create one free then upgrade from your console.