Documentation
¶
Overview ¶
Package threatintel provides the threat intelligence domain model.
Index ¶
- Variables
- type EPSSRepository
- type EPSSRiskLevel
- type EPSSScore
- func (e *EPSSScore) CVEID() string
- func (e *EPSSScore) CreatedAt() time.Time
- func (e *EPSSScore) IsCriticalRisk() bool
- func (e *EPSSScore) IsHighRisk() bool
- func (e *EPSSScore) IsTopPercentile(n float64) bool
- func (e *EPSSScore) ModelVersion() string
- func (e *EPSSScore) Percentile() float64
- func (e *EPSSScore) Score() float64
- func (e *EPSSScore) ScoreDate() time.Time
- func (e *EPSSScore) Update(score, percentile float64, modelVersion string, scoreDate time.Time)
- func (e *EPSSScore) UpdatedAt() time.Time
- type KEVEntry
- func (k *KEVEntry) CVEID() string
- func (k *KEVEntry) CWEs() []string
- func (k *KEVEntry) CreatedAt() time.Time
- func (k *KEVEntry) DateAdded() time.Time
- func (k *KEVEntry) DaysUntilDue() int
- func (k *KEVEntry) DueDate() time.Time
- func (k *KEVEntry) HasRansomwareUse() bool
- func (k *KEVEntry) IsPastDue() bool
- func (k *KEVEntry) KnownRansomwareCampaignUse() string
- func (k *KEVEntry) Notes() string
- func (k *KEVEntry) Product() string
- func (k *KEVEntry) ShortDescription() string
- func (k *KEVEntry) Update(vendorProject, product, vulnerabilityName, shortDescription string, ...)
- func (k *KEVEntry) UpdatedAt() time.Time
- func (k *KEVEntry) VendorProject() string
- func (k *KEVEntry) VulnerabilityName() string
- type KEVRepository
- type SyncError
- type SyncState
- type SyncStatus
- func (s *SyncStatus) CreatedAt() time.Time
- func (s *SyncStatus) ID() shared.ID
- func (s *SyncStatus) IsDueForSync() bool
- func (s *SyncStatus) IsEnabled() bool
- func (s *SyncStatus) LastSyncAt() *time.Time
- func (s *SyncStatus) LastSyncError() string
- func (s *SyncStatus) LastSyncStatus() SyncState
- func (s *SyncStatus) MarkSyncFailed(err string)
- func (s *SyncStatus) MarkSyncStarted()
- func (s *SyncStatus) MarkSyncSuccess(recordsSynced int, durationMs int)
- func (s *SyncStatus) Metadata() map[string]any
- func (s *SyncStatus) NextSyncAt() *time.Time
- func (s *SyncStatus) RecordsSynced() int
- func (s *SyncStatus) SetEnabled(enabled bool)
- func (s *SyncStatus) SetSyncInterval(hours int)
- func (s *SyncStatus) SourceName() string
- func (s *SyncStatus) SyncDurationMs() int
- func (s *SyncStatus) SyncIntervalHours() int
- func (s *SyncStatus) UpdatedAt() time.Time
- type SyncStatusRepository
- type ThreatIntelEnrichment
- type ThreatIntelRepository
- type ThreatIntelSource
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEPSSNotFound is returned when an EPSS score is not found. ErrEPSSNotFound = errors.New("epss score not found") // ErrKEVNotFound is returned when a KEV entry is not found. ErrKEVNotFound = errors.New("kev entry not found") // ErrSyncStatusNotFound is returned when a sync status is not found. ErrSyncStatusNotFound = errors.New("sync status not found") // ErrSyncAlreadyRunning is returned when a sync is already in progress. ErrSyncAlreadyRunning = errors.New("sync already running") // ErrSyncDisabled is returned when sync is disabled for a source. ErrSyncDisabled = errors.New("sync is disabled for this source") // ErrInvalidCVEID is returned when CVE ID format is invalid. ErrInvalidCVEID = errors.New("invalid CVE ID format") // ErrFetchFailed is returned when fetching threat intel data fails. ErrFetchFailed = errors.New("failed to fetch threat intel data") // ErrParseFailed is returned when parsing threat intel data fails. ErrParseFailed = errors.New("failed to parse threat intel data") )
Domain errors for threat intelligence.
Functions ¶
This section is empty.
Types ¶
type EPSSRepository ¶
type EPSSRepository interface {
// Upsert creates or updates an EPSS score.
Upsert(ctx context.Context, score *EPSSScore) error
// UpsertBatch creates or updates multiple EPSS scores.
UpsertBatch(ctx context.Context, scores []*EPSSScore) error
// GetByCVEID retrieves an EPSS score by CVE ID.
GetByCVEID(ctx context.Context, cveID string) (*EPSSScore, error)
// GetByCVEIDs retrieves EPSS scores for multiple CVE IDs.
GetByCVEIDs(ctx context.Context, cveIDs []string) ([]*EPSSScore, error)
// GetHighRisk retrieves all high-risk EPSS scores (score > threshold).
GetHighRisk(ctx context.Context, threshold float64, limit int) ([]*EPSSScore, error)
// GetTopPercentile retrieves scores in top N percentile.
GetTopPercentile(ctx context.Context, percentile float64, limit int) ([]*EPSSScore, error)
// Count returns the total number of EPSS scores.
Count(ctx context.Context) (int64, error)
// DeleteAll removes all EPSS scores (for full refresh).
DeleteAll(ctx context.Context) error
}
EPSSRepository defines the interface for EPSS score persistence.
type EPSSRiskLevel ¶
type EPSSRiskLevel string
EPSSRiskLevel represents EPSS-based risk levels.
const ( EPSSRiskLevelLow EPSSRiskLevel = "low" // < 0.05 (5%) EPSSRiskLevelMedium EPSSRiskLevel = "medium" // 0.05 - 0.1 (5-10%) EPSSRiskLevelHigh EPSSRiskLevel = "high" // 0.1 - 0.3 (10-30%) EPSSRiskLevelCritical EPSSRiskLevel = "critical" // > 0.3 (30%) )
func EPSSRiskLevelFromScore ¶
func EPSSRiskLevelFromScore(score float64) EPSSRiskLevel
EPSSRiskLevelFromScore returns the risk level for an EPSS score.
func (EPSSRiskLevel) String ¶
func (e EPSSRiskLevel) String() string
String returns the string representation.
type EPSSScore ¶
type EPSSScore struct {
// contains filtered or unexported fields
}
EPSSScore represents an EPSS score entry from FIRST.org.
func NewEPSSScore ¶
func NewEPSSScore(cveID string, score, percentile float64, modelVersion string, scoreDate time.Time) *EPSSScore
NewEPSSScore creates a new EPSSScore.
func ReconstituteEPSSScore ¶
func ReconstituteEPSSScore( cveID string, score, percentile float64, modelVersion string, scoreDate time.Time, createdAt, updatedAt time.Time, ) *EPSSScore
ReconstituteEPSSScore recreates an EPSSScore from persistence.
func (*EPSSScore) IsCriticalRisk ¶
IsCriticalRisk returns true if EPSS score indicates critical risk (> 0.3 or 30%).
func (*EPSSScore) IsHighRisk ¶
IsHighRisk returns true if EPSS score indicates high risk (> 0.1 or 10%).
func (*EPSSScore) IsTopPercentile ¶
IsTopPercentile returns true if in top N percentile.
func (*EPSSScore) ModelVersion ¶
ModelVersion returns the EPSS model version.
func (*EPSSScore) Percentile ¶
Percentile returns the percentile rank.
type KEVEntry ¶
type KEVEntry struct {
// contains filtered or unexported fields
}
KEVEntry represents a CISA Known Exploited Vulnerability entry.
func NewKEVEntry ¶
func NewKEVEntry( cveID, vendorProject, product, vulnerabilityName, shortDescription string, dateAdded, dueDate time.Time, ransomwareUse, notes string, cwes []string, ) *KEVEntry
NewKEVEntry creates a new KEVEntry.
func ReconstituteKEVEntry ¶
func ReconstituteKEVEntry( cveID, vendorProject, product, vulnerabilityName, shortDescription string, dateAdded, dueDate time.Time, ransomwareUse, notes string, cwes []string, createdAt, updatedAt time.Time, ) *KEVEntry
ReconstituteKEVEntry recreates a KEVEntry from persistence.
func (*KEVEntry) DaysUntilDue ¶
DaysUntilDue returns days until due date (negative if past due).
func (*KEVEntry) HasRansomwareUse ¶
HasRansomwareUse returns true if known ransomware campaign use.
func (*KEVEntry) KnownRansomwareCampaignUse ¶
KnownRansomwareCampaignUse returns ransomware campaign usage info.
func (*KEVEntry) ShortDescription ¶
ShortDescription returns the short description.
func (*KEVEntry) Update ¶
func (k *KEVEntry) Update( vendorProject, product, vulnerabilityName, shortDescription string, dueDate time.Time, ransomwareUse, notes string, cwes []string, )
Update updates the KEV entry fields.
func (*KEVEntry) VendorProject ¶
VendorProject returns the vendor/project name.
func (*KEVEntry) VulnerabilityName ¶
VulnerabilityName returns the vulnerability name.
type KEVRepository ¶
type KEVRepository interface {
// Upsert creates or updates a KEV entry.
Upsert(ctx context.Context, entry *KEVEntry) error
// UpsertBatch creates or updates multiple KEV entries.
UpsertBatch(ctx context.Context, entries []*KEVEntry) error
// GetByCVEID retrieves a KEV entry by CVE ID.
GetByCVEID(ctx context.Context, cveID string) (*KEVEntry, error)
// GetByCVEIDs retrieves KEV entries for multiple CVE IDs.
GetByCVEIDs(ctx context.Context, cveIDs []string) ([]*KEVEntry, error)
// ExistsByCVEID checks if a CVE is in KEV.
ExistsByCVEID(ctx context.Context, cveID string) (bool, error)
// ExistsByCVEIDs checks which CVEs are in KEV.
ExistsByCVEIDs(ctx context.Context, cveIDs []string) (map[string]bool, error)
// GetPastDue retrieves KEV entries past their due date.
GetPastDue(ctx context.Context, limit int) ([]*KEVEntry, error)
// GetRecentlyAdded retrieves recently added KEV entries.
GetRecentlyAdded(ctx context.Context, days, limit int) ([]*KEVEntry, error)
// GetRansomwareRelated retrieves KEV entries with known ransomware use.
GetRansomwareRelated(ctx context.Context, limit int) ([]*KEVEntry, error)
// Count returns the total number of KEV entries.
Count(ctx context.Context) (int64, error)
// DeleteAll removes all KEV entries (for full refresh).
DeleteAll(ctx context.Context) error
}
KEVRepository defines the interface for KEV catalog persistence.
type SyncError ¶
SyncError wraps a sync error with additional context.
func NewSyncError ¶
NewSyncError creates a new sync error.
type SyncState ¶
type SyncState string
SyncState represents the state of a sync operation.
func ParseSyncState ¶
ParseSyncState parses a string into a SyncState.
type SyncStatus ¶
type SyncStatus struct {
// contains filtered or unexported fields
}
SyncStatus represents the sync status for a threat intel source.
func NewSyncStatus ¶
func NewSyncStatus(sourceName string, syncIntervalHours int) *SyncStatus
NewSyncStatus creates a new SyncStatus.
func ReconstituteSyncStatus ¶
func ReconstituteSyncStatus( id shared.ID, sourceName string, lastSyncAt *time.Time, lastSyncStatus SyncState, lastSyncError string, recordsSynced, syncDurationMs int, nextSyncAt *time.Time, syncIntervalHours int, isEnabled bool, metadata map[string]any, createdAt, updatedAt time.Time, ) *SyncStatus
ReconstituteSyncStatus recreates a SyncStatus from persistence.
func (*SyncStatus) CreatedAt ¶
func (s *SyncStatus) CreatedAt() time.Time
CreatedAt returns the creation time.
func (*SyncStatus) IsDueForSync ¶
func (s *SyncStatus) IsDueForSync() bool
IsDueForSync checks if sync is due.
func (*SyncStatus) IsEnabled ¶
func (s *SyncStatus) IsEnabled() bool
IsEnabled returns whether sync is enabled.
func (*SyncStatus) LastSyncAt ¶
func (s *SyncStatus) LastSyncAt() *time.Time
LastSyncAt returns the last sync time.
func (*SyncStatus) LastSyncError ¶
func (s *SyncStatus) LastSyncError() string
LastSyncError returns the last sync error.
func (*SyncStatus) LastSyncStatus ¶
func (s *SyncStatus) LastSyncStatus() SyncState
LastSyncStatus returns the last sync status.
func (*SyncStatus) MarkSyncFailed ¶
func (s *SyncStatus) MarkSyncFailed(err string)
MarkSyncFailed marks the sync as failed.
func (*SyncStatus) MarkSyncStarted ¶
func (s *SyncStatus) MarkSyncStarted()
MarkSyncStarted marks the sync as started.
func (*SyncStatus) MarkSyncSuccess ¶
func (s *SyncStatus) MarkSyncSuccess(recordsSynced int, durationMs int)
MarkSyncSuccess marks the sync as successful.
func (*SyncStatus) Metadata ¶
func (s *SyncStatus) Metadata() map[string]any
Metadata returns a copy of the metadata.
func (*SyncStatus) NextSyncAt ¶
func (s *SyncStatus) NextSyncAt() *time.Time
NextSyncAt returns the next sync time.
func (*SyncStatus) RecordsSynced ¶
func (s *SyncStatus) RecordsSynced() int
RecordsSynced returns the number of records synced.
func (*SyncStatus) SetEnabled ¶
func (s *SyncStatus) SetEnabled(enabled bool)
SetEnabled sets the enabled status.
func (*SyncStatus) SetSyncInterval ¶
func (s *SyncStatus) SetSyncInterval(hours int)
SetSyncInterval sets the sync interval.
func (*SyncStatus) SourceName ¶
func (s *SyncStatus) SourceName() string
SourceName returns the source name.
func (*SyncStatus) SyncDurationMs ¶
func (s *SyncStatus) SyncDurationMs() int
SyncDurationMs returns the sync duration in milliseconds.
func (*SyncStatus) SyncIntervalHours ¶
func (s *SyncStatus) SyncIntervalHours() int
SyncIntervalHours returns the sync interval in hours.
func (*SyncStatus) UpdatedAt ¶
func (s *SyncStatus) UpdatedAt() time.Time
UpdatedAt returns the last update time.
type SyncStatusRepository ¶
type SyncStatusRepository interface {
// GetBySource retrieves sync status by source name.
GetBySource(ctx context.Context, source string) (*SyncStatus, error)
// GetAll retrieves all sync statuses.
GetAll(ctx context.Context) ([]*SyncStatus, error)
// GetEnabled retrieves enabled sync statuses.
GetEnabled(ctx context.Context) ([]*SyncStatus, error)
// GetDueForSync retrieves sources due for sync.
GetDueForSync(ctx context.Context) ([]*SyncStatus, error)
// Update updates a sync status.
Update(ctx context.Context, status *SyncStatus) error
}
SyncStatusRepository defines the interface for sync status persistence.
type ThreatIntelEnrichment ¶
type ThreatIntelEnrichment struct {
CVEID string
EPSSScore *float64
EPSSPercentile *float64
InKEV bool
KEVDateAdded *string
KEVDueDate *string
KEVRansomware *string
}
ThreatIntelEnrichment contains enrichment data for a CVE.
func NewThreatIntelEnrichment ¶
func NewThreatIntelEnrichment(cveID string) *ThreatIntelEnrichment
NewThreatIntelEnrichment creates a new enrichment result.
func (*ThreatIntelEnrichment) HasData ¶
func (t *ThreatIntelEnrichment) HasData() bool
HasData returns true if any enrichment data exists.
func (*ThreatIntelEnrichment) RiskLevel ¶
func (t *ThreatIntelEnrichment) RiskLevel() string
RiskLevel returns the combined risk level.
func (*ThreatIntelEnrichment) WithEPSS ¶
func (t *ThreatIntelEnrichment) WithEPSS(score, percentile float64) *ThreatIntelEnrichment
WithEPSS adds EPSS data.
func (*ThreatIntelEnrichment) WithKEV ¶
func (t *ThreatIntelEnrichment) WithKEV(dateAdded, dueDate, ransomware string) *ThreatIntelEnrichment
WithKEV adds KEV data.
type ThreatIntelRepository ¶
type ThreatIntelRepository interface {
// EPSS returns the EPSS repository.
EPSS() EPSSRepository
// KEV returns the KEV repository.
KEV() KEVRepository
// SyncStatus returns the sync status repository.
SyncStatus() SyncStatusRepository
// EnrichCVEs enriches multiple CVEs with threat intel data.
EnrichCVEs(ctx context.Context, cveIDs []string) (map[string]*ThreatIntelEnrichment, error)
// EnrichCVE enriches a single CVE with threat intel data.
EnrichCVE(ctx context.Context, cveID string) (*ThreatIntelEnrichment, error)
}
ThreatIntelRepository combines all threat intel repositories.
type ThreatIntelSource ¶
type ThreatIntelSource string
ThreatIntelSource represents a threat intelligence source.
const ( SourceEPSS ThreatIntelSource = "epss" SourceKEV ThreatIntelSource = "kev" )
func AllSources ¶
func AllSources() []ThreatIntelSource
AllSources returns all threat intel sources.
func (ThreatIntelSource) IsValid ¶
func (t ThreatIntelSource) IsValid() bool
IsValid checks if the source is valid.
func (ThreatIntelSource) String ¶
func (t ThreatIntelSource) String() string
String returns the string representation.