Files
Sachin SharmaandClaude Opus 4.7 10c027546a Phase 2H: cache poisoning + HTTP smuggling — 1 PASS + 1 honest negative + gap fix
Two-server lab (Nginx 1.27 proxy + gunicorn/Flask origin) via Docker.

Verified live:
- hunt-cache-poison: X-Forwarded-Host injection into origin reflection
  cached by Nginx (cache key omits headers). Single attacker request
  poisons cache; victim served https://attacker.evil/static/style.css
  + script src for the cache TTL (5 min in lab; longer in real CDNs).
  Chain: cache poisoning → persistent XSS at scale.

Honest negative + skill-content fix:
- hunt-http-smuggling: 9 documented payload variants (CL.TE classic,
  TE.CL, space-before-colon, trailing-space, tab-separator, lowercase
  value, mixed-case header, double TE, X-prefix smuggle) ALL rejected
  by Nginx 1.27 with HTTP 400 / 501.
- Nginx ≥ 1.21 is RFC 9112 strict by default: CL+TE conflict triggers
  rejection at the front-end. Classic smuggling payloads are dead
  against the modern Nginx default deployment.
- The skill payloads remain valid for: HAProxy ≤ 2.4 (CVE-2021-40346),
  older F5 BIG-IP / Citrix ADC, Squid 3.x, Apache Traffic Server,
  custom Python/Go proxies. H2.CL / H2.TE attacks against CDN+origin
  chains remain the dominant 2024-2026 vector.
- Skill gap closed: added Target-Suitability Matrix to
  hunt-http-smuggling listing front-end-by-front-end vulnerability
  status, fingerprint quick-check, and H2-downgrade pivot guidance.

This is Phase 2 verification's second honest negative (Phase 2G XXE
was the first). Both produce skill-content updates that move the
stack from "this attack works" to "this attack works against THESE
specific targets" — operationally far more useful.

Combined Phase 2 verification: 24+ skills exercised, 9+ skill-content
gaps catalogued and closed.

Lab source at docs/verification/phase2h-lab/ (docker-compose +
origin Flask + Nginx config, MIT-shippable).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 09:53:28 +05:30

73 lines
2.3 KiB
Python

"""
Phase 2H — origin app behind Nginx.
Intentional flaws for cache poisoning + HTTP smuggling tests:
1. Reflects X-Forwarded-Host in a Link header used for asset URLs
→ cache poisoning when X-Forwarded-Host is not part of cache key
2. Echoes Transfer-Encoding header presence — used as smuggling marker
(the actual smuggling happens at the front-end / back-end disagree-on-length level)
"""
from flask import Flask, request, jsonify, make_response
app = Flask(__name__)
@app.route("/")
def home():
"""
Reflects X-Forwarded-Host into an HTML <link> tag.
If the front-end cache stores this response keyed only by URL
(not by X-Forwarded-Host), a single attacker request can poison
the cache for all subsequent visitors.
"""
xfh = request.headers.get("X-Forwarded-Host", request.headers.get("Host", "localhost"))
body = f"""<!doctype html>
<html>
<head>
<title>Phase 2H origin</title>
<link rel="stylesheet" href="https://{xfh}/static/style.css">
<script src="https://{xfh}/static/app.js"></script>
</head>
<body>
<h1>Welcome — assets load from {xfh}</h1>
<p>This page is cached by the front-end proxy.</p>
</body>
</html>"""
resp = make_response(body)
resp.headers["Cache-Control"] = "public, max-age=300"
resp.headers["Content-Type"] = "text/html"
return resp
@app.route("/api/who")
def who():
"""
Echoes all request headers — useful to see what the back-end actually received.
Helps confirm HTTP smuggling (does the smuggled request reach back-end?).
"""
return jsonify(
method=request.method,
path=request.path,
headers={k: v for k, v in request.headers.items()},
body=request.get_data().decode("utf-8", "replace")[:1000],
)
@app.route("/api/log", methods=["GET", "POST"])
def log():
"""
Test endpoint that just records what arrived.
Hit by smuggled request → confirms smuggling worked.
"""
return jsonify(method=request.method, path=request.path, headers=dict(request.headers), body=request.get_data().decode("utf-8", "replace")[:500])
@app.route("/static/<path:p>")
def static_files(p):
return f"/* static asset {p} */", 200, {"Content-Type": "text/css"}
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=False, threaded=True)