TryHackMe | Valley
https://tryhackme.com/room/valleype
Introduction
Welcome to another writeup! This time, we have a cool easy (not so easy) challenge, involving a lot of enumeration, interaction with FTP, network packets analysis, binary analysis, hash cracking and python library hijacking leading to privilege escalation!
Nmap
As always, we start by running Nmap to discover the available services. We’ve got SSH on 22, HTTP on 80 and FTP on 37370 (unusual port, by default FTP is on 21).
PORT STATE SERVICE REASON VERSION
22/tcp open ssh syn-ack OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
80/tcp open http syn-ack Apache httpd 2.4.41 ((Ubuntu))
37370/tcp open ftp syn-ack vsftpd 3.0.3Exploring HTTP
Let’s see what we get on this website.
Just some text and two buttons, but that’s all we need, let’s click these buttons.
Directory Listing
Visiting the gallery, we can note a directory listing, so we just need to find other directories to extract some information.
First note
The other directory available is the “pricing”, and it has a valuable information about the developer: he is addicted to leaving notes on the website.
Ffuf
Running Ffuf under the “static” directory, we are able to find a file named “00”, which contains more valuable information.
4
11
8
5
12
3
10
1
2
13
14
15
16
18
6
17
9
7
0000 note
From this note, we were given another directory and a username.
First login page
Let’s explore this login page, if we analyze a js script used by this HTML, the source code gives us a username, a password and a path to one more note.
Analyzing js
As we can see, the dev.js script has precious information. We’ve got a username and a password.
Get Lorenzo Moulin’s stories in your inbox
Join Medium for free to get updates from this writer.
Final note: devNotes37370.txt
Dev notes
This note says something about a ftp server, that’s the same server we found in the enumeration phase.
Login FTP
Now that we have a credential, it’s reasonable to try it in the ftp server.
We have a successful connection and three files in the directory, let’s extract it.
Analyzing Pcap files
Applying some filters to see only HTTP packets using POST method, we are able to find another credential.
Initial Access
Now it is time to use this credential in the SSH, and it works!
First flag
This user has the user flag.
Path to the root
In this machine, the path to the root isn’t a direct path. To completely own the system, we must first login as “valley” user, and we can get the credentials exploring the valleyAuthenticator binary. After we get access to “valley” account, we explore a misconfigured permission on python library, insert a malicious payload on it and wait for a cronjob executes it. Once the cronjob executes it, we get a root reverse shell.
Horizontal privilege escalation
Under the home directory, there is a weird binary.
Transferring binary
Using scp command to transfer the file to our local machine.
If we run the strings command and search for UPX (Ultimate Packer for eXecutables) string, we can conclude that this file was packed using it.
Deobfuscating binary
To unpack this binary, just run upx -d valleyAuthenticator.
Getting hashes
Now that the binary is unpacked, we can extract valuable information from it. It seems to be two MD5 hashes.
Cracking hashes
Using CrackStation, we can easily crack these two hashes and get the last credential.
Login as valley
Vertical privilege escalation
Now it’s time to escalate vertically. The first step is to list the cronjobs and see that there is a python script that runs every minute as the root user. The second step is to analyze this script and note the base64 library imported by the script. The third step is to note that the users in the group “valleyAdmin” (which we are in this group) has write permission on it. Then, we modify its behaviour to be malicious and gain root access.
Listing cronjobs
Analyzing python script
This script is simple to understand. It just iterate over every photo under the photos directory, base64 encode it and write under photoVault directory.
Permissions on base64.py
As the script uses the base64 python library, we should take a look to see what are the permissions on it. Since we are in the group valleyAdmin, we have write permission on this library, so we can put malicious code inside it.
Writing backdoor
Since the b64encode is always called, we can insert a python reverse shell to connect with our attacker IP.
Now, set the listener in our attacker IP and wait for the connection.
We are root!
Flag
Thank you for reading, I hope you learned the techniques used in this room.






