Ronin66 Writeup: Mask

13 Nov 2026 · Ronin66 · 6 min
Machine
Mask
Platform
Ronin66
OS
Linux
Difficulty
Easy
Table of Contents

Overview

Mask is a Linux machine that runs a Next.js 14.2.0 web application on port 3000, next to SSH. The application is vulnerable to CVE-2025-29927, an authentication bypass in the Next.js middleware. The bypass leads to a protected /dashboard page that reads files through a file parameter, and a simple path traversal turns that into an arbitrary file read. Reading the private SSH key of the user jim gives us a foothold.

As jim, a sudo rule and a document folder reveal the password of a second user, jacky. jacky owns a file that jim is allowed to read as root with sudo. We replace that file with a symbolic link to the private key of root, let jim read it through sudo, and log in as root.

Enumeration

We started with an Nmap scan to identify the open ports on the target.

Nmap

Mask ➜ nmap -sC -sV 10.0.31.82
Nmap Scan Conducted

Nmap Scan Conducted

Port Service Description
22 SSH SSH on a Linux host. Needs credentials or keys, so a private key found later can be used here.
3000 HTTP Next.js web application (version 14.2.0 according to Wappalyzer). It has a public /login page and a protected /dashboard page.

Open ports and services found by the Nmap scan

The scan shows SSH on port 22 and a web application on port 3000, which we look at next.

Fingerprinting Next.js

With Wappalyzer, we identified the framework of the web application as Next.js, version 14.2.0.

Wappalyzer Identifying Next.js 14.2.0

Wappalyzer Identifying Next.js 14.2.0

Exploitation

This Next.js version is vulnerable to CVE-2025-29927.

CVE Research

Next.js uses the internal header x-middleware-subrequest to stop middleware from calling itself in a loop. Vulnerable versions (14.x before 14.2.25) trust that header even when it comes from an external client. A request that carries the header with the right value skips the middleware completely, including any authentication check that lives in it.

Testing the Bypass

Without the header, the protected /dashboard page redirects to /login. With the header, the middleware is skipped, and the page answers with its own error instead of a redirect.

Mask ➜ curl -H "x-middleware-subrequest: middleware:middleware:middleware:middleware:middleware" http://10.0.31.82:3000/dashboard
Dashboard Asking for a File Parameter

Dashboard Asking for a File Parameter

The error shows that the dashboard code expects a file parameter, so the page reads files from the server.

Reading Files

When we request a file that every user can read, /etc/passwd, the application answers with a file-not-found error. The application seems to add the requested name to a base directory, so an absolute path does not resolve.

File Not Found Error

File Not Found Error

Path Traversal

A simple path traversal with ../ leaves the base directory, and /etc/passwd is returned.

Path Traversal Returning /etc/passwd

Path Traversal Returning /etc/passwd

Retrieving the Private Key

The file shows the home directories of the users. We use this to request the private SSH key of jim.

Retrieved Private Key of jim

Retrieved Private Key of jim

Logging in

The key only works when its permissions are strict, so we set them before logging in with SSH.

Mask ➜ chmod 600 jim.rsa
Mask ➜ ssh -i jim.rsa [email protected]
Logged In as jim

Logged In as jim

Post-Enumeration

With access as jim, we looked for ways to move further.

Sudo Permissions

We discovered that jim can run a command with sudo.

jim@mask:~$ sudo -l
Sudo Permissions of jim

Sudo Permissions of jim

The rule lets jim read one file as root: /home/jacky/notes/todo.txt. Reading it prints a note from jacky.

Hey Jim,

Dont forget to patch the Next.js instance the security team flagged it as critical due to CVE-2025-29927. 
Make sure to update to the latest stable version and verify that no vulnerable dependencies remain in the build.

Jacky

The note confirms how we got in, and it points us to jacky and the notes folder.

Corporate Documents

We also found a folder named corporate-document-management. Inside it, we retrieved credentials.

Discovered Credentials

Discovered Credentials

We used the password to log in as jacky.

Logged In as jacky

Logged In as jacky

Post-Exploitation

Notes Folder

The sudo rule of jim reads todo.txt in the notes folder of jacky, and jacky owns both the folder and the file. This means that we control a file that root reads for jim.

Retrieving the Private Key of root

A symbolic link is only a pointer. When something opens the link, the system follows it to the real file and checks the permissions of whoever is opening it. We use that in two steps:

  1. As jacky, we remove todo.txt and replace it with a link to the private key of root. This is allowed because jacky owns the folder, and creating a link needs no permission on the target. jacky still cannot read the key through the link.
  2. As jim, we run the allowed sudo command. root follows the link and reads the key, which is printed to our terminal.
# First Terminal (jacky)
jacky@mask:~/notes$ rm todo.txt
jacky@mask:~/notes$ ln -s /root/.ssh/id_rsa todo.txt

# Second Terminal (jim)
jim@mask:~$ sudo /bin/cat /home/jacky/notes/todo.txt
Private Key of root Retrieved

Private Key of root Retrieved

Escalating to Root

We save the key on our machine, set the correct permissions and log in as root.

Mask ➜ chmod 600 root.rsa
Mask ➜ ssh -i root.rsa [email protected]
Logged In as root

Logged In as root

We have now rooted the target system.

← Back to Writeups