diff --git a/docs/checks/index.mdx b/docs/checks/index.mdx
index 9e9171c..db8270c 100644
--- a/docs/checks/index.mdx
+++ b/docs/checks/index.mdx
@@ -16,6 +16,7 @@ import { Card, CardGrid, LinkCard } from '@/components/docs';
+
## Severity
diff --git a/docs/checks/ssrf.mdx b/docs/checks/ssrf.mdx
new file mode 100644
index 0000000..e8a2eac
--- /dev/null
+++ b/docs/checks/ssrf.mdx
@@ -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.
+
+
+
+| 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`.
diff --git a/proxy/checks.go b/proxy/checks.go
index f026267..70427a0 100644
--- a/proxy/checks.go
+++ b/proxy/checks.go
@@ -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"
@@ -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{
@@ -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
diff --git a/proxy/checks/ssrf/internal_target_access/check.go b/proxy/checks/ssrf/internal_target_access/check.go
new file mode 100644
index 0000000..c04cc3b
--- /dev/null
+++ b/proxy/checks/ssrf/internal_target_access/check.go
@@ -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))
diff --git a/proxy/checks/ssrf/internal_target_access/check.yaml b/proxy/checks/ssrf/internal_target_access/check.yaml
new file mode 100644
index 0000000..dc23377
--- /dev/null
+++ b/proxy/checks/ssrf/internal_target_access/check.yaml
@@ -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"
diff --git a/proxy/checks/ssrf/internal_target_access/helpers.go b/proxy/checks/ssrf/internal_target_access/helpers.go
new file mode 100644
index 0000000..330dcea
--- /dev/null
+++ b/proxy/checks/ssrf/internal_target_access/helpers.go
@@ -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)
+}
diff --git a/proxy/checks/ssrf/open_forward_proxy/check.go b/proxy/checks/ssrf/open_forward_proxy/check.go
new file mode 100644
index 0000000..cbe42f4
--- /dev/null
+++ b/proxy/checks/ssrf/open_forward_proxy/check.go
@@ -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
+}
diff --git a/proxy/checks/ssrf/open_forward_proxy/check.yaml b/proxy/checks/ssrf/open_forward_proxy/check.yaml
new file mode 100644
index 0000000..443e690
--- /dev/null
+++ b/proxy/checks/ssrf/open_forward_proxy/check.yaml
@@ -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"
diff --git a/proxy/checks/ssrf/ssrf_test.go b/proxy/checks/ssrf/ssrf_test.go
new file mode 100644
index 0000000..1d18da3
--- /dev/null
+++ b/proxy/checks/ssrf/ssrf_test.go
@@ -0,0 +1,131 @@
+// Package ssrf_test exercises the checks/ssrf scanners against a real
+// httptest.Server driven through a harnessx.Engine, exactly as proxyaudit
+// would. The test servers stand in for the proxy: an "open proxy" acts on
+// the absolute-form request-target's authority, a "reverse proxy" ignores
+// it and always serves its backend.
+package ssrf_test
+
+import (
+ "context"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+
+ "github.com/cerberauth/harnessx"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+
+ internaltargetaccess "github.com/cerberauth/proxyaudit/proxy/checks/ssrf/internal_target_access"
+ openforwardproxy "github.com/cerberauth/proxyaudit/proxy/checks/ssrf/open_forward_proxy"
+ "github.com/cerberauth/proxyaudit/proxy/probebase"
+ "github.com/cerberauth/proxyaudit/proxy/scanctx"
+)
+
+func run(t *testing.T, srv *httptest.Server, aggressive bool, check harnessx.Check) harnessx.ScanSummary {
+ t.Helper()
+ target := scanctx.NewTarget(srv.URL, &scanctx.ScanContext{HTTPClient: srv.Client(), Aggressive: aggressive})
+ engine := harnessx.New(harnessx.WithChecks(probebase.HTTPFetchCheck, check))
+ summary, err := engine.Run(context.Background(), target)
+ require.NoError(t, err)
+ return summary
+}
+
+var internalHosts = map[string]bool{
+ "127.0.0.1": true, "localhost": true, "::1": true,
+ "169.254.169.254": true, "metadata.google.internal": true,
+ "10.0.0.1": true, "192.168.0.1": true,
+}
+
+// openProxy acts on the absolute-form request-target authority: it fetches
+// example.com and internal hosts, and gateway-errors on anything it can't
+// resolve. Origin-form requests get the backend page.
+func openProxy() http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if !strings.HasPrefix(r.RequestURI, "http://") {
+ _, _ = w.Write([]byte("BACKEND HOME PAGE"))
+ return
+ }
+ switch host := r.URL.Hostname(); {
+ case host == "example.com":
+ _, _ = w.Write([]byte("
Example Domain
illustrative examples
"))
+ case internalHosts[host]:
+ //nolint:gosec // G705: test stub echoes the forwarded host on purpose
+ _, _ = w.Write([]byte("INTERNAL-SERVICE " + host))
+ default: // unresolvable / unreachable
+ w.WriteHeader(http.StatusBadGateway)
+ }
+ })
+}
+
+// reverseProxy ignores the request-target authority and always serves its
+// backend — a correctly scoped proxy.
+func reverseProxy() http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ _, _ = w.Write([]byte("BACKEND HOME PAGE"))
+ })
+}
+
+func TestOpenForwardProxy_OpenProxy_Flagged(t *testing.T) {
+ srv := httptest.NewServer(openProxy())
+ defer srv.Close()
+
+ summary := run(t, srv, true, openforwardproxy.Check)
+ require.Len(t, summary.Observations, 1)
+ assert.Equal(t, "example.com", summary.Observations[0].Metadata["forwarded_host"])
+}
+
+func TestOpenForwardProxy_ReverseProxy_NoFindings(t *testing.T) {
+ srv := httptest.NewServer(reverseProxy())
+ defer srv.Close()
+
+ assert.Empty(t, run(t, srv, true, openforwardproxy.Check).Observations)
+}
+
+func TestOpenForwardProxy_NotAggressive_Skipped(t *testing.T) {
+ srv := httptest.NewServer(openProxy())
+ defer srv.Close()
+
+ summary := run(t, srv, false, openforwardproxy.Check)
+ assert.Empty(t, summary.Observations)
+ assert.True(t, skipped(summary, openforwardproxy.Check.ID))
+}
+
+func TestInternalTargetAccess_OpenProxy_Flagged(t *testing.T) {
+ srv := httptest.NewServer(openProxy())
+ defer srv.Close()
+
+ summary := run(t, srv, true, internaltargetaccess.Check)
+ require.NotEmpty(t, summary.Observations)
+ hosts := map[string]bool{}
+ for _, o := range summary.Observations {
+ hosts[o.Metadata["host"]] = true
+ }
+ assert.True(t, hosts["169.254.169.254"], "metadata endpoint should be flagged: %v", hosts)
+ assert.True(t, hosts["127.0.0.1"], "loopback should be flagged: %v", hosts)
+}
+
+func TestInternalTargetAccess_ReverseProxy_Skipped(t *testing.T) {
+ srv := httptest.NewServer(reverseProxy())
+ defer srv.Close()
+
+ summary := run(t, srv, true, internaltargetaccess.Check)
+ assert.Empty(t, summary.Observations)
+ assert.True(t, skipped(summary, internaltargetaccess.Check.ID))
+}
+
+func TestInternalTargetAccess_NotAggressive_Skipped(t *testing.T) {
+ srv := httptest.NewServer(openProxy())
+ defer srv.Close()
+
+ assert.True(t, skipped(run(t, srv, false, internaltargetaccess.Check), internaltargetaccess.Check.ID))
+}
+
+func skipped(summary harnessx.ScanSummary, id harnessx.CheckID) bool {
+ for _, r := range summary.Results {
+ if r.CheckID == id {
+ return r.Skipped
+ }
+ }
+ return false
+}
diff --git a/proxy/checks/ssrf/ssrfprobe/ssrfprobe.go b/proxy/checks/ssrf/ssrfprobe/ssrfprobe.go
new file mode 100644
index 0000000..5755926
--- /dev/null
+++ b/proxy/checks/ssrf/ssrfprobe/ssrfprobe.go
@@ -0,0 +1,138 @@
+// Package ssrfprobe sends HTTP requests with a literal, caller-chosen
+// request-target line against the target's host — specifically the
+// absolute-form target (`GET http://host/path HTTP/1.1`) that exercises
+// open-proxy / SSRF behaviour. net/http only emits an absolute-form
+// target in forward-proxy mode, so the probe writes the request line by
+// hand over a raw TCP (or TLS) connection and parses the response with
+// net/http's own reader.
+package ssrfprobe
+
+import (
+ "bufio"
+ "context"
+ "crypto/tls"
+ "fmt"
+ "io"
+ "net"
+ "net/http"
+ "net/url"
+ "strings"
+ "time"
+
+ "github.com/cerberauth/proxyaudit/proxy/scanctx"
+)
+
+// maxBodyBytes caps how much of a response body the probe buffers.
+const maxBodyBytes = 1 << 16 // 64 KiB — enough to fingerprint, not the whole page.
+
+// Response is one raw round-trip's outcome. Err is set when the connection
+// could not be established or the response could not be read (e.g. the
+// proxy dropped the connection); the status fields are then zero.
+type Response struct {
+ StatusCode int
+ Header http.Header
+ Body []byte
+ Err error
+}
+
+// Succeeded reports whether a response line was read at all.
+func (r *Response) Succeeded() bool { return r != nil && r.Err == nil && r.StatusCode != 0 }
+
+// RoundTrip opens one connection to baseURL's host and sends a GET whose
+// request-target is requestTarget (sent verbatim) with the given Host
+// header. Passing an origin-form target ("/") makes an ordinary request;
+// passing an absolute-form target ("http://other.host/") exercises
+// forward-proxy handling.
+func RoundTrip(ctx context.Context, sctx *scanctx.ScanContext, baseURL, requestTarget, hostHeader string) (*Response, error) {
+ u, err := url.Parse(baseURL)
+ if err != nil {
+ return nil, err
+ }
+
+ host := u.Hostname()
+ port := u.Port()
+ if port == "" {
+ if u.Scheme == "https" {
+ port = "443"
+ } else {
+ port = "80"
+ }
+ }
+ addr := net.JoinHostPort(host, port)
+
+ timeout := sctx.HTTPClient.Timeout
+ if timeout <= 0 {
+ timeout = 10 * time.Second
+ }
+ dialCtx, cancel := context.WithTimeout(ctx, timeout)
+ defer cancel()
+
+ conn, err := (&net.Dialer{}).DialContext(dialCtx, "tcp", addr)
+ if err != nil {
+ return &Response{Err: err}, nil
+ }
+ defer conn.Close()
+
+ if u.Scheme == "https" {
+ tlsConn := tls.Client(conn, tlsConfig(sctx, host))
+ if err := tlsConn.HandshakeContext(dialCtx); err != nil {
+ return &Response{Err: err}, nil
+ }
+ conn = tlsConn
+ }
+
+ if deadline, ok := dialCtx.Deadline(); ok {
+ _ = conn.SetDeadline(deadline)
+ }
+
+ req := fmt.Sprintf("GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: proxyaudit\r\nAccept: */*\r\nConnection: close\r\n\r\n", requestTarget, hostHeader)
+ if _, err := io.WriteString(conn, req); err != nil {
+ return &Response{Err: err}, nil
+ }
+
+ resp, err := http.ReadResponse(bufio.NewReader(conn), &http.Request{Method: http.MethodGet})
+ if err != nil {
+ return &Response{Err: err}, nil
+ }
+ defer resp.Body.Close()
+ body, _ := io.ReadAll(io.LimitReader(resp.Body, maxBodyBytes))
+ return &Response{StatusCode: resp.StatusCode, Header: resp.Header, Body: body}, nil
+}
+
+// tlsConfig mirrors the trust settings of the scan's HTTP client (so a
+// test server's self-signed cert, or a --insecure scan, behaves the same
+// over the raw connection) while pinning the SNI/ServerName to host.
+func tlsConfig(sctx *scanctx.ScanContext, host string) *tls.Config {
+ cfg := &tls.Config{ServerName: host, MinVersion: tls.VersionTLS12}
+ if t, ok := sctx.HTTPClient.Transport.(*http.Transport); ok && t.TLSClientConfig != nil {
+ src := t.TLSClientConfig
+ cfg.RootCAs = src.RootCAs
+ cfg.InsecureSkipVerify = src.InsecureSkipVerify
+ }
+ if sctx.RootCAs != nil {
+ cfg.RootCAs = sctx.RootCAs
+ }
+ return cfg
+}
+
+// HostHeader returns the authority (host, with port if non-default) to
+// send as the Host header for an ordinary request to baseURL.
+func HostHeader(baseURL string) string {
+ u, err := url.Parse(baseURL)
+ if err != nil {
+ return baseURL
+ }
+ return u.Host
+}
+
+// BodySignature returns a short, comparable fingerprint of a response body
+// (its length and leading bytes), for telling "served the real backend"
+// apart from "forwarded somewhere else" without embedding whole pages in
+// evidence.
+func BodySignature(body []byte) string {
+ head := body
+ if len(head) > 48 {
+ head = head[:48]
+ }
+ return fmt.Sprintf("%d bytes: %q", len(body), strings.TrimSpace(string(head)))
+}