Date: 25/06/2022

Difficulty: Easy

CTF: https://app.hackthebox.com/machines/Trick


Enumeration

Let’s start checking the connection with the target machine:

Untitled

Let’s do an nmap scan to discover opened TCP ports:

Untitled
Untitled

Let’s take a look to the http service:

Untitled
Untitled

Does the form works?

Untitled
Untitled

Apparently no.

Let’s try to found directories in the website:

Untitled
Untitled

We obtain a 403 error when we try to see that directories.

Let’s see if we can obtain the DNS from the domain service:

Untitled

Yeah, the DNS is trick.htb, let’s add it to the /etc/hosts file:

Untitled
Untitled

The website looks the same, but now we can enumerate for subdomains:

Untitled

Nothing for the top1million-5000.txt neither for 20000 one.

Let’s see what can we do with the port 25 (SMTP):

Untitled

Let’s enumerate the DNS:

https://book.hacktricks.xyz/network-services-pentesting/pentesting-dns
Untitled
Untitled

We got a total of 3 subdomains:

  • trick.htb
  • root.trick.htb
  • preprod-payroll.trick.htb

Let’s add them to /etc/hosts and visit them.

root.trick.htb goes to the same page as trick.htb

But preprod goes to this page:

Untitled
Untitled

I tried with some common credentials with no success. The error message will not be helpful to enumerate valid usernames, let’s check if it vulnerable to SQLi

Untitled
Untitled

Yes, it is. Now we are inside a control panel.

Untitled

So, apparently the Administrator username is Enemigosss. We can edit the profile:

Untitled

The value of the password field can be seen in cleartext if we inspect the code, but we can also see it in the form if we delete the attribute type=password from the textbox:

Untitled

So, we have credentials: Enemigosss:SuperGucciRainbowCake

Let’s see if they have reused them and we can log in via ssh:

Untitled

Nope.

Ok, it was a preprod of payroll website… Maybe there will be other preprod sites? Let’s find out:

Untitled

Yeah, at least there is a marketing preprod. Let’s add it to the /etc/hosts file and visit it:

Untitled
Untitled

It seems to be including the pages via inclussion… LFI maybe?

Untitled

It doesn’t allow us to include the /etc/passwd file, maybe we cannot use this way.

Let’s try to discover directories for this subdomain:x.php?page=index.php

Untitled

Going a step back, I found a LFI in the preprod-payroll website. Using the php filter wrapper I’m able to leak the content of certain things encoding it to b64:

php://filter/convert.base64-encode/resource=index

Untitled

There are interesting things here:

Untitled

This is how it includes the pages, it looks for the page parameter and it adds the .php file extension. If we want to include other kind of files, we should find the manner to avoid the file extension.

Untitled

This part of the code is interesting because it leaks some php files. auth.php may contain credentials? Let’s take a look:

http://preprod-payroll.trick.htb/index.php?page=php://filter/convert.base64-encode/resource=auth

Untitled

Apparently it doesn’t exists.

Let’s take a look to users.php:

Untitled

Apparently it query the users from a database. To do it, it includes a php file called db_connect let’s check it:

Untitled

So… more credentials: remo:TrulyImpossiblePasswordLmao123, let’s add it to the credentials list.

Untitled

This credentials are not valid for ssh neither.

After trying some techniques to try path traversal I haven’t found a valid way to do it. So let’s investigate the preprod-marketing site:

The version of jquery (3.4.1) is vulnerable to XSS:

Untitled

The only input I have found on the website is this contact form.

Untitled

So, I deployed a http server in my machine, listening on port 80 and tried to catch a get, with no success.

There is another strange thing, the URL:

Untitled

It looks like the LFI we exploited earlier, but the wrappers doesn’t work. Let’s try path traversal

Untitled

Yeah! At first I had no success, because probably the server is filtering the string ../ so, using ....// instead solved the problem.

At passwd file we can see a user named michael. Let’s try to connect via ssh using this username and the passwords obtained before:

Untitled

Nope.

Let’s try to catch the flag using the LFI:

Untitled

Flag found.

But we need to gain access! Let’s see if this user has some ssh credentials:

Untitled

Bingo!

Untitled

Yay! We’re inside >:D

Privilege Escalation

Now let’s find the way to escalate privileges:

Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled

To test it, I executed pspy in the target machine and tried to access via ssh with root username and a random password several times:

Untitled

After some tries, this happened:

Untitled

Looking for the file that executes the iptables command I found the file iptables-multiport.conf, inside there is something called actionban

Untitled

It’s the iptables command we saw earlier. So, let’s try to modify this, restart the service and trigger the ban to see if we can gain a revshell!

Untitled
Untitled
Untitled

And that’s how I got the root flag!