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 ¶
- Variables
- func HTTPTool(c *Client, base *url.URL) tools.Tool
- type Client
- func (c *Client) AtCap() bool
- func (c *Client) CapRefusals() int
- func (c *Client) Do(ctx context.Context, method, rawURL string, headers map[string]string, ...) (Exchange, error)
- func (c *Client) Exchange(id string) (Exchange, bool)
- func (c *Client) Exchanges() []Exchange
- func (c *Client) MaxRequests() int
- func (c *Client) Requests() int
- type ClientOptions
- type Endpoint
- type Exchange
- type Options
- type Result
Constants ¶
This section is empty.
Variables ¶
var ErrRequestCap = errors.New("request cap reached")
ErrRequestCap is returned when the scope's request cap has been used up.
Functions ¶
func HTTPTool ¶
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) AtCap ¶ added in v0.2.0
AtCap reports whether every request the scope allows has been sent.
func (*Client) CapRefusals ¶ added in v0.2.0
CapRefusals returns how many requests were not sent because the cap had been reached. A caller that hides ErrRequestCap from its own caller, as the model's request tool does, can still see here that requests were refused.
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) MaxRequests ¶ added in v0.2.0
MaxRequests returns the request cap of the scope.
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|route
}
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
// Seeds are route paths from the application's source ("/api/items",
// "GET /health", "about/"), added to the crawl next to the start URL
// so endpoints no page links to are found. Only plain GET paths are
// used: a route with a path parameter, a pattern or another method is
// left out. Seeds go through the same scope check as every link.
Seeds []string
}
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.