View on GitHub

GitPage

berzerk0's GitHub Page

Main Page | Blog | CTF Writeups | How-To Guides

CTF Writeup:

Bulldog on VulnHub


a0

11 November 2017

There are two versions of this walkthrough: This is the original, NON-INTRODUCTORY VERSION.

Find the Introductory Version here

A fun box from Vulnhub, written by Nick Frichette. You can find it here at https://www.vulnhub.com/entry/bulldog-1,211/

Here is the description by the author:

Bulldog Industries recently had its website defaced and owned by the malicious German Shepherd Hack Team. Could this mean there are more vulnerabilities to exploit? Why don’t you find out? :)

After their hack by the BlackHat German Shepherds, Bulldog Industries has brought us in to find the rest of the vulnerabilities. They will be happy they did!

Introduction

I liked this box for several reasons:

This write up assumes the reader is using Kali, but all the tools are standard (unless mentioned) in distros like BlackArch as well – except for dirsearch, but you can use dirb or dirbuster as replacements if you like. I ran it on my native Kali host machine using VirtualBox; on a host-only network.

Before beginning, I added its IP to my hosts file for convenience.

Method

1. Initial Scans


A1 – initial scan

Let’s see, we have SSH on a non-standard port, and two HTTP ports using a Python-based webserver. That’s new to me.

Let’s start with HTTP, primarily out of habit.

With HTTP, I always run nikto, nmap with vulnscan and dirsearch – all at the same time. This is one of the reasons I like tabbed terminal emulators. I use terminator, which is heavy, but I run Kali natively on my desktop so it doesn’t cause too much of a problem. A lighter alternative is Sakura.

First, we run nikto, which often gives me the juiciest pieces of info.


A2 - nikto

That /dev folder might be interesting, we’ll check it first when we do our manual scan.

Next, we try dirsearch.

I keep dirsearch in my /opt directory with other Web Tools, and run it twice, with a lot of extensions. I’m trying to be more thorough, and since it is an automated tool, this seems like a good place to start.

I run it with a script that contains two scans, one with the default wordlist, and one with the medium dirbuster wordlist found (on Kali) in /usr/share/wordlists/dirbuster/

Here’s my script if you want to give it a go:

#!/bin/bash

#dirsearchem
#$1 box name
#$2 URL (check for Domain, HTTPS, port first)

clear
date
echo "Running dirsearch on $1 $2"

python3 /opt/Web_Tools/dirsearch/dirsearch.py -u "$2" -e sh,txt,php,html,htm,asp,aspx,js,xml,log,json,jpg,jpeg,png,gif,doc,pdf,mpg,mp3,zip,tar.gz,tar --plain-text-report=dirsearch_$1_quick

python3 /opt/Web_Tools/dirsearch/dirsearch.py -u "$2" -e sh,txt,php,html,htm,asp,aspx,js,xml,log,json,jpg,jpeg,png,gif,doc,pdf,mpg,mp3,zip,tar.gz,tar -w /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt --plain-text-report=dirsearch_$1_BigList

date
echo "Finished dirsearch on $1 at  $2"

For demo reasons, I will do these two scans separately. The second scan is often overkill.


A3 – quick dirsearch

Okay, those look very interesting. We will add /admin and /robots.txt to the list, then begin the big dirsearch scan,


A4 – big dirsearch

Lastly, before browsing around using the “look at it with my eyeballs” scan, we run a full nmap scan with the vulnerability script.

We’ll give these scans a moment, and begin our manual scan.

2. Manual Website Investigation


A6 – website landing

Woof. Business operations are suspended! We have to save the bulldogs! Let’s investigate this public notice.


A7- notice

I appreciate it when CTF authors slip a bit of humor into their machines. However, it seems to me that the only useful information is that the dirtycow exploit will probably not work on this box. (“Smelly cow?”)

Let’s check on the big dirsearch list and see if caught anything new.


A8 – big dirsearch result

Doesn’t look like it. /notice is new, but that’s the page we are looking at. If we get stuck later we can try dirsearching again and adding -f or -r to force extensions and search recursively.

Alright, let’s dive into the manual scan, armed with our list of /dev, /admin and /robots.txt. I like to start with robots.txt, since it might contain info that our scans couldn’t access.

A9 – robots.txt

Oh no! ASCII art, the mark of a true elite hacker! We will have to remember to deface… I mean, fix this later on. It doesn’t contain anything new however. Let’s check /dev.

(At this point, I checked on my nmap vulnscan – it had not found anything new, but it did find /robots.txt and /dev “interesting”)


A10 - /dev page 1

I like a CTF with an attempt to create real-world context. This is full of useful information.


A11 /dev page 2

My next goal is to access that Web-Shell, and exploit it. Before I do that, I’ll need to appear like I have logged in.

3. Logging into the Website

Let’s check out that /admin page


A12 – admin page

We have a list of many usernames, so technically we can assume we are halfway to a valid set of login credentials. We have emails, but I don’t think any of them will respond to any phishing attempts.

We’ve been told that the site uses Django for everything, and this is also announced at the top of the page. This suggests SQL Injection isn’t going to be helpful here.

Hmm, we can start digging through some page sources to see if we can find something useful. I first checked /admin’s source, but didn’t find anything I new how to use at this time. There is an interesting POST data section called “csrfmiddlewaretoken” - which sounds like there is some kind of system in place against CSRF attacks.

/dev is directed to internal developers, so it is more likely to have informative comments.


A13 – devsrc

Well, those comments have the potential to be VERY informative. “Django’s default is too complex… It’s not like a hacker can do anything with a hash” - daring us to prove them wrong.

I copied the emails and hashes into the useful email:hash format. Before I introduce them to my friend John, let’s see what type of hash they are. Now, you can quickly do this on Kali using

but I want to maybe not just identify the hash format, but crack it at the same time, if I can. Enter HashBuster. From experience, I am going to guess they’re SHA1. Hash-Buster seems to only work for SHA1 and MD5 hashes, but that suits us fine.


A14 – hashbuster

Okay, we have SHA1, but it didn’t crack. Luckily, we have many hashes to choose from. We can try them all. For best results, let’s run them through John the Ripper and then check them in HashBuster while that is running.

I’m going to use my own wordlist here, my commonly used Top32Million-probable.txt that you can find in my Probable-Wordlists Repo – this particular list can’t be downloaded from GitHub directly, but torrents and MegaUpload links are provided.

You don’t HAVE to use that wordlist, but I had more success with it than the default option. For honesty’s sake, I’ll mention that rockyou works well too.


A15 – john

Somehow, I don’t find those results surprising. We do have two FULL login credentials now, so let’s try them.

(For completeness’ sake, I ran all of the hashes through hash-buster, and none came up ¯\_(ツ)_/¯ - You can google them (and should normally, but that can lead to walkthroughs online and spoilers. Then again, here you are reading one of those – so go nuts!)

We COULD try them on the website login, where we know they will probably work, but people reuse passwords all the time. The client has not closed SSH yet, so let’s try there!


A16 – ssh try

No luck, but keeping it simple can yield great results.

So, we have two usernames to choose from. Nick works on the site’s backend, and Sarah runs the database. Backend might have access to the server, but database might have access to more credentials. Both are good choices, so let’s try both!

Make sure you hit “Log Out” between attempts, or you’ll get stuck in cookie limbo. I logged in with both and got an identical not-very-promising screen for each user.


A17 – logged in

However, armed with a logged-in session, we can access the web-shell! Go to /dev/shell and let’s see what we can do.

4. Exploiting the Web-Shell


A18 – webshell

“All commands are run on the server itself” is SCREAMING command injection. We want to run commands here, so we have to figure out how to allow arbitrary commands through.

What do we know?

It’s running Django, a python variant. It is likely to be using something analogous to “exec” in php, but there might be some “if” statement checking for the right commands. I wonder if we can trick this if statement by using one of the commands on the list, then once it passes that check, executing any command we want.

Let’s try something like ;


A19 – they caught me!

Oh no! The internet police are coming after me!

Let’s try &&


A20 – andand

This is promising, but pwd is on the list of approved commands. Let’s try something unapproved, like id, whoami or cd .


A21 – norules

Not only do we find out we can run commands, but we find out we can run sudo!

Let’s see if we can use this to run a reverse shell. I have had mixed success with nc using the -e flag, so my go to shell command is:

Which we need to run after pwd or one of the other commands – after we have set up our listener of course.

On our local machine, we run:

And then on the Web-Shell, try running.


A22 nobashrev

It didn’t like that, or give us a shell – but we didn’t get a “not allowed” error. That’s called progress! My go-to method to get around this is to write a script containing the more complicated or powerful commands I want to run, then to run a command to download and execute that script using simpler commands. It usually comes in these three parts:

This last part usually uses wget-to donwload the script to a writable directory like /tmp and then running chmod +x script.sh and bash script.sh - so, we need do check if our user can run these commands.

In the webshell, we run

This script will tell us if we can run wget, chmod and bash, while also double-checking that we can write to /tmp.


A23 – canrun

All good news! We can run all of those commands, AND can write to /tmp – this means we are ready to set up our http server and download the script!

On our host machine, we write our shell script to a .sh file. I did this with a simple:

Then, we start our SimpleHTTPServer in that same directory with


A24 host and script

Our host machine is ready to serve up a freshly baked script. Make sure your listener is running, then we need to execute the change directory, download, make executable and run operation in the Web-Shell.

Make sure your ports are right! The host port is 5100 1 and the listener is 5100 0.


A25 – shell popped!

5. Enumerating With A User Shell

We have some enumeration and privesc shell scripts handy, but before we go downloading and running them, we should try some simple things.

Since this box is simulating a real world experience, we may see some common user missteps, such as leaving important notes and reminders laying around. Usually, these users would leave these things in a home folder – or maybe in emails.

Let’s see what we can see in the /home directory.

We can see here that Nick and Sarah don’t have home folders on this machine, there is just bulldogadmin and django. Luckily, we ARE django.

Just a quick check to see if root_password_do_not_touch.txt is in any of these folders. Perhaps that file is hidden?


A26 – homeenum

.hiddenadmindirectory is not a standard, and we can look inside!

A note? Could this be our AdminPassNoHackersPlz.txt file?


A27 – hidden admindir

“…the webserver is the… …one who needs to have root access…” is all I needed to hear to get me interested. Right now, we are running as the webserver, and root access would be just lovely.

The other lines that got my attention were “Once I’m finished with it, a hacker wouldn’t even be able to reverse it,” and “…it’s still a prototype right now.”

Maybe WE can reverse it.

6. Reversing to Root

As of this writing, I am pretty new to reverse engineering. I do know some basics in gdb and peda, but before we try those, let’s see if it is a gift to be simple. I know that the customPermissionApp has been compiled, but there might be some useful human-readable lines in there. We can use the strings command here, and use less to go through it carefully. First, we will need a tty.

We’ve got python, so we can run our python tty spawning command.

Now we can use less


A28 – pty and strings

Okay, let’s see if anything jumps out at us.
A29 – lesscustomP

The first thing I noticed was “sudo su root” at the bottom. This command doesn’t just run a command as root, it tries to log in as root for a time.

“sudo su” also requires a password, but the line *“Usage: ./customPermissionApp "* doesn’t appear to even ask for one. The note did mention that it only worked for the Django user, too. Could this mean that the password for the Django user is contained within this file?

We should read the whole file to try to find something, but let’s start with the section we are already looking at.


A30 – supergood
Hmm, this isn’t quite readable but I can make a guess out of it.

SUPERultH
imatePASH
SWORDyouH
CANTget

You know, if you dropped those pesky H’s at the end, you would find SUPERultimatePASSWORDyouCANTget - which is yelling at us to be tried as a root password. So, let’s try it out.

password: SUPERultimatePASSWORDyouCANTget


A31 shift+3

I just love seeing that little #.

We own this box now – we are the top (bull)dog! From here we can just go to the /root directory and grab the flag.

Lessons Learned

Thanks to Nick Frichette for a fun box! Looking forward to the sequel!


Main Page | Blog | CTF Writeups | How-To Guides