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

Monitored

13 Jan 2024 · 29 min read · root access
Monitored - maquina de Hack The Box

Executive summary — Monitored chains a public SNMP community with no view attached that leaks service credentials through the process table, an inconsistent authorization flaw in Nagios XI (the authentication API doesn't check the enabled flag that the web login does check), and CVE-2023-40931 — a time-based blind SQL injection — to steal nagiosadmin's API key, create an admin user and get RCE by abusing Nagios's own mechanisms (Manage Plugins + Core Config Manager). The final escalation reuses a sudo rule that starts the npcd daemon via systemd — the binary that service executes turns out to be writable by the very user granted that sudo.

PlatformHack The Box
Operating systemLinux (Debian 11)
DifficultyMedium
StatusRetired
Target IP10.129.56.190

Attack map

[161/UDP] SNMP — "public" rocommunity with no view attached
   │  hrSWRunParameters leaks check_host.sh's cmdline:
   │  svc : XjH7VCehowpR1xZB
   ▼
[API] Nagios XI /api/v1/authenticate — does not check the "enabled" flag
   │  SSH and the web login reject svc; the API hands it a valid token
   ▼
[SQLi]  CVE-2023-40931 — banner_message-ajaxhelper.php, time-based blind
   │  extracts nagiosadmin's API key
   ▼
[ADMIN]  API creates an admin user -> Manage Plugins + CCM (check_local_users)
   │  RCE: own SSH key installed in /home/nagios/.ssh
   ▼
[SSH]  nagios  (user.txt)
   │  sudo NOPASSWD manage_services.sh start npcd -> systemd ExecStart
   │  /usr/local/nagios/bin/npcd is writable by nagios
   ▼
[ROOT]  swap npcd for a script -> systemd runs it as root -> SUID bash

1. Reconnaissance

1.1 TCP ports

sudo nmap -p- --min-rate 5000 -T4 -Pn -oN nmap_allports.txt 10.129.56.190
sudo nmap -p22,80,389,443,5667 -sCV -Pn -oN nmap_services.txt 10.129.56.190
22/tcp   open  ssh      OpenSSH 8.4p1 Debian 5+deb11u3 (protocol 2.0)
80/tcp   open  http     Apache httpd 2.4.56
|_http-title: Did not follow redirect to https://nagios.monitored.htb/
389/tcp  open  ldap     OpenLDAP 2.2.X - 2.3.X
443/tcp  open  ssl/http Apache httpd 2.4.56 ((Debian))
|_http-title: Nagios XI
| ssl-cert: Subject: commonName=nagios.monitored.htb/organizationName=Monitored/
|                    stateOrProvinceName=Dorset/countryName=UK
5667/tcp open  tcpwrapped

The TLS certificate reveals the vhost nagios.monitored.htb. Port 5667 is NSCA (Nagios Service Check Acceptor) and 389 is LDAP: all consistent with a Nagios XI install.

echo "10.129.56.190 monitored.htb nagios.monitored.htb" | sudo tee -a /etc/hosts

1.2 The port that changes the game

With a monitoring server in front of you, UDP has to be scanned. SNMP is the monitoring protocol and lives on 161/udp: a TCP scan would never see it.

sudo nmap -sU --top-ports 50 --min-rate 2000 -Pn -oN nmap_udp.txt 10.129.56.190
PORT      STATE  SERVICE
123/udp   open   ntp
161/udp   open   snmp

Skipping the UDP scan is the most common mistake on monitoring boxes. Here, without 161, there is no way in.

🔒 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.