> ## Documentation Index
> Fetch the complete documentation index at: https://siriusbar.net/llms.txt
> Use this file to discover all available pages before exploring further.

# TryHackMe - Valley

> TryHackMe room writeup focused on enumeration and low-level exploitation.

Room link: [Valley](https://tryhackme.com/room/valleype)

An easy TryHackMe room that aims to sharpen your enumeration and pentest skills.

## User Flag

We connect to the VPN machine servers via OpenVPN. After that we run an extensive scan on the target.

<Frame caption="Nmap scan on the target">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/3.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=45589f83ab9feb7ef262e1b5216c62f2" alt="Nmap scan on the target" width="934" height="569" data-path="images/valley/3.PNG" />
</Frame>

We see the HTTP and SSH services are open on their default ports and an FTP server (vsftpd 3.0.3) is running on port **37370**. We search for an exploit for the FTP server but there is none. Let's look through the HTTP website.

<Frame caption="Website that running on port 80">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/1.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=382dc8b2a500b7e7973154bf111569ab" alt="Website that running on port 80" width="1918" height="908" data-path="images/valley/1.PNG" />
</Frame>

Next we run a directory scan on the website to further enumerate.

<Frame caption="GoBuster scan">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/6.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=216ba4f73221d1314034f6dbaa39b93c" alt="GoBuster scan" width="927" height="464" data-path="images/valley/6.PNG" />
</Frame>

From the scan we discover 3 main directories: gallery, static and the pricing. Gallery and Pricing directories not that important to us because one has random JPEG files that are nothing to do with stenography and the other consists of a useless note.txt file.

<Frame caption="note.txt file inside the pricing directory">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/5.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=f9da3bf187ed9b39039a5759933b24ac" alt="note.txt file inside the pricing directory" width="387" height="68" data-path="images/valley/5.PNG" />
</Frame>

Although, there is no files in the static directory too, when we run a directory scan on the /static, we see a directory named /00. That looks odd from the other ones.

<Frame caption="Directory scan of the /static">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/7.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=6799378aa7b8245d278b1454e3413bad" alt="Directory scan of the /static" width="508" height="372" data-path="images/valley/7.PNG" />
</Frame>

We look to the /00 and we see another note that was left by the devs (don't do this man :D). The note indicates that there is another directory with the name **/dev1243224123123**. Let's look through that.

<Frame caption="Inside of /00">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/8.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=a118a38367842f94362e59286bce506c" alt="Inside of /00" width="260" height="220" data-path="images/valley/8.PNG" />
</Frame>

We encounter with a login panel. I tried SQL Injection but didn't work. Then we look through the source code deeply and inside the **dev.js** file we found some credentials. When we try them on the login page we successfully log into the site.

<Frame caption="Login panel">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/9.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=b00c051ebf1bfdb585fba844e703901f" alt="Login panel" width="1880" height="792" data-path="images/valley/9.PNG" />
</Frame>

<Frame caption="Credentials">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/12.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=1fe46d962f05c414462095f5ae2b476a" alt="Credentials" width="728" height="228" data-path="images/valley/12.PNG" />
</Frame>

Inside the site we find another note LEFT BY THE DEVS (do you see a pattern here 🤨)
The note exactly says **stop reusing credentials** and talks about the ftp server. We infer from this that we could log into the ftp server with the same username and the password. And indeed we can.

<Frame caption="Logged in to the FTP server">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/13.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=45284460490c746fbe3556ba92e31557" alt="Logged in to the FTP server" width="648" height="341" data-path="images/valley/13.PNG" />
</Frame>

In the FTP server we see 3 pcapng files. After we get and analyze them the only important file is the file that named **siemHTTP2.pcapng**. Inside of it we find a HTTP trace. We follow it and we find some credentials to log in via ssh to the machine.
After we log in to the machine as valleyDev user we acquire the User flag.

<Frame caption="HTTP Trace">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/15.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=8494c1c87ea0ecb6b540189d6a5be17a" alt="HTTP Trace" width="933" height="511" data-path="images/valley/15.PNG" />
</Frame>

<Frame caption="User Flag">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/16.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=21f96307f8c6d57795dc174912e35ea1" alt="User Flag" width="613" height="407" data-path="images/valley/16.PNG" />
</Frame>

## Root Flag

We can't find much in the valleyDev home directory but in the /home ve found an executable called valleyAuthenticator. We download it to analyze using the SCP tool.
Using the Strings tool we identify the binary is compressed using the UPX method and we can decompress it by using the upx-ucl tool installed in Kali. After that we try to analyze it with Strings one more time and we find two hashed which are seem like md5sum hashes. We crack them using the crackstation and get the following credentials:

* User: valley
* Password: libert123

<Frame caption="valleyAuthenticator file">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/18.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=ed70c1ba01246f0a859d5fb40229ebaa" alt="valleyAuthenticator file" width="924" height="84" data-path="images/valley/18.PNG" />
</Frame>

<Frame caption="MD5 Hashed inside the binary">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/19.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=259bff849d52664a662a65b3d7fb0053" alt="MD5 Hashed inside the binary" width="602" height="243" data-path="images/valley/19.PNG" />
</Frame>

<Frame caption="Using crackstation to crack the hashes">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/20.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=8f661a5c29d8fe8407317749a99cd297" alt="Using crackstation to crack the hashes" width="1192" height="386" data-path="images/valley/20.PNG" />
</Frame>

Using this credentials we log with the **valley** user.

<Frame caption="Logged with valley user">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/21.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=471ebdbedf5919f00b3a2c0c4bff3950" alt="Logged with valley user" width="838" height="485" data-path="images/valley/21.PNG" />
</Frame>

We run linpeas to see possible privilege escalation vectors.

<Frame caption="Running linpeas.sh">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/22.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=de1c75f353c65360532ba8b4769c0ad0" alt="Running linpeas.sh" width="853" height="657" data-path="images/valley/22.PNG" />
</Frame>

Linpeas finds a python script that runs as a cronjob. Next we analyze the file.

<Frame caption="Linpeas finds a cronjob">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/23.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=685d9f559049095083ba86c1fe084e2e" alt="Linpeas finds a cronjob" width="590" height="103" data-path="images/valley/23.PNG" />
</Frame>

<Frame caption="Look into the python script">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/24.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=7aa1a13262a5e7651d9932b2ef76bed3" alt="Look into the python script" width="568" height="315" data-path="images/valley/24.PNG" />
</Frame>

After trying so much things, I decided to try **Python module hijacking**. In this case we can put a reverse shell code inside the default base64.py (Valley user is assigned to the valleyAdmin group and resulting that it can write to the base.64 file arbitrarly) file, so when the Base64 module is called our reverse shell will be run by the other script, in our case that script will be run as the root user and we will get the root shell. base64.py file is located in the /usr/lib/python3.8 directory.

<Frame caption="Base64 module and the valleyAdmin group privileges">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/25.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=362181e6d7eae4e2a9830abba6a745d0" alt="Base64 module and the valleyAdmin group privileges" width="505" height="53" data-path="images/valley/25.PNG" />
</Frame>

We get the shell and we got the flag!

<Frame caption="Putting the reverse shell inside the Base64 module and getting the root user">
  <img src="https://mintcdn.com/siriusbar/c8e1wz5GgN3iYmBQ/images/valley/26.PNG?fit=max&auto=format&n=c8e1wz5GgN3iYmBQ&q=85&s=bf80f40847f30b19fce3ee2e2c84dd93" alt="Putting the reverse shell inside the Base64 module and getting the root user" width="1839" height="768" data-path="images/valley/26.PNG" />
</Frame>
