exploit

package
v0.193.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 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 enriches a finding's severity with real-world exploitability signals: CISA KEV (Known Exploited Vulnerabilities, confirmed exploited in the wild) and FIRST EPSS (Exploit Prediction Scoring System, probability of exploitation). Data is loaded from local files (bring-your-own), so enrichment is optional and works offline.

Index

Constants

View Source
const (
	// SignalKEV is confirmed, observed exploitation.
	SignalKEV = "kev"
	// SignalEPSS is a predicted probability of exploitation.
	SignalEPSS = "epss"
)

The signals a Source can escalate on, as they appear in an Escalation.

View Source
const DatasetGoVulnDB = "govulndb"

DatasetGoVulnDB names the Go vulnerability database, in a run's list of what it consulted and on a finding whose CVE was found there.

Variables

This section is empty.

Functions

func CVE added in v0.179.0

func CVE(res sarif.Result) string

CVE is the CVE a finding is looked up by in KEV and EPSS: the one its rule id names, or, where the rule id names none, the first CVE among its aliases in the order the scanner recorded them. Empty for a finding that names no CVE anywhere, which neither dataset can raise.

The aliases matter because a scanner names a finding by the advisory it matched on. Grype without --by-cve reports `GHSA-4rgh-jx4f-qfcq` and relates CVE-2020-35669 to it, and a lookup reading only the rule id would leave a CVE on KEV unraised with nothing on the finding to say it was skipped.

The rule id first, so a finding that names its CVE is never re-keyed by an alias, and the first alias rather than any, so the same report ranks the same way every time. Last, where the finding names no CVE at all, the first CVE an advisory database lists for it (see Advisories), which is read only once the scanner's own identifiers have none to give.

func LoadEPSS

func LoadEPSS(r io.Reader) (map[string]float64, error)

LoadEPSS parses a FIRST EPSS scores CSV (columns: cve,epss,percentile; leading #comment and header lines are ignored) into a CVE→score map. Source: https://www.first.org/epss/data_stats

func LoadKEV

func LoadKEV(r io.Reader) (map[string]bool, error)

LoadKEV parses the CISA Known Exploited Vulnerabilities JSON catalog into a CVE set. Source: https://www.cisa.gov/known-exploited-vulnerabilities-catalog

func LookupIDs added in v0.181.0

func LookupIDs(res sarif.Result) []string

LookupIDs are the identifiers a finding names that an advisory lookup can be keyed on: its Go, GitHub, PyPI and RustSec advisory ids, from the rule id and then the aliases, each once.

func Matchable added in v0.175.0

func Matchable(ruleID string) bool

Matchable reports whether ruleID names a CVE, which is what KEV and EPSS are keyed on. CVE is the question to ask of a finding, which also reads the CVEs it lists as aliases.

func NeedsLookup added in v0.181.0

func NeedsLookup(res sarif.Result) bool

NeedsLookup reports whether a finding names no CVE and does name an id the Go vulnerability database could resolve to one: a Go advisory id, or a GitHub advisory id on a Go module. OSVEcosystem says which OSV.dev dataset could resolve one of any ecosystem. The database records Go advisories only, so a GitHub advisory about an npm or PyPI package is not one it could answer, and fetching the database would not change that finding.

func OSVEcosystem added in v0.190.0

func OSVEcosystem(res sarif.Result) string

OSVEcosystem is the OSV.dev ecosystem whose advisories could give a CVE to a finding that names none and does name an advisory id: "npm", "PyPI", "crates.io" or "Go", or "" for a finding that names its CVE, names no advisory id, or is about another ecosystem.

Read from the finding's package where it has one, and otherwise from an id only one ecosystem issues: PYSEC for PyPI, RUSTSEC for crates.io, GO for Go. A GitHub advisory id alone says nothing about the ecosystem.

Types

type Advisories added in v0.181.0

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

Advisories is an advisory database's records and the identifiers each lists as its aliases, read to find the CVE of a finding its scanner named only by another id, so KEV and EPSS can match it.

The Go vulnerability database lists, for each `GO-…` record, the CVE and GitHub advisory ids of the same vulnerability in other databases. That is the only claim read from it: a record's CVEs are given to a finding that names that record, or a GitHub advisory id exactly one record lists, and to nothing else.

func NewAdvisories added in v0.181.0

func NewAdvisories(dataset string, fetched time.Time, records map[string][]string) *Advisories

NewAdvisories returns the records of dataset, fetched at fetched, with records mapping each record's id to the aliases it lists. A zero fetched leaves the date off what it finds.

func NewOSVAdvisories added in v0.190.0

func NewOSVAdvisories(dataset string, fetched time.Time, records map[string][]string, licenses map[string]string) *Advisories

NewOSVAdvisories returns the records of an OSV.dev ecosystem archive, named dataset, as NewAdvisories does, with licenses mapping a record's id to the license the record states on itself. A lookup from it names the record's source, license and link (sarif.CVELookup).

func (*Advisories) Len added in v0.181.0

func (a *Advisories) Len() int

Len is how many records the database holds.

func (*Advisories) Lookup added in v0.181.0

func (a *Advisories) Lookup(res sarif.Result) *sarif.CVELookup

Lookup is the CVEs the database lists for a finding that names none itself, or nil.

Nil wherever the answer is uncertain, because a CVE wrongly given to a finding can raise it to critical on somebody else's exploitation. A GitHub advisory id more than one record lists says nothing about which of them this finding is. Two ids on one finding may lead to two records, as a RustSec advisory and the GitHub advisory of the same flaw are two records in OSV.dev's data, and they give an answer only where every one of them that lists a CVE lists the same ones. A record that lists no CVE gives nothing.

type Options added in v0.56.0

type Options struct {
	// KEV is the set of CVEs CISA has observed being exploited.
	KEV map[string]bool
	// EPSS maps a CVE to its exploitation probability.
	EPSS map[string]float64
	// ThresholdFrom names what set Threshold, the default, a descriptor key, or a flag. So a report
	// can say who chose the line a score was measured against.
	ThresholdFrom string
	// Threshold is the EPSS probability at or above which severity is raised one level. Zero or
	// less disables the EPSS bump; KEV still applies.
	Threshold float64
	// Fetched says when each dataset was obtained, so an escalation can cite a date. Keys are
	// SignalKEV and SignalEPSS; a zero time simply omits the date.
	Fetched map[string]time.Time
	// Stale marks the datasets that were older than the run's maxAge when they were read, keyed like
	// Fetched. Only the caller knows the limit, so it says; the source only carries the answer.
	Stale map[string]bool
	// Advisories finds the CVE of a finding whose scanner named it only by a Go or GitHub advisory
	// id. Nil resolves nothing; KEV and EPSS then match only the CVEs findings name themselves.
	Advisories *Advisories
	// OSV holds OSV.dev's advisories for each ecosystem read, keyed as OSVEcosystem names them:
	// "npm", "PyPI", "crates.io", "Go". A finding of an ecosystem with none resolves nothing here.
	OSV map[string]*Advisories
}

Options builds a Source. Every field is optional; a Source with no data enriches nothing.

type Source

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

Source holds exploitability data plus the EPSS threshold for a severity bump.

func New

func New(kev map[string]bool, epss map[string]float64, threshold float64) *Source

New returns a Source. threshold is the EPSS probability (0–1) at or above which a finding's severity is bumped one level; a threshold ≤ 0 disables the EPSS bump (KEV still applies).

The convenience form, for a caller with nothing to say about where the data came from. Use NewFrom to record fetch dates, without which an escalation cannot cite one.

func NewFrom added in v0.56.0

func NewFrom(opts Options) *Source

NewFrom returns a Source built from opts.

func (*Source) Consulted added in v0.107.0

func (s *Source) Consulted() []sarif.Consulted

Consulted names the datasets this source can answer from, with the day each was obtained.

Which is a different statement from any escalation, and the one a reader needs first. An escalation is recorded only when a signal *moved* a finding, so its absence covers three unrelated cases: the CVE is not listed, it is listed but was already at the top band, and nobody loaded the data at all. Silence reads as the last of those, which is the reading that makes a ranking look unexplained.

Sorted, so evidence produced twice from the same inputs is byte-identical.

func (*Source) Empty

func (s *Source) Empty() bool

Empty reports whether the source carries no data (no enrichment possible).

func (*Source) Enrich

func (s *Source) Enrich(base sarif.Severity, ruleID string) sarif.Severity

Enrich raises base severity using exploitability signals for the CVE referenced by ruleID: on KEV → critical; else EPSS ≥ threshold → one level higher. Findings without a CVE ruleID (secrets, SAST, IaC) or with no matching data return base unchanged. Pass CVE(res) rather than the rule id for a finding that may name its CVE only as an alias.

func (*Source) Explain added in v0.56.0

func (s *Source) Explain(base sarif.Severity, ruleID string) (sarif.Severity, *sarif.Escalation)

Explain does what Enrich does and also says why, returning nil when nothing moved.

Separate from Enrich rather than replacing it because most callers only want the severity, and a reason nobody reads is a reason nobody keeps accurate.

func (*Source) Exploited added in v0.165.3

func (s *Source) Exploited(ruleID string) *sarif.Match

Exploited is the KEV entry for the CVE ruleID references, or nil where KEV does not list it or was not loaded.

Answered whether or not Explain moved anything. Explain records a change of band, and a CVE the scanner already rated critical is listed and changes nothing, so a caller reading only the escalation loses the one fact that orders the fix list.

func (*Source) Lookup added in v0.181.0

func (s *Source) Lookup(res sarif.Result) *sarif.CVELookup

Lookup is the CVEs this source's advisory databases list for a finding that names no CVE itself, or nil where it names one, no database was read, or none gives a single answer.

The Go vulnerability database answers first, as it is the source of the Go ids govulncheck reports. Where it gives nothing, the OSV.dev advisories of the finding's ecosystem are asked, which also hold the GitHub record of a Go flaw whose Go record lists no CVE yet.

Jump to

Keyboard shortcuts

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