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 @@ -16,6 +16,7 @@ import { Card, CardGrid, LinkCard } from '@/components/docs';
<LinkCard title="Caching Behavior & Web Cache Deception" description="Authenticated-response caching, cache-key/Vary consistency, unkeyed-header cache poisoning, web cache deception." href="./caching/" />
<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/" />
</CardGrid>

## Severity
Expand Down
60 changes: 60 additions & 0 deletions docs/checks/ssrf.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: Open Proxy / SSRF via the Proxy
description: Whether the proxy honors absolute-form request-targets and fetches arbitrary external or internal hosts on the client's behalf.
---

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

A reverse proxy should route only to its configured backend. If it instead
honors the authority in an absolute-form request-target
(`GET http://any.host/ HTTP/1.1`), it behaves as an open forward proxy: an
attacker can make it fetch arbitrary hosts — the public internet (open
relay) and, far worse, internal-only surfaces it fronts, including the
cloud metadata service.

<Aside type="caution">
These checks are part of the v0.4 aggressive suite and only run with
`--aggressive`. They induce the proxy to make outbound requests. The
open-proxy probe targets IANA's reserved `example.com`; the scanner never
contacts it directly — only the proxy does, and only if it forwards.
</Aside>

| Check ID | Title | CVSS 4.0 | CWE | OWASP |
| --- | --- | --- | --- | --- |
| `ssrf.open_forward_proxy` | Open Forward Proxy / SSRF via Absolute-URI Request | 8.2 | [CWE-918](https://cwe.mitre.org/data/definitions/918.html) | API7:2023 |
| `ssrf.internal_target_access` | SSRF Reaches Internal Hosts via the Proxy | 9.3 | [CWE-918](https://cwe.mitre.org/data/definitions/918.html) | API7:2023 |

## `ssrf.open_forward_proxy`

Sends an absolute-form request for `http://example.com/` and confirms
open-proxy behaviour only when the proxy returns that domain's recognizable
page content, which the backend never serves. Establishes the foundational
SSRF primitive: the proxy honors a client-supplied request-target authority
instead of routing only to its backend.

**Remediate:** reject absolute-form request-targets (or ignore their
authority) and route strictly to the configured upstream; never operate a
reverse proxy with forward-proxy semantics enabled on an internet-facing
listener.

## `ssrf.internal_target_access`

Building on the open-proxy primitive, probes whether forwarding reaches the
proxy's own loopback, link-local cloud-metadata endpoints
(`169.254.169.254`, `metadata.google.internal`), and private RFC 1918
ranges. Detection is differential: it first learns how the proxy answers an
unresolvable forward, then flags only internal targets whose response is a
success distinct from that baseline. If the proxy serves its backend for
any authority (not forwarding), the check skips.

**Remediate:** in addition to disabling absolute-URI forwarding, apply
egress filtering so the proxy cannot connect to loopback, link-local, and
private ranges, and enforce IMDSv2 (session-token) on cloud instances.

## Port scanning

Active port scanning through a confirmed-SSRF proxy (checklist item 4) is
intentionally **not** performed automatically — it is the most intrusive
step and only meaningful once reachability is established. It is left to a
dedicated, separately gated follow-up rather than running under
`--aggressive`.
9 changes: 9 additions & 0 deletions proxy/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ 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"
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"
"github.com/cerberauth/proxyaudit/proxy/checks/tls/certificate"
cipherstrength "github.com/cerberauth/proxyaudit/proxy/checks/tls/cipher_strength"
Expand Down Expand Up @@ -111,6 +113,10 @@ func AllChecks() ([]harnessx.Check, map[harnessx.CheckID]checkdef.CheckDef) {

// Proxy-Level Template Injection (Agg-tier, --aggressive).
headerssti.Check,

// Open Proxy / SSRF via the Proxy (Agg-tier, --aggressive).
openforwardproxy.Check,
internaltargetaccess.Check,
}

defs := map[harnessx.CheckID]checkdef.CheckDef{
Expand Down Expand Up @@ -157,6 +163,9 @@ func AllChecks() ([]harnessx.Check, map[harnessx.CheckID]checkdef.CheckDef) {
contenttypeconsistency.Check.ID: contenttypeconsistency.Def,

headerssti.Check.ID: headerssti.Def,

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

return checks, defs
Expand Down
98 changes: 98 additions & 0 deletions proxy/checks/ssrf/internal_target_access/check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Package internaltargetaccess builds on the open-proxy primitive: when
// the proxy honors absolute-form request-targets, it probes whether that
// reaches hosts the client should never be able to — the proxy's own
// loopback interface, link-local cloud-metadata endpoints, and private
// (RFC 1918) ranges. Reachability of any of these is the high-impact SSRF
// case (credential theft via the metadata service, access to internal-
// only admin surfaces).
//
// Detection is differential and conservative: it first asks the proxy to
// forward to a host guaranteed not to resolve, establishing how the proxy
// answers a forward it cannot fulfil. Only if that baseline is a distinct
// failure (so forwarding can be told from the proxy simply serving its
// backend) does it probe the internal targets, flagging each whose
// response is a success distinct from that baseline. If the baseline
// itself succeeds — the proxy serves its backend for any authority, i.e.
// it is not forwarding — the check skips rather than guess.
//
// Requires --aggressive: it induces outbound requests to internal hosts,
// part of the opt-in attack-simulation suite.
package internaltargetaccess

import (
"context"
_ "embed"

"github.com/cerberauth/harnessx"
"github.com/cerberauth/harnessx/checkdef"
"github.com/cerberauth/proxyaudit/proxy/checks/ssrf/ssrfprobe"
"github.com/cerberauth/proxyaudit/proxy/probebase"
"github.com/cerberauth/proxyaudit/proxy/scanctx"
)

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

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

// unresolvableHost establishes the proxy's "can't forward" baseline: a
// .invalid name (RFC 6761) never resolves, so a forwarding proxy fails it.
const unresolvableHost = "proxyaudit-ssrf-nx.invalid"

// internalTarget is an authority a client should never reach through a
// correctly scoped proxy.
type internalTarget struct {
host string
kind string
}

var internalTargets = []internalTarget{
{"127.0.0.1", "proxy loopback interface"},
{"localhost", "proxy loopback interface"},
{"[::1]", "proxy loopback interface (IPv6)"},
{"169.254.169.254", "link-local cloud metadata (AWS/Azure/OpenStack IMDS)"},
{"metadata.google.internal", "GCP metadata service"},
{"10.0.0.1", "private RFC 1918 range (10.0.0.0/8)"},
{"192.168.0.1", "private RFC 1918 range (192.168.0.0/16)"},
}

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 internal-target SSRF probes"}, nil
}

baseline, err := ssrfprobe.RoundTrip(ctx, sctx, target.URL, "http://"+unresolvableHost+"/", unresolvableHost)
if err != nil {
return harnessx.Result{Err: err}, nil
}
// A distinct "can't forward" baseline is a connection error, a gateway
// status, or a client-side rejection. If instead the proxy answered a
// forward to a nonexistent host with a normal success, it is serving
// its backend regardless of authority (not forwarding at all) and
// internal reachability can't be inferred.
if !distinctFailure(baseline) {
return harnessx.Result{Skipped: true, SkipReason: "proxy serves its backend for an unresolvable forward target — absolute-URI forwarding not in effect, nothing to probe"}, nil
}

var observations []harnessx.Observation
for _, t := range internalTargets {
r, err := ssrfprobe.RoundTrip(ctx, sctx, target.URL, "http://"+t.host+"/", t.host)
if err != nil {
return harnessx.Result{Observations: observations, Err: err}, nil
}
// Reached the internal host: a success response (the proxy
// connected and got an answer) distinct from the can't-forward
// baseline.
if !r.Succeeded() || r.StatusCode >= 500 || sameOutcome(r, baseline) {
continue
}
observations = append(observations, harnessx.Observation{
Title: "Proxy reaches internal host " + t.host + " via SSRF (" + t.kind + ")",
Description: "An absolute-form request for http://" + t.host + "/ was forwarded by the proxy and returned a response distinct from how it answers an unreachable host — the proxy connected to " + t.host + " (" + t.kind + ") on the client's behalf. This exposes internal-only surfaces to any external client; the cloud metadata endpoint in particular can leak instance credentials.",
Evidence: "GET http://" + t.host + "/ -> " + status(r) + " " + ssrfprobe.BodySignature(r.Body) + "; unreachable baseline -> " + baselineDesc(baseline),
Metadata: map[string]string{"host": t.host, "kind": t.kind},
})
}
return harnessx.Result{Observations: observations}, nil
}, checkdef.WithSkip(probebase.SkipUnlessFetched))
13 changes: 13 additions & 0 deletions proxy/checks/ssrf/internal_target_access/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
id: "ssrf.internal_target_access"
name: "SSRF Reaches Internal Hosts via the Proxy"
description: "When the proxy honors absolute-form request-targets, probes whether that reaches hosts a client never should — the proxy's own loopback, link-local cloud-metadata endpoints (169.254.169.254, metadata.google.internal), and private RFC 1918 ranges. Differential and conservative: it first learns how the proxy answers an unresolvable forward, and only flags internal targets whose response is a success distinct from that baseline; if the proxy serves its backend for any authority it skips. Requires --aggressive."
link: "https://owasp.org/www-community/attacks/Server_Side_Request_Forgery"
tags:
- ssrf
- open-proxy
depends_on:
- "probe.http_fetch"
cvss_vector: "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:N/SC:H/SI:L/SA:N"
cvss_score: 9.3
cwe_id: "CWE-918"
owasp: "API7:2023"
59 changes: 59 additions & 0 deletions proxy/checks/ssrf/internal_target_access/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package internaltargetaccess

import (
"net/http"
"strconv"

"github.com/cerberauth/proxyaudit/proxy/checks/ssrf/ssrfprobe"
)

// gatewayStatuses are the responses a proxy returns when it tried to
// forward but the upstream connection failed.
var gatewayStatuses = map[int]bool{
http.StatusBadGateway: true, // 502
http.StatusServiceUnavailable: true, // 503
http.StatusGatewayTimeout: true, // 504
}

// rejectionStatuses are the responses a proxy returns when it refuses a
// forward target outright rather than attempting it.
var rejectionStatuses = map[int]bool{
http.StatusBadRequest: true, // 400
http.StatusForbidden: true, // 403
http.StatusNotFound: true, // 404
}

// distinctFailure reports whether r is a recognizable "can't / won't
// forward" outcome — a transport error or a gateway/rejection status —
// as opposed to the proxy quietly serving its backend.
func distinctFailure(r *ssrfprobe.Response) bool {
if r == nil || r.Err != nil {
return true
}
return gatewayStatuses[r.StatusCode] || rejectionStatuses[r.StatusCode]
}

// sameOutcome reports whether two responses look like the same handling
// (both transport errors, or the same status with the same body
// signature), used to tell a reached internal host apart from the
// can't-forward baseline.
func sameOutcome(a, b *ssrfprobe.Response) bool {
if a.Err != nil || b.Err != nil {
return a.Err != nil && b.Err != nil
}
return a.StatusCode == b.StatusCode && ssrfprobe.BodySignature(a.Body) == ssrfprobe.BodySignature(b.Body)
}

func status(r *ssrfprobe.Response) string {
if r.Err != nil {
return "connection error"
}
return strconv.Itoa(r.StatusCode) + " " + http.StatusText(r.StatusCode)
}

func baselineDesc(r *ssrfprobe.Response) string {
if r.Err != nil {
return "connection error"
}
return status(r)
}
83 changes: 83 additions & 0 deletions proxy/checks/ssrf/open_forward_proxy/check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Package openforwardproxy tests whether the reverse proxy also behaves as
// an open forward proxy: given a request whose request-target is an
// absolute URI for an arbitrary external host, does it fetch that host on
// the client's behalf? That is the foundational SSRF / open-relay
// primitive — once it holds, an attacker reaches any host the proxy can.
//
// The probe sends an absolute-form request for the IANA example domain
// (example.com, reserved for exactly this kind of use) and confirms open-
// proxy behaviour only when the proxy returns that domain's recognizable
// content, which a request served by the real backend never contains. The
// scanner never contacts example.com directly — only the proxy does, and
// only if it forwards.
//
// Requires --aggressive: it induces the proxy to make an outbound request
// to a host of the scanner's choosing, part of the opt-in attack-
// simulation suite.
package openforwardproxy

import (
"bytes"
"context"
_ "embed"

"github.com/cerberauth/harnessx"
"github.com/cerberauth/harnessx/checkdef"
"github.com/cerberauth/proxyaudit/proxy/checks/ssrf/ssrfprobe"
"github.com/cerberauth/proxyaudit/proxy/probebase"
"github.com/cerberauth/proxyaudit/proxy/scanctx"
)

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

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

// externalHost is IANA's reserved example domain; fetching it is harmless,
// and its page body carries markers no backend would emit by coincidence.
const externalHost = "example.com"

// forwardMarkers are strings from example.com's well-known page used to
// confirm the proxy actually fetched it.
var forwardMarkers = [][]byte{[]byte("Example Domain"), []byte("illustrative examples")}

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 open-proxy probes"}, nil
}

// Baseline: an ordinary origin-form request served by the backend,
// used to prove the forward markers aren't already present.
control, err := ssrfprobe.RoundTrip(ctx, sctx, target.URL, "/", ssrfprobe.HostHeader(target.URL))
if err != nil {
return harnessx.Result{Err: err}, nil
}
if marked(control.Body) {
return harnessx.Result{Skipped: true, SkipReason: "backend response already contains the probe's forward markers — can't attribute them to forwarding"}, nil
}

probe, err := ssrfprobe.RoundTrip(ctx, sctx, target.URL, "http://"+externalHost+"/", externalHost)
if err != nil {
return harnessx.Result{Err: err}, nil
}
if !probe.Succeeded() || !marked(probe.Body) {
return harnessx.Result{}, nil
}

return harnessx.Result{Observations: []harnessx.Observation{{
Title: "Proxy forwards absolute-URI requests to arbitrary external hosts (open proxy / SSRF)",
Description: "An absolute-form request (GET http://" + externalHost + "/) sent to the proxy was fulfilled by fetching " + externalHost + " and returning its content, which the backend never serves. The proxy honors the client-supplied request-target authority instead of routing only to its configured backend, so an attacker can reach any host the proxy can — external or internal — turning the proxy into an open relay and SSRF pivot.",
Evidence: "GET http://" + externalHost + "/ -> " + ssrfprobe.BodySignature(probe.Body),
Metadata: map[string]string{"forwarded_host": externalHost},
}}}, nil
}, checkdef.WithSkip(probebase.SkipUnlessFetched))

func marked(body []byte) bool {
for _, m := range forwardMarkers {
if bytes.Contains(body, m) {
return true
}
}
return false
}
13 changes: 13 additions & 0 deletions proxy/checks/ssrf/open_forward_proxy/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
id: "ssrf.open_forward_proxy"
name: "Open Forward Proxy / SSRF via Absolute-URI Request"
description: "Sends an absolute-form request (GET http://example.com/) to the proxy and confirms it fetched the arbitrary external host — the proxy honors the client-supplied request-target authority rather than routing only to its backend, making it an open relay and SSRF pivot to any host it can reach. Uses IANA's reserved example domain; the scanner never contacts it directly. Requires --aggressive."
link: "https://owasp.org/www-community/attacks/Server_Side_Request_Forgery"
tags:
- ssrf
- open-proxy
depends_on:
- "probe.http_fetch"
cvss_vector: "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:L/VA:N/SC:N/SI:N/SA:N"
cvss_score: 8.2
cwe_id: "CWE-918"
owasp: "API7:2023"
Loading
Loading