Post

Hack the Box (HTB) - Nibbles

Weak Password & Poor Sudo Permission

Hack the Box (HTB) - Nibbles

Enumeration

Let’s run AutoRecon against our box at 10.10.10.75

1
sudo autorecon 10.10.10.75

Looking at the results, we see the following services:

  • 22/tcp SSH OpenSSH 7.2p2 Ubuntu 4ubuntu2.2
  • 80/tcp HTTP Apache httpd 2.4.18

Let’s examine the Apache server

Hello World

Not much here at initial glance, let’s check the source HTML

HTML

We see nibbleblog mentioned in this comment. Let’s attempt to navigate to that directory

Nibble Blog page

On the bottom right we can observe powered by nibbleblog. Nibbleblog is a open source CMS

Wappalyzer indicates that the server is using php on the backend. Let’s check for standard login pages such as /login.php & /admin.php

adminlogin

There’s an admin login page, but this doesn’t help us much as we lack credentials. Let’s run a ferox buster scan against the main blog page

content

Looks like there’s a /content directory. Let’s check it out

Content Directory

There’s some eternally exposed directories, which definitely not good, (but excellent for us). Let’s dig into /private

Admin User

Looking inside the /private directory leads us to a users.xml file. This file contains the login user for ID 0 (aka the admin) which so happens to be admin. Let’s head back over to the login admin panel and try a few different passwords

Logged in

Here we were able to login using the username admin that we obtained earlier and the password nibbles. This password was somewhat predictable, given its presence in the blog title. This approach to login is a bit contrived but is common in CTFs

Scrolling to the bottom, we see some more information

Version

Let’s do a google search for the version 4.0.3

Nibbleblog search

Aha, there’s an authenticated file upload (CVE-2015-6987). Let’s take a look

Examining the exploit in exploit DB, it appears to be a ruby script designed for MSF that lets authenticated users upload a malicious PHP file which grants RCE by accessing it via a direct request to the file in content/private/plugins/my_image/image.php

Looking at the gui real quick for the application, this is the culprit

image plugin

Without Metasploit

Since we have GUI access, we can simply crate a php reverse shell script and upload here. This is essentially all the metasploit exploit is doing

1
nano pwned.php

Script

Upload the script

image.php

Our script doesn’t execute right away, but navigating back to the web directory in our browser we can see that our image was renamed to image.php. Proceeding to click on it gives us a shell

NO MS Shell

With Metasploit

Let’s fire up MSF and perform this exploit

1
msfdb run

Search for “nibbleblog”

MSF Nibbleblog

Set the options for the exploit, hit run

User

Let’s upgrade our shell and run a sudo -l

sudo -l

We’re able to run this monitor.sh file as root with nopasswd. This is 100% the attack vector on an easy rated box. Let’s proceed to check out this shell script

monitor.sh

This script is writable by us, and with the ability to run it as sudo we can simply edit it to spawn a root shell

monitor.sh Edited

root

GG, we’ve rooted Nibbles!

Vulnerabilities & Mitigation’s

VulnerabilityMitigation
Authenticated File Upload (CVE-2015-6967)Restrict file uploads to safe file types and validate input.
Weak Admin PasswordUse strong, complex passwords.
Poor Sudo Permissions for monitor.shRestrict sudo permissions and avoid NOPASSWD configurations.

Remediation References

This post is licensed under CC BY 4.0 by the author.