Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/checks/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Card, CardGrid, LinkCard } from '@/components/docs';
<LinkCard title="WAF / Filtering Behavior" description="Baseline SQLi/XSS/path-traversal blocking, encoding-based bypasses, consistency across content types and encodings." href="./waf/" />
<LinkCard title="Proxy-Level Template Injection" description="Request headers reflected through a server-side template engine (e.g. Caddy templates). Aggressive suite." href="./templateinjection/" />
<LinkCard title="Open Proxy / SSRF" description="Absolute-URI forwarding to arbitrary external and internal hosts, including cloud metadata. Aggressive suite." href="./ssrf/" />
<LinkCard title="Request Smuggling / Desync" description="Whether the proxy rejects ambiguous request framing (CL.TE / TE.CL / TE.TE). Aggressive suite." href="./smuggling/" />
</CardGrid>

## Severity
Expand Down
52 changes: 52 additions & 0 deletions docs/checks/smuggling.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: Request Smuggling / Desync
description: Whether the proxy rejects ambiguous request framing — the precondition for CL.TE / TE.CL / TE.TE smuggling.
---

import { Aside } from '@/components/docs';

Every classic HTTP request-smuggling attack starts from the same flaw: a
message whose length is ambiguous (conflicting `Content-Length`, or
`Content-Length` together with `Transfer-Encoding`, or an obfuscated
`Transfer-Encoding`) that a front-end proxy and a back-end resolve
differently. RFC 9112 requires rejecting such a message; a proxy that
accepts it supplies the desync primitive.

<Aside type="caution">
This check is part of the v0.4 aggressive suite and only runs with
`--aggressive`. It is non-destructive: it sends only benign,
self-contained bodies on their own `Connection: close` sockets and never
attempts the desync itself (which could poison another client's
connection) — it reports purely on whether the malformed framing was
rejected or accepted.
</Aside>

| Check ID | Title | CVSS 4.0 | CWE | OWASP |
| --- | --- | --- | --- | --- |
| `smuggling.ambiguous_framing` | Ambiguous Request Framing Accepted (Smuggling Precondition) | 7.3 | [CWE-444](https://cwe.mitre.org/data/definitions/444.html) | API8:2023 |

## `smuggling.ambiguous_framing`

Sends four RFC-violating framings and flags any the proxy answers with a
2xx/3xx instead of rejecting (4xx/5xx or a dropped connection):

- **conflicting duplicate `Content-Length`** — two different values (CL.CL),
- **`Content-Length` + `Transfer-Encoding: chunked`** — the CL.TE / TE.CL ambiguity,
- **duplicate `Transfer-Encoding` with a non-chunked final encoding** — TE.TE,
- **whitespace-obfuscated header name** (`Transfer-Encoding : chunked`).

Each body is bounded and self-contained so no probe can stall a
length-honoring parser. The check first confirms a well-formed POST is
accepted; if the endpoint rejects even that, it skips.

**Remediate:** run a front-end that strictly conforms to RFC 9112 — reject
messages with conflicting `Content-Length`, with both `Content-Length` and
`Transfer-Encoding`, or with an unrecognized/obfuscated `Transfer-Encoding`
— and ensure the front-end and back-end share the same parsing rules.

## Not yet covered

HTTP/2→1.1 downgrade smuggling (H2.CL / H2.TE), raw H2C smuggling, and
connection-reuse boundary isolation (checklist items 2, 3, 5) require
HTTP/2 framing control and are tracked separately; the downgrade path ties
to the HTTP/2 & HTTP/3 protocol work.
5 changes: 5 additions & 0 deletions proxy/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
xforwardedfor "github.com/cerberauth/proxyaudit/proxy/checks/headertrust/x_forwarded_for"
xforwardedhost "github.com/cerberauth/proxyaudit/proxy/checks/headertrust/x_forwarded_host"
xrealip "github.com/cerberauth/proxyaudit/proxy/checks/headertrust/x_real_ip"
ambiguousframing "github.com/cerberauth/proxyaudit/proxy/checks/smuggling/ambiguous_framing"
internaltargetaccess "github.com/cerberauth/proxyaudit/proxy/checks/ssrf/internal_target_access"
openforwardproxy "github.com/cerberauth/proxyaudit/proxy/checks/ssrf/open_forward_proxy"
headerssti "github.com/cerberauth/proxyaudit/proxy/checks/templateinjection/header_ssti"
Expand Down Expand Up @@ -117,6 +118,8 @@ func AllChecks() ([]harnessx.Check, map[harnessx.CheckID]checkdef.CheckDef) {
// Open Proxy / SSRF via the Proxy (Agg-tier, --aggressive).
openforwardproxy.Check,
internaltargetaccess.Check,
// Request Smuggling / Desync (Agg-tier, --aggressive).
ambiguousframing.Check,
}

defs := map[harnessx.CheckID]checkdef.CheckDef{
Expand Down Expand Up @@ -166,6 +169,8 @@ func AllChecks() ([]harnessx.Check, map[harnessx.CheckID]checkdef.CheckDef) {

openforwardproxy.Check.ID: openforwardproxy.Def,
internaltargetaccess.Check.ID: internaltargetaccess.Def,

ambiguousframing.Check.ID: ambiguousframing.Def,
}

return checks, defs
Expand Down
151 changes: 151 additions & 0 deletions proxy/checks/smuggling/ambiguous_framing/check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// Package ambiguousframing tests how the proxy handles requests whose
// message length is ambiguous — the precondition for every classic
// request-smuggling / desync attack (CL.TE, TE.CL, TE.TE). RFC 9112
// requires a server to reject a message that carries conflicting
// Content-Length values, or both Content-Length and Transfer-Encoding, or
// an unrecognized Transfer-Encoding. A front-end that instead accepts such
// a message, and a back-end that resolves the length differently, is a
// desync waiting to happen.
//
// The probe never performs an actual desync: it sends only benign,
// self-contained bodies and never tries to smuggle a second request, so it
// cannot poison another client's connection (each probe uses its own
// Connection: close socket). It reports purely on whether the ambiguous
// message was rejected (a 4xx/5xx or a dropped connection) or accepted (a
// 2xx/3xx) — acceptance being the smuggling precondition.
//
// Requires --aggressive: it puts deliberately malformed requests on the
// wire, part of the opt-in attack-simulation suite.
package ambiguousframing

import (
"context"
_ "embed"
"net/http"
"net/url"
"strconv"

"github.com/cerberauth/harnessx"
"github.com/cerberauth/harnessx/checkdef"
"github.com/cerberauth/proxyaudit/proxy/checks/smuggling/smugprobe"
"github.com/cerberauth/proxyaudit/proxy/probebase"
"github.com/cerberauth/proxyaudit/proxy/scanctx"
)

//go:embed check.yaml
var checkYAML []byte

var Def = checkdef.MustParseCheckDefYAML("ambiguous_framing", checkYAML)

const crlf = "\r\n"

// variant is one ambiguous-framing message shape.
type variant struct {
id string
title string
why string
headers string // header lines (each ending in CRLF) after Host/Connection
body string
}

// variants are RFC-violating framings a conformant proxy must reject. Each
// body is self-contained and bounded so no probe can hang a length-honoring
// parser waiting for bytes that never arrive.
var variants = []variant{
{
id: "duplicate_content_length",
title: "conflicting duplicate Content-Length",
why: "two Content-Length headers with different values — a front-end and back-end that pick different ones disagree on where the request ends",
headers: "Content-Length: 6" + crlf + "Content-Length: 5" + crlf,
body: "AAAAAA", // 6 bytes; both lengths are satisfiable, so no parser stalls
},
{
id: "cl_te",
title: "both Content-Length and Transfer-Encoding",
why: "Content-Length and Transfer-Encoding: chunked together — the CL.TE / TE.CL ambiguity, where one hop honors the length and the other the chunking",
headers: "Content-Length: 6" + crlf + "Transfer-Encoding: chunked" + crlf,
body: "0" + crlf + crlf + "X", // valid empty chunk (5 bytes) + 1 pad byte = 6, satisfies CL too
},
{
id: "te_obfuscated_value",
title: "Transfer-Encoding with an unrecognized final encoding",
why: "two Transfer-Encoding headers where the final one isn't chunked — a hop that reads the first chunks the body, a hop that reads the last doesn't (TE.TE)",
headers: "Transfer-Encoding: chunked" + crlf + "Transfer-Encoding: identity" + crlf,
body: "0" + crlf + crlf,
},
{
id: "te_obfuscated_name",
title: "whitespace-obfuscated Transfer-Encoding header name",
why: "a space before the colon in \"Transfer-Encoding : chunked\" — a strict parser ignores the header, a lenient one honors the chunking, so the two hops frame the body differently",
headers: "Transfer-Encoding : chunked" + crlf,
body: "0" + crlf + crlf,
},
}

var Check = checkdef.NewCheck(Def, func(ctx context.Context, target harnessx.Target, _ harnessx.ResultStore) (harnessx.Result, error) {
sctx := scanctx.TargetContext(target)
if !sctx.Aggressive {
return harnessx.Result{Skipped: true, SkipReason: "aggressive-suite check — rerun with --aggressive to send ambiguous-framing probes"}, nil
}

tgt, err := smugprobe.NewTarget(sctx, target.URL)
if err != nil {
return harnessx.Result{Err: err}, nil
}
path := requestPath(target.URL)

// Baseline: a well-formed POST with a correct Content-Length must be
// accepted, or the endpoint rejects everything and acceptance of a
// malformed variant can't be read as a framing weakness.
control := tgt.Send(ctx, build(path, tgt.Host(), "Content-Length: 6"+crlf, "AAAAAA"))
if control.Rejected() {
return harnessx.Result{Skipped: true, SkipReason: "endpoint rejects a well-formed POST (" + describe(control) + ") — can't establish a baseline to judge ambiguous framing against"}, nil
}

var observations []harnessx.Observation
for _, v := range variants {
resp := tgt.Send(ctx, build(path, tgt.Host(), v.headers, v.body))
if resp.Rejected() {
continue
}
observations = append(observations, harnessx.Observation{
Title: "Proxy accepts ambiguous request framing (" + v.title + ")",
Description: "A request with " + v.why + " was accepted by the proxy (" + describe(resp) + ") instead of being rejected as RFC 9112 requires. If the back-end resolves the message length differently from this front-end, the mismatch is a request-smuggling / desync primitive. This check does not attempt the desync itself — it reports only that the malformed framing was not rejected.",
Evidence: "POST " + path + " with " + v.title + " -> " + describe(resp) + "; well-formed control -> " + describe(control),
Metadata: map[string]string{"variant": v.id, "status": statusText(resp)},
})
}
return harnessx.Result{Observations: observations}, nil
}, checkdef.WithSkip(probebase.SkipUnlessFetched))

// build assembles a raw HTTP/1.1 request from a path, host, extra header
// lines (each CRLF-terminated), and a body sent verbatim.
func build(path, host, headers, body string) string {
return "POST " + path + " HTTP/1.1" + crlf +
"Host: " + host + crlf +
"User-Agent: proxyaudit" + crlf +
"Connection: close" + crlf +
headers + crlf + body
}

func requestPath(rawURL string) string {
u, err := url.Parse(rawURL)
if err != nil || u.RequestURI() == "" {
return "/"
}
return u.RequestURI()
}

func describe(r *smugprobe.Response) string {
if r.Err != nil {
return "connection dropped/failed"
}
return statusText(r)
}

func statusText(r *smugprobe.Response) string {
if r.Err != nil {
return "no response"
}
return strconv.Itoa(r.StatusCode) + " " + http.StatusText(r.StatusCode)
}
13 changes: 13 additions & 0 deletions proxy/checks/smuggling/ambiguous_framing/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
id: "smuggling.ambiguous_framing"
name: "Ambiguous Request Framing Accepted (Smuggling Precondition)"
description: "Sends requests with RFC-violating, ambiguous message length — conflicting duplicate Content-Length, Content-Length together with Transfer-Encoding (CL.TE/TE.CL), and obfuscated Transfer-Encoding (TE.TE) — and flags any the proxy accepts instead of rejecting. Acceptance is the precondition for request smuggling / desync when a back-end resolves the length differently. Non-destructive: it sends only benign self-contained bodies and never attempts the desync itself. Requires --aggressive."
link: "https://portswigger.net/web-security/request-smuggling"
tags:
- smuggling
- desync
depends_on:
- "probe.http_fetch"
cvss_vector: "CVSS:4.0/AV:N/AC:H/AT:P/PR:N/UI:N/VC:H/VI:H/VA:L/SC:N/SI:N/SA:N"
cvss_score: 7.3
cwe_id: "CWE-444"
owasp: "API8:2023"
124 changes: 124 additions & 0 deletions proxy/checks/smuggling/smuggling_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Package smuggling_test exercises the checks/smuggling scanners against a
// raw TCP server (net/http's own server rewrites malformed framing, so a
// hand-rolled listener is needed to model a proxy that accepts or rejects
// it) driven through a harnessx.Engine as proxyaudit would.
package smuggling_test

import (
"context"
"fmt"
"net"
"net/http"
"strings"
"testing"
"time"

"github.com/cerberauth/harnessx"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

ambiguousframing "github.com/cerberauth/proxyaudit/proxy/checks/smuggling/ambiguous_framing"
"github.com/cerberauth/proxyaudit/proxy/probebase"
"github.com/cerberauth/proxyaudit/proxy/scanctx"
)

// behaviour decides how the stub proxy answers a raw request.
type behaviour func(raw string) int

// permissive accepts everything.
func permissive(string) int { return http.StatusOK }

// strict rejects RFC-violating ambiguous framing, accepts the rest —
// a conformant proxy.
func strict(raw string) int {
lower := strings.ToLower(raw)
switch {
case strings.Count(lower, "content-length:") >= 2,
strings.Contains(lower, "content-length:") && strings.Contains(lower, "transfer-encoding"),
strings.Count(lower, "transfer-encoding") >= 2,
strings.Contains(raw, "Transfer-Encoding :"):
return http.StatusBadRequest
}
return http.StatusOK
}

// rejectAll models an endpoint that 400s even a well-formed request.
func rejectAll(string) int { return http.StatusBadRequest }

// rawServer serves one response per connection, its status chosen by fn
// after reading the request bytes.
func rawServer(t *testing.T, fn behaviour) string {
t.Helper()
ln, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)
t.Cleanup(func() { _ = ln.Close() })

go func() {
for {
conn, err := ln.Accept()
if err != nil {
return
}
go func(c net.Conn) {
defer c.Close()
_ = c.SetReadDeadline(time.Now().Add(time.Second))
// The whole request arrives in one write before the client
// reads, so one Read returns it — no need to drain to EOF
// (the client holds the connection open) and wait out the
// deadline.
buf := make([]byte, 8192)
n, _ := c.Read(buf)
code := fn(string(buf[:n]))
body := "OK"
_, _ = fmt.Fprintf(c, "HTTP/1.1 %d %s\r\nContent-Length: %d\r\nConnection: close\r\n\r\n%s",
code, http.StatusText(code), len(body), body)
}(conn)
}
}()
return "http://" + ln.Addr().String()
}

func run(t *testing.T, url string, aggressive bool) harnessx.ScanSummary {
t.Helper()
target := scanctx.NewTarget(url, &scanctx.ScanContext{HTTPClient: http.DefaultClient, Aggressive: aggressive})
engine := harnessx.New(harnessx.WithChecks(probebase.HTTPFetchCheck, ambiguousframing.Check))
summary, err := engine.Run(context.Background(), target)
require.NoError(t, err)
return summary
}

func TestAmbiguousFraming_PermissiveProxy_FlagsEveryVariant(t *testing.T) {
summary := run(t, rawServer(t, permissive), true)
variants := map[string]bool{}
for _, o := range summary.Observations {
variants[o.Metadata["variant"]] = true
}
for _, want := range []string{"duplicate_content_length", "cl_te", "te_obfuscated_value", "te_obfuscated_name"} {
assert.True(t, variants[want], "expected variant %q flagged, got %v", want, variants)
}
}

func TestAmbiguousFraming_StrictProxy_NoFindings(t *testing.T) {
assert.Empty(t, run(t, rawServer(t, strict), true).Observations)
}

func TestAmbiguousFraming_EndpointRejectsBaseline_Skipped(t *testing.T) {
summary := run(t, rawServer(t, rejectAll), true)
assert.Empty(t, summary.Observations)
assert.True(t, skipped(summary))
}

func TestAmbiguousFraming_NotAggressive_Skipped(t *testing.T) {
summary := run(t, rawServer(t, permissive), false)
assert.Empty(t, summary.Observations)
assert.True(t, skipped(summary))
}

func skipped(summary harnessx.ScanSummary) bool {
for _, r := range summary.Results {
if r.CheckID == ambiguousframing.Check.ID {
return r.Skipped
}
}
return false
}
Loading
Loading