> For the complete documentation index, see [llms.txt](https://angellm.gitbook.io/hacknotes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://angellm.gitbook.io/hacknotes/htb/2022/trick.md).

# Trick

**Date**: 25/06/2022

**Difficulty**: Easy

**CTF**: <https://app.hackthebox.com/machines/Trick>

***

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

<figure><img src="/files/ig9of3qlBJUbXPIHweXh" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/zLbsDBZSfzhSR5iCtKRc" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/PCLQV9bDiVaX9JRCPiWm" alt=""><figcaption></figcaption></figure>

Let’s take a look to the http service:

<figure><img src="/files/PKPXmshpjeAEYl1zb3hO" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/owVa2usUcZeBJJ0RfuKN" alt=""><figcaption></figcaption></figure>

Does the form works?

<figure><img src="/files/rRYz7oSvIQ6NofcNwudw" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/0AvmosOb7ldGfIo104X0" alt=""><figcaption></figcaption></figure>

Apparently no.

Let’s try to found directories in the website:

<figure><img src="/files/oldtEQwzdE5pWunoCStZ" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/AmFp7nnFiccEi8Z6DyeS" alt=""><figcaption></figcaption></figure>

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:

<figure><img src="/files/snC92a5GQ1AwWfGHZ7P8" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/S4UHKl0DmrW6laQ6BblT" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/ltoMgGF8Ljc1ZbOeDYAt" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/9EmB6ygt96E1s1LseT8b" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="/files/PDpm9WG0y5tbC8cy5sbu" alt=""><figcaption></figcaption></figure>

Let’s enumerate the DNS:

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

<figure><img src="/files/KPiAKdFhjLJrhpox1P6T" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/QaDrnEuxxuDpRFlvDvy9" alt=""><figcaption></figcaption></figure>

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:

<figure><img src="/files/YECvXHLzIVuufJ4bzmfw" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/j7EK8nxfo5MfzN0x8GuW" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/02LskfVj0yhL4i4JZJDQ" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/4qvNWrI1QqWXLUhPqRVz" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/OysJo4HPPItQHIYpDwOu" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/dJjOf5gQfezrVVGExSix" alt=""><figcaption></figcaption></figure>

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:

<figure><img src="/files/b2BANrUNiAycMoQhrh3v" alt=""><figcaption></figcaption></figure>

So, we have credentials.

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

<figure><img src="/files/jqDVuNjPy5bqDIJ5Mdbw" alt=""><figcaption></figcaption></figure>

Nope.

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

<figure><img src="/files/B7y7biMPUEMrS5iDpp83" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/ltaQJFPeFV97SDterxv4" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/913n22huQAtKtnPjxJ18" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/SYi4ZJOJ6MryTpuJeXsv" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="/files/cYRVtdBOh8etSwnxGPd2" alt=""><figcaption></figcaption></figure>

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`

<figure><img src="/files/iiREvSv3T3pd5yucFuvA" alt=""><figcaption></figcaption></figure>

There are interesting things here:

<figure><img src="/files/dAuPiiP8fHiJONyjUiMC" alt=""><figcaption></figcaption></figure>

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.

<figure><img src="/files/66Tqod9iJeXH1hnG7liy" alt=""><figcaption></figcaption></figure>

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`

<figure><img src="/files/w6c6ySZ0aYy7kzM5BHsp" alt=""><figcaption></figcaption></figure>

Apparently it doesn’t exists.

Let’s take a look to `users.php`:

<figure><img src="/files/DL1im4ffuqebpnPOF4nd" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/2M38EvsneBEhhAft1VIN" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/0sCO0VwnqQIfhjTG6Ca4" alt=""><figcaption></figcaption></figure>

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:

<figure><img src="/files/yxREaIPvpryXjmftFgUP" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/V4UKQlfkoY41b492U1W2" alt=""><figcaption></figcaption></figure>

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:

<figure><img src="/files/GWCC8A79DpSJlcFR68Ir" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/zCSfHlK6n5VVumindZjt" alt=""><figcaption></figcaption></figure>

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:

<figure><img src="/files/0ipKfRsfQ3za4EDpe1yK" alt=""><figcaption></figcaption></figure>

Nope.

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

<figure><img src="/files/lRChIuoFhRctrNNmNaDc" alt=""><figcaption></figcaption></figure>

Flag found.

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

<figure><img src="/files/w7T14gkP0xu8G3ztKPLQ" alt=""><figcaption></figcaption></figure>

Bingo!

<figure><img src="/files/3Hcma29UzTdlNra7m5ST" alt=""><figcaption></figcaption></figure>

Yay! We’re inside >:D

Now let’s find the way to escalate privileges

<figure><img src="/files/KnRoG5Rb7qNepsOwGwi3" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/eZkOuRPYVGsDuIOUnyeE" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/bhChMCufOiDZTvsA1T86" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/Jhvj1Dv1jMoGNYDVC0fr" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/97lRop8572TW5u7VnBdC" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/OAMpznMBKvNqKSBRd8Tu" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/PoMgUcJOnvxoEqbhHYAj" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/NzlxLdOvY81P5V2Nr2lP" alt=""><figcaption></figcaption></figure>

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:

<figure><img src="/files/kcBKjwq8Mdd4IXYPNnVU" alt=""><figcaption></figcaption></figure>

After some tries, this happened:

<figure><img src="/files/E9SimLrnlWkvybQkG0KU" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/3280fiRtRFCSKidTAnf5" alt=""><figcaption></figcaption></figure>

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!

<figure><img src="/files/flrLxjkgCOFPKVLZwnAo" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/tLgMJlXPpq0ktO9sucye" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/BHCV041FS2ytdaiH5zlq" alt=""><figcaption></figcaption></figure>

And that’s how I got the root flag!


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://angellm.gitbook.io/hacknotes/htb/2022/trick.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
