# DriftingBlues: 2 BOOT2ROOT CTF VULNHUB WRITEUP

Welcome back to another write-up! In this post, I’ll be walking you through the step-by-step process of how I successfully rooted *DriftingBlues: 2* from VulnHub. This is the second machine in the DriftingBlues series, and it continues the challenge with a slightly higher difficulty level! Let's start!

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FfcsVVxSCGa7x8QmY3Y0P%2Fblue-anime-498-x-280-gif-v38hc1xd9ei9hmlx.gif?alt=media&#x26;token=152d6cb1-52ba-419f-87b0-7cdbb2e7cc6a" alt=""><figcaption></figcaption></figure>

We'll use **Nmap** to identify open ports that could serve as potential entry points into the system.

`nmap -A -sC -p- -T5 -oN nmap_result.log 192.168.96.47`

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FWK2Jqso1aVGs3Ldm6DTX%2FScreenshot%20(1496).png?alt=media&#x26;token=a265efa9-c677-4021-b0af-ca055c5bd250" alt=""><figcaption><p>ftp, shh, and http are open</p></figcaption></figure>

As shown here, the FTP service permits anonymous login—let’s go ahead and access it.

`lftp -u anonymous, 192.168.96.47`&#x20;

Upon login, this is what I've found

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FBvxa9fljAhBTG2xEnAVk%2FScreenshot%20(1499).png?alt=media&#x26;token=55f49670-0a38-4dc5-b531-044a396452a6" alt=""><figcaption></figcaption></figure>

Here's the image

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2Fe4UIAtsBY5bxVUkH8yPt%2FScreenshot%20(1500).png?alt=media&#x26;token=8b60ea21-f57a-4878-85a9-296d83986abe" alt=""><figcaption></figcaption></figure>

I attempted to use `steghide` and `stegcrack` to check for any hidden data within the system, but it seems like there’s nothing concealed.

Let's visit the website

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FTw2WNjtdFkGSFlllVJHD%2FScreenshot%20(1501).png?alt=media&#x26;token=73689413-eff7-41b5-8c45-1f2685ee2611" alt=""><figcaption><p>Nothing useful</p></figcaption></figure>

The next step I took was to launch **Gobuster** and perform a brute-force scan to discover hidden subdirectories.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FyN1KyLn5Z8O06epAzVZD%2FScreenshot%20(1502).png?alt=media&#x26;token=2d0adf2b-6bb3-4206-8a99-3bf60f105185" alt=""><figcaption></figcaption></figure>

The blog subdirectory captured my attention so the next thing I did is to visit it and here's the result

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FTSsJPVbWtObKITyKBGKr%2FScreenshot%20(1504).png?alt=media&#x26;token=0b38d414-6a1f-4778-99e1-10aa2481cba4" alt=""><figcaption><p>Just an HTML style</p></figcaption></figure>

At the very bottom, I noticed this

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FA7rsztfRfqKqs5ULyHCk%2FScreenshot%20(1505).png?alt=media&#x26;token=e4a98623-ace0-4264-8890-ed0930b250d0" alt=""><figcaption></figcaption></figure>

The `/blog` subdirectory is clearly running on WordPress. The first thing I did was add it to the `/etc/hosts` file. After that, I proceeded to use **WPScan** to gather more information about the site.

`wpscan --url http://driftingblues.box/blog/`&#x20;

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FSytx3FoiKbFhdvueWUeV%2FScreenshot%20(1507).png?alt=media&#x26;token=63f323ae-edb5-40eb-a447-dd729e94ad0c" alt=""><figcaption><p>Nothing's interesting even at the very bottom</p></figcaption></figure>

I also checked the **uploads** directory, but didn’t find anything useful there.

The next step I took was to re-run directory enumeration, this time specifically targeting the `/blog` subdirectory.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FwCERcRAH3dtekG3KCaXQ%2FScreenshot%20(1510).png?alt=media&#x26;token=449ab332-fb9d-44e5-b72f-b3509ba8faf7" alt=""><figcaption></figcaption></figure>

There's a `wp-login.php` , let's take that a visit

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FSEbCRvHqUbS5KOCgfcrj%2FScreenshot%20(1511).png?alt=media&#x26;token=4db3b1fa-5086-4203-b4c9-bf63f3533e73" alt=""><figcaption></figcaption></figure>

Since there's a wp-login, we can brute-force this using **WPscan**, **WPscan** has a bruteforce feature for wordpress logins.

`wpscan --url http://driftingblues.box/blog/ -P /usr/share/wordlists/rockyou.txt --detection-mode aggressive -e`&#x20;

After spending quite some time and enjoying some coffee on a rainy day, I finally managed to obtain the credentials.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FAgdYj0Pl9EQkot518TCR%2FScreenshot%20(1512).png?alt=media&#x26;token=51b74628-d860-4222-af31-9f761ee313e8" alt=""><figcaption></figcaption></figure>

Now let's login!

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FhwRoHiSUiDGyhrBFnQzX%2FScreenshot%20(1529).png?alt=media&#x26;token=8d6effb1-2f4c-4482-b8b0-1f6f222feea3" alt=""><figcaption></figcaption></figure>

We’re in! So what’s next? To get a shell, we’ll need to modify some source code under **Appearance → Theme Editor**. You can pick any PHP file from the theme, but the most effective choice is usually `404.php`, since it’s easy to trigger by simply accessing a non-existent page.

For the payload, I used [PentestMonkey’s](https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php) reverse shell, but you can also use my custom version, I’ve created my [own](https://github.com/kUrOSH1R0oo/reverse-shell-payloads/blob/main/payload.php) PHP reverse shell script that works just as well.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FctNBabjaJj792JG8kocx%2FScreenshot%20(1514).png?alt=media&#x26;token=c12fc591-40eb-4c06-941a-12ea10a7ccc1" alt=""><figcaption></figcaption></figure>

Before we trigger the 404, we need to establish a listener first

`nc -lnvp 1234`&#x20;

Now let's browse a subdirectory that doesn't exist and we should trigger the payload.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2F9FjJSUJME2FwtOYppFfJ%2FScreenshot%20(1513).png?alt=media&#x26;token=70dd8043-cd48-4f02-a094-f7e99210212e" alt=""><figcaption><p>We're in!!</p></figcaption></figure>

By the way, you can also achieve this using Metasploit with the `wp_admin_shell_upload` module.

The first thing I did was upgrade to a stable shell by spawning a pseudo-terminal using Python’s `pty` module.

`python3 -c 'import pty; pty.spawn("/bin/bash")'`&#x20;

Next, we’ll set the `TERM` environment variable to `xterm`, which tells the shell or terminal emulator to function as an xterm-compatible terminal for better display and interaction.

`export TERM=xterm`&#x20;

Upon exploring I've found a one user at `/home`&#x20;

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FjCXpfmKbVyWLZh5RroIa%2FScreenshot%20(1517).png?alt=media&#x26;token=c56d9da1-e5f9-409e-b074-c81476b17dd3" alt=""><figcaption></figcaption></figure>

Here are the files contained in the `freddie` directory.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FGgdsN01PaPgzI5EbFiW5%2FScreenshot%20(1518).png?alt=media&#x26;token=55039970-d674-4c44-8693-6805acc080e3" alt=""><figcaption></figcaption></figure>

As shown, the `user.txt` file is present, but notice the permissions — only the user `freddie` has read access. So, to view the contents of `user.txt`, we first need to gain access as the `freddie`user.

The good news is that `freddie` has a `.ssh` directory. This means if we can access the `id_rsa` file, which is the private SSH key, we can use it to log in as `freddie` via SSH.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FcLynQLx1iqrlsdw1MicV%2FScreenshot%20(1520).png?alt=media&#x26;token=6f311b4f-d6a1-4ee0-a298-dc9297ab2eb1" alt=""><figcaption></figcaption></figure>

There it is! Now we just need to copy the private key to our attacker machine, set its permissions to `600` using `chmod`, and use it to authenticate and log in as the user `freddie` via SSH.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FubuKrXFwzFBRG11qDlzr%2FScreenshot%20(1522).png?alt=media&#x26;token=60f95442-5159-45eb-aaf6-4e5469058a9c" alt=""><figcaption></figcaption></figure>

We're now `freddie`!

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FSTkWpXkVyR5Qdm66THeF%2FScreenshot%20(1523).png?alt=media&#x26;token=c7549536-6141-448c-958d-64af8c24a0c4" alt=""><figcaption><p>User Flag!</p></figcaption></figure>

Now it’s time to fully take control of the system — let’s go for root access! I started by running the `sudo -l` command to check which actions `freddie` is allowed to execute with elevated privileges.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FhkIPTL2dj4eor1YWtZy5%2FScreenshot%20(1524).png?alt=media&#x26;token=f8c1d927-a3fa-4c87-bc92-a80ebe1a4572" alt=""><figcaption></figcaption></figure>

It turns out that `freddie` can execute `nmap` with root privileges. So, I headed over to [**GTFOBins**](https://gtfobins.github.io/gtfobins/nmap/) to find a way to exploit this, and here’s what I discovered.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FsQnoRYV3LLm2HLfmmiIQ%2FScreenshot%20(1525).png?alt=media&#x26;token=bb6ebae2-a955-4091-859f-aa2e0ed755f3" alt=""><figcaption></figcaption></figure>

This exploit takes advantage of Nmap’s native support for Lua through its Nmap Scripting Engine (NSE). By creating a temporary file containing the Lua command `os.execute("/bin/sh")` and running it with `nmap --script=$TF`, the user can execute system commands directly. Lua is used because Nmap is built to interpret Lua scripts for automation and advanced scanning tasks, making it ideal for this kind of abuse. If Nmap is run with `sudo`, the script runs with root privileges, and the spawned shell (`/bin/sh`) will also be a root shell. This leads to privilege escalation by exploiting a legitimate feature in a trusted binary to execute arbitrary commands as the superuser.

Now let's try the exploit and we will try to launch nmap with sudo to see the result

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2F5GSANdyIPdWrWGcGxnju%2FScreenshot%20(1526).png?alt=media&#x26;token=743b428e-705c-49f1-a551-22bcbfd9d9b6" alt=""><figcaption><p>Yay!</p></figcaption></figure>

It works!!! We are root!

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FE8jJu1I5l2dTfjUoo7Gh%2FScreenshot%20(1527).png?alt=media&#x26;token=2bd81c00-05cc-427c-8c6a-06da3bafcdd1" alt=""><figcaption><p>The shell is not stable hehe, but here's the root flag!</p></figcaption></figure>

We've successfully pwned DriftingBlues: 2!!

**Conclusion**

This challenge shows a common path of gaining full control over a vulnerable system. It starts by identifying a login page and using a tool like WPScan to brute-force access. After logging in, we take advantage of file editing features to upload a reverse shell and connect back to our machine. Once a basic shell is established, we stabilize it for better control and explore the system for further opportunities. Finding a private SSH key allows us to switch users, and checking for `sudo` permissions reveals a way to escalate privileges using a trusted tool. By carefully chaining each step—initial access, user escalation, and privilege escalation—we successfully gained root access, showing how small misconfigurations can lead to complete system compromise.
