exploit

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: AGPL-3.0 Imports: 16 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 loads the CISA Known Exploited Vulnerabilities (KEV) catalog and the FIRST EPSS scores, keyed by CVE id, and derives from them the kev / epss / priority attributes of a vulnerability finding. See docs/security/exploit-signals.md.

Index

Constants

View Source
const (
	// DefaultKEVURL is CISA's KEV catalog (JSON). The same file is published
	// in github.com/cisagov/kev-data.
	DefaultKEVURL = "https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json"
	// DefaultEPSSURL always points to today's EPSS scores (it redirects to the
	// dated file). FIRST asks bulk users to take this file, not the API.
	DefaultEPSSURL = "https://epss.empiricalsecurity.com/epss_scores-current.csv.gz"
)
View Source
const (
	// OutcomeImported: the feed changed and its data was replaced.
	OutcomeImported = "imported"
	// OutcomeUnchanged: the source answered "not modified".
	OutcomeUnchanged = "unchanged"
	// OutcomeFailed: the check failed; what was loaded is untouched.
	OutcomeFailed = "failed"
)

Outcomes of one feed in a Result.

View Source
const DefaultEPSSThreshold = 0.1

DefaultEPSSThreshold is the EPSS score from which a finding is prioritised. FIRST publishes no universal threshold; 0.1 is the figure commonly cited.

Variables

View Source
var (
	// ErrEmptyFeed: the feed parsed but holds no entry, which a real feed never
	// does: a wrong URL or a broken mirror must not wipe what is loaded.
	ErrEmptyFeed = errors.New("feed holds no entries")
	// ErrBadFeed: the feed is not in the expected format.
	ErrBadFeed = errors.New("feed is not in the expected format")
)

Errors of the feed parsers; none carries feed content.

View Source
var ErrBadCriteria = errors.New("invalid exploitation criteria")

ErrBadCriteria is returned for a condition that is not valid.

Functions

func CVEs

func CVEs(v models.Vulnerability) []string

CVEs returns the CVE ids a finding stands for: its own id when that is a CVE id, then the CVE ids among its aliases (a GHSA, GO or PYSEC advisory lists them). Sorted and without duplicates; empty when the finding has none.

func NormalizeCVE

func NormalizeCVE(id string) string

NormalizeCVE returns id upper-cased and trimmed when it is a CVE id (CVE-YYYY-NNNN...), and "" otherwise.

func SeverityRankOfCounts

func SeverityRankOfCounts(critical, high, medium, low int) int

SeverityRankOfCounts is the severity rank (4..0) of a result with these finding counts, the rule of the security_results view.

Types

type Aggregate

type Aggregate struct {
	KEVCount int
	// MaxEPSS is nil when no finding of the result is scored.
	MaxEPSS *float64
}

Aggregate is the kev_count and max_epss stored on a scan result.

type AliasResolver

type AliasResolver interface {
	// OSVCVEAliases returns, for each of the given ids that the mirror holds, the
	// CVE ids among its aliases; ids the mirror does not know are absent.
	OSVCVEAliases(ctx context.Context, ids []string) (map[string][]string, error)
}

AliasResolver maps vulnerability ids to the CVE ids the same record is known by in a local advisory mirror (the OSV mirror's alias table).

type Annotation

type Annotation struct {
	// CVE is the CVE id the signals were looked up by: the one in the KEV
	// catalog or with the highest EPSS score, else the first CVE id of the
	// finding. Empty when the finding has no CVE id.
	CVE string `json:"cve,omitempty"`
	// KEV is true when the CVE is in the CISA KEV catalog.
	KEV bool `json:"kev"`
	// KEVDateAdded and KEVDueDate (YYYY-MM-DD) are CISA's dates for a KEV CVE.
	KEVDateAdded *string `json:"kev_date_added,omitempty"`
	KEVDueDate   *string `json:"kev_due_date,omitempty"`
	// KEVRansomware is true when CISA knows the CVE to be used in ransomware campaigns.
	KEVRansomware bool `json:"kev_ransomware,omitempty"`
	// EPSS is the EPSS score (0..1) and EPSSPercentile its percentile; null when
	// no CVE of the finding is scored. EPSSDate is the day of the score file.
	EPSS           *float64 `json:"epss"`
	EPSSPercentile *float64 `json:"epss_percentile"`
	EPSSDate       *string  `json:"epss_date"`
	// Priority is the derived priority: kev, epss, then the severity.
	Priority Priority `json:"priority"`
}

Annotation is what the feeds say about one finding, in the shape the API returns it next to the finding's own fields.

type Criteria

type Criteria struct {
	// KEV trips on a CVE in the CISA KEV catalog.
	KEV bool
	// EPSSMin, when set, trips on an EPSS score at or above it.
	EPSSMin *float64
	// MinPriority, when set, trips on a priority at or above it (the order is
	// kev, epss, critical, high, medium, low).
	MinPriority Priority
}

Criteria are conditions on the exploitation signals of a finding, for a quality gate: a finding trips the gate when it meets ANY condition that is set.

func ParseCriteria

func ParseCriteria(kev, epssMin, minPriority string) (Criteria, error)

ParseCriteria builds Criteria from the raw values of the gate's parameters: kev "true" or "false" (or empty), epssMin a number in 0..1 (or empty) and minPriority one of the Priorities (or empty).

func (Criteria) Empty

func (c Criteria) Empty() bool

Empty reports whether no condition is set.

func (Criteria) Reasons

func (c Criteria) Reasons(a Annotation) []string

Reasons returns why the finding trips the gate, one short phrase per condition it meets ("kev", "epss>=0.5", "priority>=high"); empty when it trips none.

type EPSSMeta

type EPSSMeta struct {
	// ModelVersion is the model that produced the scores (v2026.06.15).
	ModelVersion string
	// ScoreDate is when the scores were generated; zero when the file has no header comment.
	ScoreDate time.Time
}

EPSSMeta is the header comment of an EPSS score file.

type EPSSReader

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

EPSSReader reads an EPSS score file (epss_scores-current.csv, optionally gzip-compressed) row by row.

func NewEPSSReader

func NewEPSSReader(r io.Reader, maxBytes int64) (*EPSSReader, error)

NewEPSSReader reads the header of an EPSS score file; r may be gzip-compressed. The rows are read with Next; the text, once uncompressed, may not exceed maxBytes (a compressed file can hold far more than its size suggests).

func (*EPSSReader) Meta

func (r *EPSSReader) Meta() EPSSMeta

Meta returns the header comment of the file.

func (*EPSSReader) Next

func (r *EPSSReader) Next() (models.EPSSScore, error)

Next returns the next score, or io.EOF after the last. A row that is not a CVE id with a score and a percentile in 0..1 is an error naming its line.

type Enricher

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

Enricher annotates findings with the signals of the loaded feeds.

func NewEnricher

func NewEnricher(lookup Lookup, threshold float64) *Enricher

NewEnricher returns an Enricher over lookup. threshold is the EPSS score from which a finding is prioritised. A nil lookup (the feeds are off or the database cannot hold them) annotates every finding with its severity priority.

func (*Enricher) Aggregates

func (e *Enricher) Aggregates(ctx context.Context, lists ...[]models.Vulnerability) ([]Aggregate, error)

Aggregates computes the stored aggregates of each list of findings, reading the feeds once for all lists.

func (*Enricher) Annotate

func (e *Enricher) Annotate(ctx context.Context, lists ...[]models.Vulnerability) ([][]Vulnerability, error)

Annotate returns the findings of each list with their annotations, in order, reading the feeds once for all lists. Without a loaded feed the annotations carry the severity priority only.

func (*Enricher) Enabled

func (e *Enricher) Enabled() bool

Enabled reports whether the enricher reads feeds (false: the feeds are off).

func (*Enricher) FeedStates

func (e *Enricher) FeedStates(ctx context.Context) (map[string]models.ExploitFeedState, error)

FeedStates returns the state of the KEV and EPSS feeds by name (empty when the feeds are off or were never checked).

func (*Enricher) Threshold

func (e *Enricher) Threshold() float64

Threshold returns the EPSS score from which a finding is prioritised.

func (*Enricher) WithAliases

func (e *Enricher) WithAliases(r AliasResolver) *Enricher

WithAliases makes the enricher resolve the findings that carry no CVE id (a bare GHSA, GO or PYSEC id) through r, so they still get the signals of the CVE they stand for. A nil r keeps the ids the findings carry. It returns e.

type FeedResult

type FeedResult struct {
	// Outcome is OutcomeImported, OutcomeUnchanged or OutcomeFailed.
	Outcome string
	// Entries is the number of rows loaded (OutcomeImported only).
	Entries int
	// Err is why the feed failed (OutcomeFailed only); it is logged, never shown to clients.
	Err error
}

FeedResult is the outcome of importing one feed.

type Importer

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

Importer downloads the KEV catalog and the EPSS scores and keeps them, and the per-result aggregates derived from them, in the database.

func NewImporter

func NewImporter(store Store, kev, epss Source, log *logger.Logger) *Importer

NewImporter returns an Importer for the two sources.

func (*Importer) RefreshAggregates

func (i *Importer) RefreshAggregates(ctx context.Context) (int, error)

RefreshAggregates recomputes kev_count and max_epss of every stored vulnerability result from the loaded feeds, in batches, and returns how many results changed.

func (*Importer) Run

func (i *Importer) Run(ctx context.Context) Result

Run checks both feeds, imports what changed and, when anything was imported, recomputes the aggregates of every stored vulnerability result. A feed that fails leaves its loaded data in place and is retried by the next run.

type KEVCatalog

type KEVCatalog struct {
	// Version is the catalog's catalogVersion and ReleasedAt its dateReleased
	// (zero when absent or unparseable).
	Version    string
	ReleasedAt time.Time
	Entries    []models.KEVEntry
}

KEVCatalog is a parsed KEV catalog.

func ParseKEV

func ParseKEV(r io.Reader) (*KEVCatalog, error)

ParseKEV reads the KEV catalog JSON (known_exploited_vulnerabilities.json). An entry with an invalid CVE id or date added is skipped; a duplicate keeps its first occurrence.

type Lookup

type Lookup interface {
	// ExploitSignals returns the KEV entry and EPSS score of each of the given
	// upper-case CVE ids that a feed lists; the others are absent from the map.
	ExploitSignals(ctx context.Context, cves []string) (map[string]models.ExploitSignal, error)
	// ExploitFeedStates returns the state of the feeds by name; a feed that was
	// never loaded is absent.
	ExploitFeedStates(ctx context.Context) (map[string]models.ExploitFeedState, error)
}

Lookup reads the loaded feeds.

type Priority

type Priority string

Priority is the derived remediation priority of a finding: a CVE in the KEV catalog first, then one whose EPSS score reaches the threshold, then the severity the scanner reported (its CVSS band).

const (
	PriorityKEV      Priority = "kev"
	PriorityEPSS     Priority = "epss"
	PriorityCritical Priority = "critical"
	PriorityHigh     Priority = "high"
	PriorityMedium   Priority = "medium"
	PriorityLow      Priority = "low"
	// PriorityNone is a finding without a usable severity.
	PriorityNone Priority = "none"
)

The priorities, from the highest.

func FromRank

func FromRank(rank int) Priority

FromRank returns the priority of a rank, PriorityNone for rank 0 or an unknown rank.

func ParsePriority

func ParsePriority(s string) (Priority, bool)

ParsePriority returns the priority named s, and false for an unknown name.

func Priorities

func Priorities() []Priority

Priorities lists the priorities in rank order, highest first.

func PriorityOf

func PriorityOf(severity string, cvss float64, kev bool, epss *float64, threshold float64) Priority

PriorityOf derives the priority of one finding: KEV first, then an EPSS score at or above threshold, then the severity.

func RowPriority

func RowPriority(kevCount int, maxEPSS *float64, severityRank int, threshold float64) Priority

RowPriority derives the priority of a stored scan result from its aggregates: kevCount findings in KEV, the highest EPSS score and the severity rank (4..0) of its worst finding.

func (Priority) Rank

func (p Priority) Rank() int

Rank returns the sort rank of p: kev 6, epss 5, critical 4 ... low 1, none 0.

type Result

type Result struct {
	KEV, EPSS FeedResult
	// Refreshed is the number of stored results whose aggregates changed.
	Refreshed int
	// RefreshErr is why the aggregates could not be recomputed.
	RefreshErr error
}

Result is the outcome of one Run.

type Source

type Source struct {
	// URL is the https URL of the file (an air-gapped mirror serves the same
	// file formats).
	URL string
	// Client fetches it; it is built by the caller with the SSRF policy that fits the URL.
	Client *http.Client
}

Source is where a feed is fetched from.

type StatusError

type StatusError struct{ Code int }

StatusError is a feed source answering something other than 200 or 304.

func (*StatusError) Error

func (e *StatusError) Error() string

type Store

type Store interface {
	Lookup
	ReplaceKEV(ctx context.Context, entries []models.KEVEntry, state models.ExploitFeedState) error
	ReplaceEPSS(ctx context.Context, state models.ExploitFeedState, next func() (models.EPSSScore, error)) (int, error)
	RecordExploitFeedCheck(ctx context.Context, name, sourceURL, errMsg string, checkedAt time.Time) error
	ListVulnExploitCandidates(ctx context.Context, afterID string, limit int) ([]models.VulnExploitCandidate, error)
	UpdateVulnExploitAggregates(ctx context.Context, aggs []models.VulnExploitAggregate) (int, error)
}

Store is what the importer needs of the database: the Lookup, the writes of the two feeds and the per-result aggregates.

type Vulnerability

type Vulnerability struct {
	models.Vulnerability
	Annotation
}

Vulnerability is a stored finding with its Annotation.

Jump to

Keyboard shortcuts

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