HTB: Nibbles Walkthrough

 



Writeup — Nibbles By Araiz Naqvi

Overview

Difficulty: Easy
- Operating System: Linux
- Objective: Understand potential breaking points in nibble machine.
- Tools Used: nmap, nc, whatweb, searchsploit, metasploit, gobuster, SecsList, linpeas
Prepared by Araiz Naqvi

Starting Enumeration with Nmap

The very first step is to get an idea of the open ports and services running.
To do this we will start with nmap scans:

Nmap Scanning for open ports

Here, two ports are open, SSH and HTTP which also show that the target is running Linux Ubuntu 2.2 version and an Apache httpd 2.4.18 server.

But, before we go deeper into these open ports, let’s run an all ports TCP scan and leave it in the background cause usually it takes forever to happen.

Leaving the everlong TCP all port scan in the background

I actually did some banner grabbing in the meanwhile, but for consistency sake, I also immediately did a few other nmap scans to try and get as much information as possible.

Also, since I know that ports 22 and 80 are open, I first ran this scan using default nmap scripts using -sc flag as:

Running script scans

Second, I also tried to use a scan script that would probe nmap to find frequently named web page directories or files that contain important and sensitive information using the -script=http-enum:

Checking http

As seen there was not much luck here. No useful information was retrieved.


Banner Grabbing

Just before I was about to start banner grabbing, I also got back the results for the all port scans I did, and least to say they were quite disappointing but np :_ ).

Full TCP port scan

No serious information found.
Let’s start banner grabbing!
I first used the good old nc to get basic banner information:

Banner grabbing with nc

This validates that the target hosts an Apache Web Server and an OpenSSH server at ports 80 and 22 respectively.


Web Footprinting

After having pretty hard luck in the scanning.
Let’s figure out the various technologies used and see whether we can find vulnerabilities in them.

Let’s start with whatweb to get a basic idea of the technologies used:

Finding web technologies in use

We already know all this. No useful information here again.
Let’s have a look at the website:

Shows a simple website saying “Hello World!”. Let’s also take a look at the source code using `ctrl+u`:

Source code of used IP.

Aha! There’s a weird looking directory mentioned!
Let’s check it out:

http://10.129.163.128/nibbleblog/

Does not look interesting at first.
But, let’s check out technologies used using `whatweb`:

Finding web technologies in use in http://10.129.163.128/nibbleblog/

This website is using HTML, PHP and JQuery.
Also, upon further google searches, nibbleblog turns out to be an actual thing.
It’s a blog making platform using PHP and instead of using a traditional database it saves data as files.

Now, if we search up for nibbleblog exploit this is one of them that strikes and is a critical finding!
There’s a Nibbleblog File Upload Vulnerability which allows an authenticated user to remotely execute arbitrary PHP codes. It was tested for version 4.0.3.

It also mentions a metasploit module to use:

msf exploit for Nibblesblog v4.0.3

Noted!

We just yet don’t know whether the version of nibbleblog being used is 4.0.3 or not. So, let’s try to figure that out.
Seeing what options are required:

msf parameters needed

We clearly need:
- Username (Don’t have)
- Password (Don’t have)
- TargetURI (We have)
- RPORT (We have)
- RHOSTS (We have)

So, let go figure out the version and a set of username and password.


Enumerating Hidden Directories and Files

Let’s use gobuster along with seclists wordlists to find all hidden directories and paths.

Gobuster directory discovery

And, we do have quite a bunch of links! Let’s go through each one at a time!
Starting with http://10.129.163.128/nibbleblog//admin/:

http://10.129.163.128/nibbleblog//admin/

There’s nothing too exciting here. I’ll save you the time.
The next interesting space is http://10.129.163.128/nibbleblog/README and oh boy! Here, we figure the first part of the puzzle and find that nibbleblog version 4.0.3 is in use!:

Nibbleblog version in use is 4.0.3!

Also, the next important page would’ve been http://10.129.163.128/nibbleblog/admin.php but I bruteforced a few too many times and got blacklisted but this was the login portal for admins.

I used combinations like admin:admin, root:root and admin:password123 and tadaaa I was locked out :_ )

Nevertheless, moving on after a little scanning and digging I find within this directory http://10.129.163.128/nibbleblog//content/private/users.xml a users.xml which contained some real gold:

A user with name admin exists!

As seen I had the username correct, there is a user with username admin just left to figure the password out. So, one last key left to find.

So far, we know:
- A Nibbleblog install potentially vulnerable to an authenticated file upload vulnerability
- An admin portal at `nibbleblog/admin.php`
- Directory listing which confirmed that `admin` is a valid username
- Login brute-forcing protection blacklists our IP address after too many invalid login attempts. This takes login brute-forcing with a tool such as Hydra is off the table

Also, after looking at some more pages like http://10.129.163.128/nibbleblog//content/private/config.xml, there’s a brief chance that since so many times here and there they’ve written the word nibbles there’s a slight chance this can be the password too.

It’s safe to say that we may have a password and have cracked all the keys!
So far, we know:
- We started with a simple nmap scan showing two open ports
- Discovered an instance of Nibbleblog
- Analyzed the technologies in use using whatweb
- Found the admin login portal page at admin.php
- Discovered that directory listing is enabled and browsed several directories
- Confirmed that admin was the valid username
- Found out the hard way that IP blacklisting is enabled to prevent brute-force login attempts
- Uncovered clues that led us to a valid credentials admin:nibbles

In fact after logging in using admin:nibbles, we do get in.
On scrolling around, oh boy! What i’m about to type is one of the craziest things i’ve ever done!

So, looking around, I saw plugins and there is this images tab.
Let’s try to inject and try RCE using php since we remember that nibblesblog is in php.
Let’s create a phpInject.php:

PHP to get id

Now, upload this php into the browse option and hit `save`.

Successful Injection!

Clearly, it’s executing it! This also means we can execute a reverse shell to us!
Let’s just find where this is going.

If you go back to http://10.129.184.244//nibbleblog//content/private/plugins/my_image/ that we found using gobuster, remember?

Here all uploads will appear

This is it! You can either open this or use curl and it will execute.
On opening, it returns:

ID received from the PHP injection

Clearly, RCE is working!!
Now, let’s create a reverse shell:
First, listen using nc on a port of your choice, I chose 4444:

Setting a listening server on local system

Next, create a php file with the reverse shell command:

Reverse Shell PHP Code

(Also if you noticed an IP change in the middle somewhere it was cause I forgot to renew the HTB timer)

How do I know my IP? Use ifconfig:

Your IP on which you will receive the reverse shell connection.

When we upload this php to the images and do as we did all over to execute it, we now have a successful reverse shell!

A successful reverse shell!

So as you see python was not installed but usually its python3 that’s installed. So a rough guess came correct.

Also, I have not forgotten that we are also able to exploit the metasploit but this was another excellent finding.

Now, the last thing that remains is to escalate privs.
So, let’s first check what privs we have using:

Get information on sudo permissions.

and we get to see that we have full sudo privs over /home/nibbler/personal/stuff/monitor.sh and this is gold.
We can run using sudo access to another reverse shell say at port 8444 and get complete root access.

So, in the personal.zip, first unzip it:

Unzipping personal.zip

Let’s move into the directory and edit the monitor.sh since this is the file who’s sudo privs will give us root access:

Appending reverse shell at the end of monitor.sh

Now, I appended it to the last line since when this executable runs it will execute everything in it, but don’t run it just yet. Let’s first power on nc at port 8444 (8444 is just from the reference i was taking, but you can take any):

Starting listening server at port 8444

Let’s now execute the .sh but with sudo: (remember to use sudo, I was stuck at this point for about 34 minutes to be precise)

Executing monitor.sh

Gives a bunch of bs, but looking at whether picked up or not:

Reverse shell for root access connected successfully!

Bingo!!!! We’ve connected, also if you notice the # means we’re logged on as root!
Let’s go get the last flag:

Getting the root flag.

With this we’ve successfully hacked the box.


Flag

The user.txt flag is 79c03865431abf47b90ef24b9695e148.
The root.txt flag is de5e5d6619862a8aa5b9b212314e0cdd.

Comments

Popular posts from this blog

HTB: Crocodile Walkthrough

HTB: Cap Walkthrough