dast

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 25 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 dast analyzes a running web application that the operator owns or is authorized to test. Every request goes through a Client, and a Client cannot exist without an authz.Grant: the grant decides which hosts, paths and methods may be contacted, how many requests a run may send and how fast. Responses are untrusted input. Nothing a target returns can widen the scope, raise a cap or change which probes exist.

Index

Constants

This section is empty.

Variables

View Source
var ErrRequestCap = errors.New("request cap reached")

ErrRequestCap is returned when the scope's request cap has been used up.

Functions

func HTTPTool

func HTTPTool(c *Client, base *url.URL) tools.Tool

HTTPTool returns the investigator tool "http_request" bound to the client. Its arguments are {"method": "GET", "url": "/path?x=1", "headers": {...}, "body": "..."}, where url is a path relative to base or an absolute in-scope URL. The result is the exchange id, the status line, the response headers and the first 6000 bytes of the body. A request outside the scope, or with a method the scope does not allow, is an error from Run that explains the scope rule. The tool has no argument that reaches the scope, the request cap or the rate limit.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client sends requests inside an authorized scope and records them.

func NewClient

func NewClient(g *authz.Grant, opts ClientOptions) (*Client, error)

NewClient returns a client bound to a grant. A nil grant is an error: there is no way to build a client without authorization.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, rawURL string, headers map[string]string, body []byte) (Exchange, error)

Do sends one request. The URL and method are checked with the grant before anything is sent; a refused request returns an error wrapping authz.ErrNotAuthorized and sends nothing. Redirects are followed manually, at most 5 hops, each hop re-checked against the scope; a hop that leaves scope is not followed and is recorded in Note. Every hop counts against the request cap and waits for the rate limit. The returned exchange is the last hop.

func (*Client) Exchange

func (c *Client) Exchange(id string) (Exchange, bool)

Exchange returns the recorded exchange with the given id.

func (*Client) Exchanges

func (c *Client) Exchanges() []Exchange

Exchanges returns a copy of every recorded exchange, in order.

func (*Client) Requests

func (c *Client) Requests() int

Requests returns how many requests have been sent, counting every redirect hop.

type ClientOptions

type ClientOptions struct {
	// HTTP is the transport to use. Nil means a client with a 15 second
	// timeout. Redirect handling of a supplied client is replaced: the
	// Client follows redirects itself so every hop is checked.
	HTTP *http.Client
	// OnRecord is called once per exchange, in order. It must not call Do.
	OnRecord func(Exchange)
	// Sleep waits between requests for the rate limit. Nil means a wait
	// that ends early when the request context is cancelled.
	Sleep func(time.Duration)
	// UserAgent defaults to "spackle (authorized security testing)".
	UserAgent string
	// Headers are sent on every request (operator-supplied authentication).
	Headers map[string]string
}

ClientOptions configure a Client.

type Endpoint

type Endpoint struct {
	Method string   `json:"method"`
	Path   string   `json:"path"`
	Params []string `json:"params,omitempty"` // query or form field names, sorted
	Source string   `json:"source"`           // link|form|start
}

Endpoint is something discovered on the target.

type Exchange

type Exchange struct {
	ID          string            `json:"id"` // "X-0001", sequential per client
	Method      string            `json:"method"`
	URL         string            `json:"url"`
	ReqHeaders  map[string]string `json:"request_headers,omitempty"`  // credential values replaced by "[redacted]"
	ReqBody     string            `json:"request_body,omitempty"`     // redacted, capped at 16 KiB
	Status      int               `json:"status"`                     // 0 when no response
	RespHeaders map[string]string `json:"response_headers,omitempty"` // Set-Cookie keeps attributes, not the value
	RespBody    string            `json:"response_body,omitempty"`    // redacted, capped at 64 KiB, valid UTF-8
	DurationMS  int64             `json:"duration_ms"`
	Note        string            `json:"note,omitempty"` // for example a redirect that was not followed
	Error       string            `json:"error,omitempty"`
}

Exchange is one recorded request and response.

type Options

type Options struct {
	// MaxPages bounds how many pages the crawl fetches. Zero means 40.
	MaxPages int
}

Options configure Baseline.

type Result

type Result struct {
	Leads     []seed.Lead
	Endpoints []Endpoint
	Notes     []string // what was skipped and why (cap reached, unsafe methods not allowed, ...)
}

Result is what a baseline run found.

func Baseline

func Baseline(ctx context.Context, c *Client, start *url.URL, opts Options) (Result, error)

Baseline crawls from start within scope and runs the passive and active checks. It never returns an error for a finding-level problem; errors are for "could not reach the target at all" and for a cancelled run, which also returns what was found so far.

Jump to

Keyboard shortcuts

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