HTB: Previous
Table of Contents
Reconnaissance#
Service Scan#
| |
| |
Two ports — SSH and an nginx reverse proxy redirecting to previous.htb. Adding that to /etc/hosts and visiting the site reveals PreviousJS — a documentation platform built on Next.js.
Enumeration#
The site serves a Next.js application with a docs section. The page source shows a build ID (qVDR2cKpRgqCslEh-llk9) and references to /_next/static/ assets — confirming this is a standard Next.js deployment behind nginx.
Key observations:
- Login state shown in top-right corner (“Logged in as ???”)
/docs/getting-startedand/docs/examplesroutes available- A user
jeremy@previous.htbis referenced
Exploitation#
CVE-2025-29927 — Next.js Middleware Authentication Bypass#
The application uses Next.js middleware for authentication. CVE-2025-29927 allows bypassing middleware entirely by sending a crafted X-Middleware-Subrequest header that tricks Next.js into thinking the request is an internal subrequest.
Bypass header:
| |
By appending this header to requests, all middleware-based authentication checks are skipped — granting access to protected routes without credentials.
Local File Inclusion#
With authentication bypassed, the /api/download endpoint becomes accessible. The example parameter is vulnerable to path traversal:
| |

This leaks the NextAuth configuration file, which contains hardcoded credentials:
| |
User Access#
SSH in with the extracted credentials:
| |
User flag obtained.
Privilege Escalation#
Sudo Enumeration#
| |
| |
Jeremy can run terraform apply as root, but only from /opt/examples. The Terraform configuration there is not writable — but Terraform supports provider dev overrides via ~/.terraformrc.
Terraform Provider Override#
The attack: create a .terraformrc that redirects the provider resolution to a directory we control, then plant a malicious “provider” binary that executes as root when Terraform initializes.
| |
Run the sudo command:
| |
Terraform loads our malicious provider as root, writes a passwordless sudo rule for jeremy, and we escalate:
| |
Root flag obtained.
Key Takeaways#
- CVE-2025-29927 is a critical middleware bypass in Next.js — any application relying solely on middleware for auth is vulnerable. The fix is upgrading Next.js and implementing server-side auth checks.
- Hardcoded credentials in source — NextAuth config files should use environment variables, not inline secrets.
- Terraform dev overrides — the
.terraformrcfile in a user’s home directory can redirect provider resolution. Ifterraform applyruns as root, any user-controlled provider path becomes a privesc vector.