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
| 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
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
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
Path Traversal
A simple path traversal with ../ leaves the base directory, and /etc/passwd is returned.

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
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
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
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
We used the password to log 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:
- As
jacky, we removetodo.txtand replace it with a link to the private key ofroot. This is allowed becausejackyowns the folder, and creating a link needs no permission on the target.jackystill cannot read the key through the link. - As
jim, we run the allowedsudocommand.rootfollows 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
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
We have now rooted the target system.

