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

Unattended

13 Apr 2019 · 8 min read · root access
Unattended — Hack The Box machine

Executive summary -- Unattended chains a 2-stage nested SQL injection that ends in a local file inclusion (LFI), session poisoning to turn the LFI into code execution as www-data, a cron job that executes a writable database value to pivot to the user guly, and finally a boot key derivable from the initramfs (readable by the grub group) that turns out to be root's password.

PlatformHack The Box
Operating systemLinux
DifficultyMedium
StatusRetired
Target IP<TARGET_IP>

Attack map

[443/HTTPS] www.nestedflanders.htb -- nginx -> internal Apache/PHP
   |  2-stage nested SQLi in index.php?id= (CWE-89)
   |  the final value ends up in include() = LFI
   v
[LFI]  read index.php (DB credentials) and a PHP config file
   |  cookies -> $_SESSION -> session file -> session poisoning
   v
[RCE]  www-data
   |  config table (id=86, checkrelease): guly's cron executes its value
   v
[RCE]  guly  (user.txt) -- persistent shell via a custom control channel
   |  guly in group grub -> can read /boot/initrd.img-*
   |  cryptroot reveals: /sbin/uinitrd <arg> prints the key (= root password)
   v
[ROOT]  su - with the recovered password (root.txt)

1. Reconnaissance

sudo nmap -p- --min-rate 2000 -T4 -Pn -oN scans/allports.txt <TARGET_IP>

Only two open ports, 80 and 443. There is no SSH exposed, so all post-exploitation has to go through HTTP(S).

sudo nmap -p80,443 -sCV -Pn -oN scans/svc.txt <TARGET_IP>
80/tcp  open  http     nginx 1.10.3
443/tcp open  ssl/http nginx 1.10.3
| ssl-cert: Subject: commonName=www.nestedflanders.htb/organizationName=Unattended ltd/...
|  Not valid before: 2018-12-19T09:43:58

Why it matters: the TLS certificate leaks the vhost www.nestedflanders.htb. Without that name, nginx does not serve the real application.

echo '<TARGET_IP> nestedflanders.htb www.nestedflanders.htb' | sudo tee -a /etc/hosts

On https://www.nestedflanders.htb/ there is a portfolio with links such as index.php?id=25, id=465 and id=587. nginx acts as a TLS proxy in front of an internal Apache/PHP on 127.0.0.1:8080.

🔒 Clearance required

Root Access unlocks the content you can't see — everything else on the site is already open.

See Root Access plans

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