Documentation
¶
Overview ¶
Package attack implements the application service for the attack bounded context — orchestrates pkg/domain/attack entities and cross-cutting concerns (audit, notifications, RBAC).
Index ¶
- type AssetChange
- type AssetPathScore
- type AssetTypeBreakdown
- type ChainHop
- type ExposedService
- type ExposureChain
- type ExposureChainResult
- type ExposureChainSummary
- type FindingRiskCounter
- type PathScoringResult
- type PathSummary
- type SurfaceRepository
- type SurfaceService
- func (s *SurfaceService) ComputeAttackPathScores(ctx context.Context, tenantID shared.ID, relRepo asset.RelationshipRepository) (*PathScoringResult, error)
- func (s *SurfaceService) GetAttackPathScores(ctx context.Context, tenantID shared.ID) (*PathScoringResult, error)
- func (s *SurfaceService) GetExposureChains(ctx context.Context, tenantID shared.ID) (*ExposureChainResult, error)
- func (s *SurfaceService) GetStats(ctx context.Context, tenantID shared.ID) (*SurfaceStats, error)
- func (s *SurfaceService) SetFindingRiskCounter(c FindingRiskCounter)
- type SurfaceStats
- type SurfaceStatsData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssetChange ¶
type AssetChange struct {
Type string `json:"type"` // added, removed, changed
AssetName string `json:"asset_name"`
AssetType string `json:"asset_type"`
Timestamp time.Time `json:"timestamp"`
}
AssetChange represents a recent asset change.
type AssetPathScore ¶
type AssetPathScore struct {
// AssetID is the UUID of the asset.
AssetID string `json:"asset_id"`
// Name is the human-readable name of the asset.
Name string `json:"name"`
// AssetType is the type of the asset (e.g., "host", "application").
AssetType string `json:"asset_type"`
// Exposure is the asset's configured exposure level.
Exposure string `json:"exposure"`
// Criticality is the asset's criticality level.
Criticality string `json:"criticality"`
// RiskScore is the asset-level risk score (1-10).
RiskScore int `json:"risk_score"`
// IsCrownJewel marks high-value target assets.
IsCrownJewel bool `json:"is_crown_jewel"`
// FindingCount is the number of open findings on this asset.
FindingCount int `json:"finding_count"`
// ReachableFrom is the count of distinct public entry points that can
// reach this asset following attack-path relationship types.
ReachableFrom int `json:"reachable_from"`
// PathScore is the composite attack path score:
// (reachable_from * impact_weight) where impact_weight = risk_score * criticality_multiplier
// Higher = more urgent to remediate.
PathScore float64 `json:"path_score"`
// IsEntryPoint is true when this asset is itself a public entry point.
IsEntryPoint bool `json:"is_entry_point"`
// IsProtected is true when the asset has at least one "protected_by" or "monitors" relationship.
IsProtected bool `json:"is_protected"`
}
AssetPathScore holds the computed attack path score for a single asset.
type AssetTypeBreakdown ¶
type AssetTypeBreakdown struct {
Type string `json:"type"`
Total int `json:"total"`
Exposed int `json:"exposed"`
}
AssetTypeBreakdown represents asset count breakdown by type.
type ChainHop ¶ added in v0.3.0
type ChainHop struct {
AssetID string `json:"asset_id"`
Name string `json:"name"`
AssetType string `json:"asset_type"`
Exposure string `json:"exposure"`
}
ChainHop is one asset on an exposure chain.
type ExposedService ¶
type ExposedService struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Port int `json:"port,omitempty"`
Exposure string `json:"exposure"`
Criticality string `json:"criticality"`
FindingCount int `json:"finding_count"`
LastSeen time.Time `json:"last_seen"`
}
ExposedService represents an exposed service/asset.
type ExposureChain ¶ added in v0.3.0
type ExposureChain struct {
// EntryPointID/Name is the nearest public entry point that reaches the target.
EntryPointID string `json:"entry_point_id"`
EntryPointName string `json:"entry_point_name"`
// TargetID/Name is the reached asset carrying KEV/critical findings.
TargetID string `json:"target_id"`
TargetName string `json:"target_name"`
TargetCriticality string `json:"target_criticality"`
IsCrownJewel bool `json:"is_crown_jewel"`
// Hops is the ordered path entry → … → target (inclusive). Length 1 means the
// entry point itself is the target (a directly-exposed dangerous asset).
Hops []ChainHop `json:"hops"`
// Length is the number of edges traversed (len(Hops)-1); 0 = directly exposed.
Length int `json:"length"`
// ReachableFromEntryPoints is how many distinct public entry points can reach
// this target (blast-radius width).
ReachableFromEntryPoints int `json:"reachable_from_entry_points"`
// KEVCount/CriticalCount are the open KEV / critical findings on the target.
KEVCount int `json:"kev_count"`
CriticalCount int `json:"critical_count"`
// Score ranks urgency: dangerous + close-to-internet + crown-jewel = higher.
Score float64 `json:"score"`
}
ExposureChain is the shortest path from a public entry point to an asset that carries a KEV or critical finding — the concrete "how the internet reaches a dangerous asset" story that plain reachability scoring doesn't surface.
type ExposureChainResult ¶ added in v0.3.0
type ExposureChainResult struct {
Summary ExposureChainSummary `json:"summary"`
Chains []ExposureChain `json:"chains"`
}
ExposureChainResult is the full result returned by ComputeExposureChains.
type ExposureChainSummary ¶ added in v0.3.0
type ExposureChainSummary struct {
EntryPoints int `json:"entry_points"`
TargetsAtRisk int `json:"targets_at_risk"`
TotalChains int `json:"total_chains"`
HasRelationshipData bool `json:"has_relationship_data"`
}
ExposureChainSummary holds aggregate metrics for the tenant.
type FindingRiskCounter ¶ added in v0.3.0
type FindingRiskCounter interface {
KEVCriticalCountsByAsset(ctx context.Context, tenantID shared.ID) (kev, critical map[string]int, err error)
}
FindingRiskCounter provides, per asset, the number of open KEV and critical findings. Implemented by the finding repository; injected via a setter so the attack-surface service stays decoupled from the vulnerability layer.
type PathScoringResult ¶
type PathScoringResult struct {
Summary PathSummary `json:"summary"`
// TopAssets is the ranked list of assets by PathScore (descending), limited to 50.
TopAssets []AssetPathScore `json:"top_assets"`
}
PathScoringResult is the full result returned by ComputeAttackPathScores.
type PathSummary ¶
type PathSummary struct {
// TotalPaths is the total number of directed attack paths discovered
// (entry point → reachable asset pairs).
TotalPaths int `json:"total_paths"`
// EntryPoints is the count of public-exposure assets that act as entry points.
EntryPoints int `json:"entry_points"`
// ReachableAssets is the count of non-public assets reachable from at least one entry point.
ReachableAssets int `json:"reachable_assets"`
// MaxDepth is the longest BFS chain found.
MaxDepth int `json:"max_depth"`
// CriticalReachable is the count of critical/high assets reachable from entry points.
CriticalReachable int `json:"critical_reachable"`
// CrownJewelsAtRisk is the count of crown-jewel assets reachable from entry points.
CrownJewelsAtRisk int `json:"crown_jewels_at_risk"`
// HasRelationshipData indicates whether the tenant has any relationship data at all.
HasRelationshipData bool `json:"has_relationship_data"`
}
PathSummary holds aggregate attack path metrics for the tenant.
type SurfaceRepository ¶
type SurfaceRepository interface {
// GetStats returns attack surface statistics for a tenant
GetStats(ctx context.Context, tenantID shared.ID) (*SurfaceStatsData, error)
// GetExposedServices returns top exposed services/assets
GetExposedServices(ctx context.Context, tenantID shared.ID, limit int) ([]ExposedService, error)
// GetRecentChanges returns recent asset changes
GetRecentChanges(ctx context.Context, tenantID shared.ID, limit int) ([]AssetChange, error)
// GetStatsWithTrends returns stats with week-over-week comparison
GetStatsWithTrends(ctx context.Context, tenantID shared.ID) (*SurfaceStatsData, error)
}
SurfaceRepository defines the interface for attack surface data access.
type SurfaceService ¶
type SurfaceService struct {
// contains filtered or unexported fields
}
SurfaceService provides attack surface operations.
func NewSurfaceService ¶
func NewSurfaceService(assetRepo asset.Repository, relRepo asset.RelationshipRepository, log *logger.Logger) *SurfaceService
NewSurfaceService creates a new SurfaceService.
func (*SurfaceService) ComputeAttackPathScores ¶
func (s *SurfaceService) ComputeAttackPathScores( ctx context.Context, tenantID shared.ID, relRepo asset.RelationshipRepository, ) (*PathScoringResult, error)
ComputeAttackPathScores performs in-memory attack path analysis for the tenant. It:
- Loads all assets (nodes) and relationships (edges)
- Identifies public-exposure assets as entry points
- Runs BFS from each entry point following attack-path edges
- Counts how many entry points can reach each internal asset
- Computes a composite PathScore from reachability + risk + criticality
- Returns top 50 assets by PathScore + aggregate summary
func (*SurfaceService) GetAttackPathScores ¶
func (s *SurfaceService) GetAttackPathScores(ctx context.Context, tenantID shared.ID) (*PathScoringResult, error)
GetAttackPathScores computes attack path scoring for the tenant.
func (*SurfaceService) GetExposureChains ¶ added in v0.3.0
func (s *SurfaceService) GetExposureChains(ctx context.Context, tenantID shared.ID) (*ExposureChainResult, error)
GetExposureChains computes exposure chains for the tenant. Returns an empty result (not an error) when no finding-risk counter is wired.
func (*SurfaceService) GetStats ¶
func (s *SurfaceService) GetStats(ctx context.Context, tenantID shared.ID) (*SurfaceStats, error)
GetStats returns attack surface statistics for a tenant.
func (*SurfaceService) SetFindingRiskCounter ¶ added in v0.3.0
func (s *SurfaceService) SetFindingRiskCounter(c FindingRiskCounter)
SetFindingRiskCounter wires the KEV/critical finding counter used by exposure-chain analysis. Optional: without it, GetExposureChains returns an empty result rather than failing.
type SurfaceStats ¶
type SurfaceStats struct {
// Summary stats
TotalAssets int `json:"total_assets"`
ExposedServices int `json:"exposed_services"`
CriticalExposures int `json:"critical_exposures"`
RiskScore float64 `json:"risk_score"`
// Trends (week-over-week)
TotalAssetsChange int `json:"total_assets_change"`
ExposedServicesChange int `json:"exposed_services_change"`
CriticalExposuresChange int `json:"critical_exposures_change"`
// Asset breakdown by type with exposed count
AssetBreakdown []AssetTypeBreakdown `json:"asset_breakdown"`
// Top exposed services
ExposedServicesList []ExposedService `json:"exposed_services_list"`
// Recent changes
RecentChanges []AssetChange `json:"recent_changes"`
}
SurfaceStats represents aggregated attack surface statistics.
type SurfaceStatsData ¶
type SurfaceStatsData struct {
TotalAssets int
ExposedServices int
CriticalExposures int
AverageRiskScore float64
TotalAssetsChange int
ExposedServicesChange int
CriticalExposuresChange int
ByType map[string]int
ExposedByType map[string]int
}
SurfaceStatsData holds raw attack surface statistics.