Executive Summary#
Previous is a medium-difficulty Linux machine that showcases a recent Next.js vulnerability (CVE-2025-29927) combined with local file inclusion, credential disclosure, and terraform provider abuse for privilege escalation. The attack path involves exploiting a middleware authentication bypass to access sensitive files, extracting SSH credentials, and then abusing sudo permissions to execute a malicious terraform provider as root.
Reconnaissance#
Initial Nmap Scan#
| |
Nmap Results
| |
Key Findings:
- Port 22: SSH (OpenSSH 8.9p1)
- Port 80: HTTP (nginx 1.18.0)
- Redirect to
http://previous.htb/
Host Configuration.#
| |
Web Application Analysis#
Directory Enumeration#
| |
Gobuster Results
| |
Key Directories:
/docs- Protected endpoint/api- API endpoints/signin- Login page
Technology Detection#
| |
Technology Stack Results
| |
| |
Technology Stack:
- Framework: Next.js (identified via
X-Powered-Byheader) - Web Server: nginx/1.18.0
- Email found:
jeremy@previous.htb
Vulnerability Discovery#
CVE-2025-29927 - Next.js Middleware Authentication Bypass#
The application is vulnerable to CVE-2025-29927, a critical authentication bypass in Next.js middleware. This vulnerability allows attackers to bypass authentication checks by using specific HTTP headers.
Testing the Vulnerability#
| |
Accessing Protected Endpoints#
| |
Local File Inclusion Exploitation#
Discovering the Download Endpoint#
Through the protected /docs endpoint, we discover an /api/download endpoint vulnerable to path traversal.
File System Enumeration#
| |
System Users
| |
Key Users:
node:x:1000:1000::/home/node:/bin/shnextjs:x:1001:65533::/home/nextjs:/sbin/nologin
Environment Variables#
| |
Environment Variables
| |
Critical Finding:
| |
NextAuth Configuration Disclosure#
| |
NextAuth Configuration
| |
Credentials Extracted:
- Username:
jeremy - Password:
MyNameIsJeremyAndILovePancakes
Initial Access#
SSH Access#
| |
User Flag#
| |
User Flag: 7a8517b41efe9980928781**********
Privilege Escalation#
Sudo Privileges Analysis#
| |
Sudo Configuration
| |
Key Finding:
Jeremy can execute: (root) /usr/bin/terraform -chdir\=/opt/examples apply
Terraform Configuration Analysis#
| |
Terraform Configuration
| |
The terraform configuration uses a custom provider: previous.htb/terraform/examples
Terraform Provider Exploitation#
Step 1: Create Provider Override Configuration#
| |
Step 2: Create Provider Directory#
| |
Step 3: Create Malicious Provider#
| |
Step 4: Execute Terraform#
| |
Step 5: Verify SUID Binary#
| |
Step 6: Escalate to Root#
| |
Root Flag#
| |
Root Flag: bab24396eb1e6c31eedd6c**********
Impact Assessment#
CVSS Score#
Base Score: 9.8 (Critical)
Business Impact#
- Complete system compromise
- Unauthorized access to sensitive data
- Potential data exfiltration
- Administrative privilege escalation
Remediation#
Immediate Actions#
- Update Next.js: Upgrade to a patched version that addresses CVE-2025-29927
- Review Sudo Configuration: Remove or restrict terraform sudo permissions
- Input Validation: Implement proper path traversal protection for the download API
- Credential Management: Rotate all exposed credentials
Long-term Security Improvements#
- Web Application Firewall: Deploy WAF rules to detect middleware bypass attempts
- File Access Controls: Implement strict file system permissions
- Security Headers: Add security headers to prevent similar attacks
- Regular Security Audits: Conduct periodic penetration testing
IOCs (Indicators of Compromise)#
Network Indicators#
| |
File System Indicators#
| |
Process Indicators#
| |
Tools Used#
nmap ~ Port scanning and service enumeration | gobuster ~ Directory and file discovery | curl ~ HTTP request manipulation and LFI exploitation | terraform ~ Privilege escalation vector |
Lessons Learned#
- Stay Updated: Recent CVEs can provide immediate attack vectors
- Least Privilege: Sudo permissions should follow principle of least privilege
- Input Validation: All user inputs must be properly validated and sanitized
- Configuration Security: Sensitive configuration files should not be accessible via web applications
References#
- CVE-2025-29927 - Next.js Middleware Authorization Bypass
- HackTheBox - Previous Machine
- Terraform Provider Development
This writeup is for educational purposes only. Always ensure you have proper authorization before testing security vulnerabilities.

