exploit

package
v0.1.0-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package exploit turns an answer key into attempted exploitation.

Every other eval in this repository grades DETECTION: given a target whose weaknesses were established by hand, does the scanner name them correctly. That leaves the more important question unasked. A finding is a claim that somebody could do something, and a tool can be precise about exposures nobody can reach.

So this package does the thing the finding claims is possible, holding only the public anon key — the credential any visitor to the site already has — and keeps what came back. A read exploit passes when real rows arrive. A write exploit passes when a row is written AND read back, because a 201 with nothing behind it proves only that a request was accepted. A storage exploit passes when bytes are retrieved, and separately when bytes are uploaded and fetched again.

It is deliberately independent of the scanner. Nothing here imports the probe or surface packages, and nothing consults a scan result: if both the scanner and this harness shared a wrong assumption about what PostgREST means by 200, they would agree with each other and both be wrong. The link between them — every exploit has a finding, every finding an exploit — is asserted afterwards, by comparing two independently produced lists.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PocketBaseDeleteAccount

func PocketBaseDeleteAccount(ctx context.Context, base, recordID, token string) error

PocketBaseDeleteAccount removes an account this harness created. Deleting needs the account's own token, which is what it is given.

Types

type AppResult

type AppResult struct {
	// Exploit, not ID: this names the ACT that was attempted, and it is the id
	// in fixtures/application/answer-key.yaml, not a finding id. The
	// distinction has teeth. internal/emitsites reads every id-shaped literal
	// in a field called ID as a finding the code can emit, and the
	// documentation audit failed on all four the moment this file compiled --
	// correctly, because a demonstrator is not a check and its vocabulary must
	// not be mistaken for one. The key's scanner_finding column is where the
	// two vocabularies meet, in one place, deliberately.
	Exploit string
	// Done is true when the technique retrieved what the key says it should.
	Done bool
	// Detail is what happened, in the words of the thing that happened.
	Detail string
}

AppResult is one demonstration.

func CrossIdentityRead

func CrossIdentityRead(ctx context.Context, api, path, tokenA, tokenB string) AppResult

CrossIdentityRead demonstrates one account receiving another's record.

Three answers, as the finding requires: anonymous refused, A served, B served THE SAME BODY. Two would report a public catalogue.

func PublicRecord

func PublicRecord(ctx context.Context, api string) AppResult

PublicRecord demonstrates a record served to a caller holding nothing.

The retrieval is the proof, and so is the address inside it: an endpoint that is open and holds nothing is not this finding.

func PublishedSpec

func PublishedSpec(ctx context.Context, api string) AppResult

PublishedSpec demonstrates a specification naming endpoints the front end never calls.

func RewriteBypass

func RewriteBypass(ctx context.Context, api, path string) AppResult

RewriteBypass demonstrates a refusal that a header gets past.

Three requests, because two would not settle it: the plain request must be refused, the header request must return data, and the SAME request without the header must not -- otherwise the header changed nothing and the URL simply answers.

type Exploit

type Exploit struct {
	ID       string `yaml:"id"`
	Relation string `yaml:"relation"`
	// Collection is PocketBase's unit, and is deliberately NOT spelled
	// "relation". A collection is not a table: it carries its own rules rather
	// than policies, and reusing the Supabase word here would be the kind of
	// forced fit that makes an abstraction look real while the concepts
	// underneath disagree.
	Collection string `yaml:"collection"`
	Routine    string `yaml:"routine"`
	Bucket     string `yaml:"bucket"`
	Object     string `yaml:"object"`
	// Technique names the exploitation method explicitly.
	//
	// The first version dispatched by sniffing the prose in Class for words
	// like "escalation". The escalation entry read "authenticated-only read
	// reachable via open signup", which contains no such word, so it fell
	// through to a plain anonymous read, correctly found nothing, and reported
	// the exploit as failing. The harness was grading the answer key's English
	// rather than the target.
	// Schema addresses a PostgREST schema other than the default. Needed
	// because the scanner now reports findings in every exposed schema, and a
	// cross-check that cannot REACH what the scanner reports would grade those
	// findings as unproven noise -- which is exactly what it did the first time
	// a relation in a reporting schema was found.
	Schema string `yaml:"schema"`
	// MarkerColumn is the text column a write technique stamps so the row can
	// be found again. Empty means "author", which is what the first fixture
	// table happened to have -- a hardcoding that only showed up when a second
	// writable table with different columns was added and every insert failed
	// with "Could not find the 'author' column".
	MarkerColumn string `yaml:"marker_column"`
	// Argument is the parameter name a SQL-executing routine takes. Empty
	// means "query", which is what the routines people actually write are
	// called -- exec_sql(query text) is the shape that appears in migration
	// helpers and admin pages.
	Argument string `yaml:"argument"`
	// App is the page a browser loads. Defaults to the key's app section, and
	// an entry may name a different one -- an archived copy of a bundle is the
	// same technique pointed at a different URL, not a second technique.
	App string `yaml:"app_url"`
	// Route is an application path, for the findings that are about somebody's
	// server rather than about their database.
	Route string `yaml:"route"`
	// Origin is where a surface lives when it is not on the key's base_url.
	// Edge Functions are served by a different process on a different port in
	// the fixture, and by the same origin under /functions/v1 in the product;
	// naming it per entry covers both without a second answer key.
	Origin string `yaml:"origin"`
	// Function is an Edge Function name.
	Function  string `yaml:"function"`
	Technique string `yaml:"technique"`
	Class     string `yaml:"class"`
	Why       string `yaml:"why"`
	Proof     string `yaml:"proof"`
	Rows      int    `yaml:"expect_rows"`
	Finding   string `yaml:"scanner_finding"`
}

Exploit is one claim that must be demonstrated, not merely detected.

type FirebaseExploit

type FirebaseExploit struct {
	ID         string `yaml:"id"`
	Technique  string `yaml:"technique"`
	Collection string `yaml:"collection"`
	Path       string `yaml:"path"`
	Class      string `yaml:"class"`
	Why        string `yaml:"why"`
	Proof      string `yaml:"proof"`
	// MustRecognise and MustIgnore grade a CLASSIFIER rather than a
	// permission. The Remote Config template is fetchable by design -- that is
	// the product working -- so the claim being tested is which of its values
	// are credentials, and a classifier that says yes to everything is not
	// one.
	MustRecognise []string `yaml:"must_recognise"`
	MustIgnore    []string `yaml:"must_ignore"`
	Bucket        string   `yaml:"bucket"`
	// Function is the deployed name. It is its own field rather than a reuse
	// of Path because Path means an RTDB path in CheckProtected, and a control
	// probe that is ambiguous about what it is probing is not a control.
	Function string `yaml:"function"`
	Docs     int    `yaml:"expect_docs"`
	Keys     int    `yaml:"expect_keys"`
	Finding  string `yaml:"scanner_finding"`
}

FirebaseExploit is one claim that has to be demonstrated.

type FirebaseKey

type FirebaseKey struct {
	ProjectID string `yaml:"project_id"`
	// RTDB is the database's own origin, which is regional: a project in
	// europe-west1 answers on firebasedatabase.app and 404s on firebaseio.com
	// with a correctUrl in the body naming the right one.
	RTDB      string              `yaml:"rtdb"`
	Notes     string              `yaml:"notes"`
	Exploits  []FirebaseExploit   `yaml:"exploits"`
	Protected []FirebaseProtected `yaml:"protected"`
}

FirebaseKey is the ground truth for one Firebase project.

func LoadFirebaseKey

func LoadFirebaseKey(path string) (*FirebaseKey, error)

LoadFirebaseKey reads an answer key.

type FirebaseProtected

type FirebaseProtected struct {
	Collection string `yaml:"collection"`
	Path       string `yaml:"path"`
	Function   string `yaml:"function"`
	Why        string `yaml:"why"`
	// ClosedToSignup distinguishes the two kinds of closed, and the difference
	// is the most important one on this backend.
	//
	// `allow read: if request.auth != null` refuses anonymous callers and
	// admits anyone who signs up, so it is closed to the first question and
	// wide open to the second -- reporting it as protected would be the error
	// in the other direction. `request.auth.uid == resource.data.owner` is
	// closed to both, and a scanner that reports it is producing the false
	// positive that matters.
	//
	// Only entries with this set must be absent from the WHOLE report. The
	// others must merely be absent from what anonymous callers are told they
	// can reach.
	ClosedToSignup bool `yaml:"closed_to_signup"`
}

FirebaseProtected is something that must stay closed. Unlike the Supabase side, existence here is an assertion of the KEY rather than of the response: Firestore answers 403 identically for a protected collection and one that does not exist, so only a document saying "this exists" makes a refusal meaningful.

type FirebaseRunner

type FirebaseRunner struct {
	ProjectID string
	APIKey    string
	RTDB      string
	// AppID and ProjectNumber address the Remote Config client API, which is
	// keyed by project NUMBER rather than by id and identifies the calling
	// app. Neither is a secret and neither is guessable; both ship in the
	// config object every application hands its browsers.
	AppID         string
	ProjectNumber string
	HTTP          *http.Client
	Now           func() time.Time

	// FunctionHost overrides where functions are called, for the same reason
	// the scanner has functionHostOverride: a test asserting that this harness
	// does NOT call something must not call Google to prove it.
	FunctionHost string

	// Invoke gates the one technique that RUNS code instead of reading data.
	// Everything else here retrieves; calling a function executes whatever
	// somebody deployed, and no answer key can know what that does.
	Invoke bool
}

FirebaseRunner attempts the exploits.

func NewFirebaseRunner

func NewFirebaseRunner(projectID, apiKey, rtdb string) *FirebaseRunner

NewFirebaseRunner builds a runner with the same timeout policy as the Supabase one.

func (*FirebaseRunner) CheckProtected

func (r *FirebaseRunner) CheckProtected(ctx context.Context, k *FirebaseKey) []Outcome

CheckProtected requires everything the key calls closed to refuse.

func (*FirebaseRunner) Run

func (r *FirebaseRunner) Run(ctx context.Context, k *FirebaseKey) []Outcome

Run attempts every exploit in the key.

type Key

type Key struct {
	ProjectRef string `yaml:"project_ref"`
	BaseURL    string `yaml:"base_url"`
	Notes      string `yaml:"notes"`
	App        struct {
		URL string `yaml:"url"`
	} `yaml:"app"`
	Exploits  []Exploit `yaml:"exploits"`
	Protected []struct {
		Relation string `yaml:"relation"`
		// Schema, so a relation that must stay closed can be checked in any
		// exposed schema rather than only the default one.
		Schema string `yaml:"schema"`
		Why    string `yaml:"why"`
	} `yaml:"protected"`
}

Key is the ground truth for one project: what should be exploitable, what must not be, and how to reach it.

func LoadKey

func LoadKey(path string) (*Key, error)

LoadKey reads an answer key.

type NeonExploit

type NeonExploit struct {
	ID       string `yaml:"id"`
	Table    string `yaml:"table"`
	Class    string `yaml:"class"`
	Rows     int    `yaml:"expect_rows"`
	Finding  string `yaml:"scanner_finding"`
	DataAPI  string `yaml:"-"`
	AuthURL  string `yaml:"-"`
	Origin   string `yaml:"-"`
	Email    string `yaml:"-"`
	Password string `yaml:"-"`

	// Technique names which demonstration this entry asks for. Dispatch is on
	// this field and nothing else: reading intent out of prose would make the
	// key's wording load-bearing.
	Technique string `yaml:"technique"`

	// Why is the key's own account of the grant. It is quoted verbatim by the
	// technique that cannot demonstrate one, so the reason travels with the
	// result rather than living only in the file.
	Why string `yaml:"why"`

	// Column and Marker say what a write puts in the row, so the caller can
	// find exactly what it wrote and take it back out again.
	Column string `yaml:"column"`
	Marker string `yaml:"-"`

	// IOwnThis gates every technique that writes. Unset means nothing is sent.
	IOwnThis bool `yaml:"-"`

	// Token and HTTP let a caller supply a session instead of establishing
	// one. Empty Token runs the full Neon Auth sequence, which is what happens
	// against a live lab; a supplied one exercises the request under test on
	// its own, which is what lets a recorded exchange replay offline.
	Token string       `yaml:"-"`
	HTTP  *http.Client `yaml:"-"`
}

A NeonExploit is one entry from the Neon answer key.

type NeonKey

type NeonKey struct {
	Endpoint    string        `yaml:"endpoint"`
	Exploitable []NeonExploit `yaml:"exploitable"`
	Protected   []NeonTable   `yaml:"protected"`
}

A NeonKey is the ground truth for one Neon project.

func LoadNeonKey

func LoadNeonKey(path string) (*NeonKey, error)

LoadNeonKey reads a committed answer key.

type NeonRunner

type NeonRunner struct {
	DataAPI  string
	AuthURL  string
	Origin   string
	Email    string
	Password string
	// Marker is what a write puts in the row it inserts, so the fixture can be
	// restored by deleting exactly that.
	Marker string
	// IOwnThis gates every technique that writes.
	IOwnThis bool
}

A NeonRunner executes the entries of a key against one project.

func (*NeonRunner) Run

func (r *NeonRunner) Run(ctx context.Context, k *NeonKey) []Outcome

Run attempts every entry in the key.

type NeonTable

type NeonTable struct {
	Table string `yaml:"table"`
	Why   string `yaml:"why"`
}

A NeonTable is something that must stay closed.

type Outcome

type Outcome struct {
	ID        string `json:"id"`
	Class     string `json:"class"`
	Target    string `json:"target"`
	Succeeded bool   `json:"succeeded"`
	Detail    string `json:"detail"`
	Request   string `json:"request"`
	Status    int    `json:"status"`
	// Unmeasured marks an outcome the harness could not establish either way,
	// as against one it established as a failure.
	//
	// Added after an audit reported "1 of 8 documented exploits did not work
	// against the lab: signup-escalation: the collection refused a signed-up
	// caller too: HTTP 429". The collection refused nothing -- the Firestore
	// free tier ran out mid-run and the read was rate-limited. A 429 is an
	// inability to look, and grading it as a refusal reports the lab as MORE
	// secure than it is, which is the same false negative this project refuses
	// everywhere else, arriving as a false FAILURE.
	Unmeasured bool `json:"unmeasured,omitempty"`

	// Residue names what a probe created and could not remove.
	//
	// Every write technique creates something, reads it back and deletes it.
	// The delete's status used to be interpolated into the success message and
	// never checked, so a lab granting create and refusing delete produced a
	// successful outcome whose prose contained the number 403 and a claim that
	// the object had been removed. The scanner reports exactly that shape
	// against other people's projects as unruly-probe-object-left-behind; a
	// harness aimed at our own lab has no business being quieter.
	Residue    string    `json:"residue,omitempty"`
	RowsGot    int       `json:"rows_got,omitempty"`
	RowsWanted int       `json:"rows_wanted,omitempty"`
	Sample     string    `json:"sample,omitempty"`
	At         time.Time `json:"at"`
}

Outcome records what actually happened, in enough detail for somebody who did not run it to check the conclusion rather than take it on trust.

func AnonRead

func AnonRead(ctx context.Context, base, collection string) Outcome

AnonRead demonstrates that a collection is readable with no credential.

Rows are the proof. A 200 is not: PocketBase returns 200 with an empty items array when the rule filtered everything, which is exactly the shape a world-open collection with no records also has.

func NeonEscalation

func NeonEscalation(ctx context.Context, e NeonExploit) Outcome

NeonEscalation signs up through Neon Auth and reads a table with the token.

This is a SECOND implementation of the same sequence internal/neonauth performs, written deliberately rather than by importing it. The harness imports nothing from the scanner, and that independence is the reason its agreement with the scan means anything: if both arrive at the same rows through separately written code, the measurement is corroborated rather than merely repeated.

The sequence has three steps and each fails quietly if got wrong: sign-up needs an Origin header, the session comes back as a COOKIE, and the token exchange refuses a bearer with 401.

Nothing is written to the target. Sign-up creates an account, which IS an artefact -- that is why this runs only against a lab the operator owns, and why the account is reused rather than churned.

func NeonWrite

func NeonWrite(ctx context.Context, e NeonExploit) Outcome

NeonWrite demonstrates that an account which signed itself up can INSERT.

The demonstration is the RETURNED ROW, not the status. PostgREST answers 201 to an accepted insert and, by default, returns nothing at all -- so a 201 alone says a request was accepted, which is the boolean this project refuses to call evidence. Prefer: return=representation makes the server hand back what it stored, and that row is the proof: it exists, it has an id the database assigned, and it carries the value that was sent.

Two safeties, both structural:

  • Nothing is sent without IOwnThis. The consent is checked before the request is BUILT, so a harness run without it cannot have written.
  • The row is written with a Marker the caller chooses, so the caller can delete exactly what this wrote. internal/neonfixture does the deleting, as the owner: on this fixture the authenticated role can insert but not delete, which is the whole reason a write probe needs an owner-side undo rather than an apologetic second request.

Token may be supplied by the caller. When it is empty the full Neon Auth sequence runs, which is what happens against the live lab; when it is set, the write is exercised on its own, which is what lets a recorded transcript replay it offline. The sequence is still implemented here either way -- the independence that makes this harness worth having is not traded for it.

func SignupEscalation

func SignupEscalation(ctx context.Context, base, collection, email, password string) (Outcome, string, string)

SignupEscalation demonstrates that registering an account unlocks a collection an anonymous caller cannot read.

It returns the outcome, the account it created and that account's token, so the caller can delete it. Returning the id alone was not enough: deleting a PocketBase user needs its own token, so an API that hands back only the id makes cleanup impossible and guarantees the residue it warns about. Found by running the cross-check and reading the account it left behind.

type Runner

type Runner struct {
	Base    string
	AnonKey string
	HTTP    *http.Client
	// Now is injected so evidence timestamps are reproducible under test.
	Now func() time.Time
}

Runner performs exploitation against one project.

func NewRunner

func NewRunner(base, anonKey string) *Runner

NewRunner returns a Runner holding only the anon key, which is the point: everything it demonstrates is available to any visitor.

func (*Runner) CheckProtected

func (r *Runner) CheckProtected(ctx context.Context, k *Key) []Outcome

CheckProtected verifies the relations that must NOT yield anything.

Graded as hard as the exploits. A harness that only proves exploits cannot tell a scanner that is right from one that flags everything.

func (*Runner) MintAuthenticatedJWT

func (r *Runner) MintAuthenticatedJWT(ctx context.Context) (string, error)

MintAuthenticatedJWT signs up and returns the session token.

Exposed because the scanner needs the same credential to measure escalation: its -user-jwt flag answers "what does the authenticated role reach that anon does not", and on a project with open signup that role is available to anyone. Minting it here is not a shortcut around the scanner's consent model — it IS the exploit, performed the way an attacker performs it.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, k *Key) []Outcome

Run attempts every exploit in the key and returns what happened.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL