TryHackMe Publisher
Writeup
Overview
- Machine Name: Publisher
- OS: Linux
- Difficulty: Easy
Summary
On the machine "Publisher", we started by enumerating and discovering SPIP version 4.2.0, which had a known RCE exploit. Using this exploit, we gained initial access and found ourselves in a Docker container. Then escaped the container by leveraging an SSH connection with a found ID RSA key. Finally, we achieved privilege escalation by modifying a script to gain root access.
Reconnaissance
Nmap Scan Results
We can see that only ports 22 (SSH) and 80 (HTTP) are open. Let's check the website to see what we can find !
Directory Enumeration
We can see an interesting directory.
While checking on Wappalyzer https://www.wappalyzer.com/, we found that the webpage is running SPIP 4.2.0. Let's check if there are any vulnerabilities or exploits available for this version.
And yes! We found an RCE exploit for SPIP 4.2.0.
Exploitation
Vulnerabilities Exploited
Lets procceed with the explotation with Metasploit
We're in as www-data
. Let's conduct enumeration; checking the hostname reveals that we're in a Docker container.
If we navigate back two directories, we can find the user flag.
While enumerating to escape Docker, I discovered an .ssh
directory in the home folder containing an id_rsa
key. This enabled us to establish an SSH connection and successfully escape Docker.
Let's copy id_rsa
and id_rsa.pub
to our local machine and connect via SSH. The id_rsa.pub
file indicates it's associated with the user 'think'.
Voila! We're now connected via SSH. So far, this machine has been quite straightforward. Let's proceed with privilege escalation enumeration to identify how we can elevate our privileges and gain root.
Post-Exploitation
Privilege Escalation via Script Modification
Initial Discovery and Enumeration
-
Initial Upload and Enumeration:
- Uploaded
linpeas.sh
to the target machine to perform comprehensive enumeration.
- Uploaded
-
Identifying SUID Binary:
- Discovered
/usr/sbin/run_container
as a SUID binary (-rwsr-sr-x
), indicating it runs with root privileges.
- Discovered
Script Analysis and Modification
-
Analyzing
/opt/run_container.sh
:- Examined the script used by
/usr/sbin/run_container
to manage Docker containers.
- Examined the script used by
-
Modifying the Script:
- Edited
/opt/run_container.sh
to include/bin/bash -p
in theprompt_container_id()
function. This insertion granted a root shell when executed.
- Edited
Exploitation and Root Access
-
Executing the Modified Script:
- Copied the modified
/opt/run_container.sh
to/dev/shm
and then replaced the original script.
- Copied the modified
-
Gaining Root Access:
- Executed
/usr/sbin/run_container
, which invoked the modified script. - Successfully obtained a root shell (
bash-5.0#
) due to the insertion of/bin/bash -p
in the script.
- Executed