Documentation
¶
Overview ¶
Package scan is the vulnerability-scan module (S-SCAN-1..4, modules/scan/CONTRACT.md): it confirms exploited vulnerabilities with safe nuclei templates on devices inside the confirmed scope, inside the time window, at the rate and with the exclusions the admin set, and keeps the probe log. Consent and scope stay here, in core; nuclei itself is a pinned binary run by the worker in the scan container, reached through Engine.
Index ¶
- Constants
- Variables
- func Jobs(svc *Service) []jobs.Job
- func ToAPIError(err error) error
- type APIError
- type AnnouncedKEV
- type Checks
- type Commitment
- type Config
- type ConfigView
- type Current
- type Decision
- type Device
- type Engine
- type EngineView
- type EventView
- type Evidence
- type External
- type ExternalProbe
- type ExternalTarget
- type FindingConfirmedEvent
- type FindingRef
- type Findings
- type IdentRow
- type Identification
- type Identifier
- type Inventory
- type Job
- type KEVFeed
- type NewKEV
- type OSPages
- type OpenPort
- type Patch
- type ProbeView
- type Publisher
- type Reach
- type RunEvent
- type RunHead
- type RunRow
- type RunView
- type ScanHandlers
- func (h *ScanHandlers) ScanGetScansConfig(ctx context.Context) (*oas.ScanGetScansConfigOK, error)
- func (h *ScanHandlers) ScanGetScansEvents(ctx context.Context) (*oas.ScanGetScansEventsOK, error)
- func (h *ScanHandlers) ScanGetScansProbes(ctx context.Context) (*oas.ScanGetScansProbesOK, error)
- func (h *ScanHandlers) ScanGetScansProbesCsv(ctx context.Context) (oas.ScanGetScansProbesCsvOK, error)
- func (h *ScanHandlers) ScanGetScansRuns(ctx context.Context, params oas.ScanGetScansRunsParams) (*oas.ScanGetScansRunsOK, error)
- func (h *ScanHandlers) ScanGetScansTargets(ctx context.Context) (*oas.ScanGetScansTargetsOK, error)
- func (h *ScanHandlers) ScanPostScansRuns(ctx context.Context, req *oas.ScanPostScansRunsReq) (*oas.ScanPostScansRunsCreated, error)
- func (h *ScanHandlers) ScanPostScansRunsIDStop(ctx context.Context, params oas.ScanPostScansRunsIDStopParams) (*oas.ScanPostScansRunsIDStopOK, error)
- func (h *ScanHandlers) ScanPutScansConfig(ctx context.Context, req *oas.ScanPutScansConfigReq) (*oas.ScanPutScansConfigOK, error)
- type Scope
- type ScopeView
- type Service
- func (s *Service) Config(ctx context.Context) (ConfigView, error)
- func (s *Service) DeviceChanged(ctx context.Context, assetID string) error
- func (s *Service) Engine(ctx context.Context) (EngineView, error)
- func (s *Service) Events(ctx context.Context) ([]EventView, bool, error)
- func (s *Service) OnNewKEV(ctx context.Context, ev NewKEV) error
- func (s *Service) Probes(ctx context.Context) ([]ProbeView, error)
- func (s *Service) ProbesCSV(ctx context.Context) (io.Reader, error)
- func (s *Service) Reach(ctx context.Context, assetID string) (Reach, error)
- func (s *Service) RecordExternalProbes(ctx context.Context, ps []ExternalProbe) error
- func (s *Service) Run(ctx context.Context, id string) (RunView, error)
- func (s *Service) RunRecover(ctx context.Context) error
- func (s *Service) RunRescans(ctx context.Context) error
- func (s *Service) RunRetention(ctx context.Context) error
- func (s *Service) Runs(ctx context.Context) ([]RunView, error)
- func (s *Service) RunsOf(ctx context.Context, asset string) ([]RunView, error)
- func (s *Service) SaveConfig(ctx context.Context, user string, p Patch) (ConfigView, error)
- func (s *Service) ScheduleOwner() schedule.Owner
- func (s *Service) StartRun(ctx context.Context, user string, ids []string) (RunView, error)
- func (s *Service) StopRun(ctx context.Context, user, id string) (RunView, error)
- func (s *Service) Targets(ctx context.Context) ([]TargetView, error)
- type Settings
- type TargetView
- type Window
Constants ¶
const ( MaxRate = 20 MaxExclusions = 200 MinUnresponsive = 2 MaxUnresponsive = 20 )
Limits of INV-5.
const ( ProbeNotRun = "not_run" ProbeRefused = "refused" )
Probe-log results of a template probe that never reached the target (migration 0007).
const ( EventRunStarted = "scan.run.started" EventRunFinished = "scan.run.finished" EventRunStopped = "scan.run.stopped" EventFindingConfirmed = "scan.finding.confirmed" )
Event names published by this module (CONTRACT, Events).
const ExternalPrefix = "ext:"
ExternalPrefix marks an external target id in the scan list (contract.ts ScanTarget.id).
const ( // JobTick is how often the KEV rescans are looked at: well inside the 60 minutes of S-SCAN-2. JobTick = time.Minute )
Job timing.
const (
MaxRunTargets = 200 // INV-3
)
Limits of a run.
const ModuleID = "scan"
ModuleID is the id of this module in the registry, the module gate and core/jobs.
const ReasonGone = "gone"
ReasonGone is the policy reason of a device deleted since the device list was read (review L6): it leaves the list.
const RecoverEvery = 10 * time.Minute
RecoverEvery is how often the recover job looks for probe rows of a run that is no longer live. core/run records the run itself at every start; core/jobs runs a job as soon as its module is on, so after a restart the log is closed at once.
const RetentionDays = 90
RetentionDays is how long the probe log is kept (INV-7: at least 90 days; the GUI says 90).
const ScheduleKey = "scan.vuln"
ScheduleKey is the owner key of the regular vulnerability check in core/schedule.
Variables ¶
var ( ErrDangerousLocked = apiErr(400, "dangerous_locked", "Vedette has no dangerous checks: no exploitation, no denial of service. It cannot be turned on.") )
The API errors of the scan endpoints.
var ErrEngineDown = errors.New("scan: the scanner cannot run jobs now")
ErrEngineDown is wrapped by an Engine.Run error that means the scanner cannot run any job now.
var ErrIdentifyInterrupted = errors.New("scan: the identification was interrupted by a change")
ErrIdentifyInterrupted is the error of an identification sensor-active stopped by itself while the run goes on: the device, the discovery settings (rate, scope) or the module changed. That device is not checked in this run; the next one is (review M2).
var ErrIdentifyStopped = errors.New("scan: the identification was stopped")
ErrIdentifyStopped is the error of an identification the run's Stop now (or its end) cut short.
var Migrations = mustSub(migrationFiles, "migrations/sqlite")
Migrations holds the SQLite migrations of the scan module, rooted at the directory that holds the NNNN_*.sql files. Apply them after core's and inventory's: store.Migrate(ctx, db, "scan", scan.Migrations).
Functions ¶
func Jobs ¶
Jobs are the module's background work; core/jobs runs them only while the module is on (SYS-5), except retention: it only deletes rows past the retention (INV-7), so it is housekeeping and keeps its timer while the module is off.
func ToAPIError ¶
ToAPIError turns an API error of this package into the *apierr.Error of the response; other errors pass through (the server answers them as 500 internal without detail).
Types ¶
type APIError ¶
APIError maps 1:1 to an error code of the scan endpoints (web/src/features/scan/mocks.ts, the behaviour spec). Callers wrap it with %w and the HTTP layer turns it into the response with ToAPIError.
type AnnouncedKEV ¶
AnnouncedKEV is one announced entry and when feeds announced it.
type Checks ¶
type Checks struct {
Window Window
Rate int // requests per second
Exclusions []string
// Version names the shared block as read (Checks); on SaveChecks it is the one the page read ("" = none: no check), and another
// one refuses the save with 409 safety_changed (review #860 M1).
Version string
}
Checks is the part of the settings every LAN engine shares (INV-16): the window, the check rate and the exclusions.
type Commitment ¶
Commitment is who ticked the scope commitment and when (contract.ts ScanScope.commitment).
type Config ¶
type Config struct {
DB *store.DB
Audit *audit.Log
Inventory Inventory
Runs *run.Manager // every check is a run of this manager (core/run); register the kind before it starts
Engine Engine // nil: the scanner is unavailable (INV-2), nothing is ever sent
Pack *pack.Index // the safe template pack of the scan image; nil: the scanner is unavailable
Findings Findings // nil: results stay in the run, nothing is confirmed
Identify Identifier // nil: Scan now does not identify devices first; each says why
OSPages OSPages // nil: the identification rows say the OS as they recorded it
External External // nil: the list has no external targets
Publisher Publisher // nil: no events
KEV KEVFeed // nil: no catch-up of missed new_kev
Location func(ctx context.Context) *time.Location // the organization's time zone, the one the window and the schedule are read in (review H1); nil: UTC; a nil result: unknown, nothing automated starts
Log *slog.Logger
Clock func() time.Time // nil: time.Now
}
Config is what NewService needs. Only DB, Audit, Inventory and Log are required.
type ConfigView ¶
type ConfigView struct {
Config Settings `json:"config"`
Scope ScopeView `json:"scope"`
CanScan bool `json:"can_scan"`
BlockReason *string `json:"block_reason"`
DangerousChecks bool `json:"dangerous_checks"` // always false (INV-4)
// Version is the shared safety block's (INV-16, inventory INV-32): a PUT that sends it back is refused with 409 safety_changed
// when the block changed since (review #860 M1). "" without SharedChecks.
Version string `json:"version"`
}
ConfigView is contract.ts ScanConfigResponse.
type Decision ¶
type Decision struct {
Allowed bool
Reason string // inventory's reason: ok, box, no_ip, scope_not_confirmed, out_of_scope, regular_scan_never,
// declared_by_hand, fragile_passive_only, unclassified_passive_only
Careful bool // fragile or unclassified: a quarter of the rate
IP string // the address the decision was made for
}
Decision is inventory.VulnScanPolicy as scan needs it.
type Device ¶
type Device struct {
ID string
Label string // host name, or the IP when there is none
IP string // "" or "—" when unknown
Kind string // inventory kind; "unknown" until classified
Approved bool
Fragile bool
Box bool // the Vedette box itself: scanned only when a person picks it
Services []OpenPort
// For the picker's search and filters only: never part of a policy decision.
MAC string // "" when unknown
Vendor string // "" when unknown
LastSeen string // ISO time; "" when unknown
}
Device is an inventory device as the scan module sees it.
type Engine ¶
type Engine interface {
// Ready returns nil when a job can be sent now: the worker has a fresh heartbeat with nuclei and the template
// pack present. Otherwise it says why, for the log; the user sees msgScannerDown.
Ready(ctx context.Context) error
// Run runs one job, already checked by core (nucleiargv.Build), and returns one result per line nuclei printed,
// parsed fail closed against the job's templates and targets (nucleiout.Parse): a line that is not what the job
// asked for makes the whole run an error, and output over the cap is an error too (INV-10). No line is an empty
// result, which only means "no match reported", never "not vulnerable"; with -ms nuclei prints a non-match
// or error line per template and target, so an empty output is unusual. Outcome.HostErrors says which targets
// nuclei gave up on (timeouts counted from its error log): how core sees a device that died after it had
// answered some templates (INV-6). Cancelling ctx stops the run
// (Stop now, the device timeout): the engine stops nuclei and returns soon after. An error that wraps
// ErrEngineDown says the scanner itself cannot run jobs now (the worker gone, another template pack): the run stops
// with that message instead of trying every device.
Run(ctx context.Context, j Job) (nucleiout.Outcome, error)
}
Engine is the scanner seam: the worker in the scan container that runs the pinned nuclei binary, reached over the sensor protocol (S5: cmd/vedette wires the Dispatcher of sensor-active). Tests pass a fake. Without an Engine, or without a template pack, the scanner is unavailable and nothing is ever sent (INV-2).
type EngineView ¶
EngineView is the scan module as Settings › Scanning shows its nuclei card (#850, core INV-40): the newest run that ended, the run going on now with its progress, and why no scan can start (nil when one can).
type EventView ¶
type EventView struct {
ID string `json:"id"`
TS string `json:"ts"`
CVE string `json:"cve"`
Product string `json:"product"`
Devices []string `json:"devices"`
LatencyMin *float64 `json:"latency_min"`
RunID *string `json:"run_id"`
Result string `json:"result"`
}
EventView is contract.ts RescanEvent.
type Evidence ¶
type Evidence struct {
Summary string // one sentence plus how to check it yourself
Template string // template path in the pack
Request string
Response string
CheckedAt time.Time
}
Evidence is what a confirming scan hands the findings module (S-SCAN-3): cleaned and capped already.
type External ¶
type External interface {
Targets(ctx context.Context) ([]ExternalTarget, error)
}
External lists the exposure module's targets. Nil: the list has no external part.
type ExternalProbe ¶
type ExternalProbe struct {
ID string // from the scanner; the second write with the same ID completes the row
IP string
Label string
Template string
Request string
Answered bool
// Result, when set, is the result of a template probe of exposure's safe checks: matched or not_matched (a
// probe that got no usable answer stays no_response), ProbeNotRun (handed to nuclei, which did not run it) or ProbeRefused (the
// scan worker refused the job: nothing was sent; kf-scan item 5). It wins over Answered; any other value is not written.
Result string
}
ExternalProbe is one probe of the external-surface scan (INV-12) in the probe log: the same table, retention (90 days) and CSV as the probes of a run (INV-7), with no run id. Template names the kind ("exposure: tcp", "exposure: https"…).
type ExternalTarget ¶
type ExternalTarget struct {
ID string // exposure target id, without the "ext:" prefix
Value string // the domain or the IP
IP string // the IP of an IP target, the last known address of a domain, or "—"
Verified bool
Expired bool
}
ExternalTarget is a target of the exposure module as the scan list shows it. External targets are listed but not scanned by this version: the reason is always one of unverified, expired, not_supported.
type FindingConfirmedEvent ¶
type FindingConfirmedEvent struct {
AssetID string `json:"asset_id"`
CVE string `json:"cve"`
Template string `json:"template"`
Evidence string `json:"evidence"` // the summary
}
FindingConfirmedEvent is the payload of scan.finding.confirmed. findings is told directly (ConfirmFromScan); the event is for everyone else.
type FindingRef ¶
type FindingRef struct {
ID string
AssetID string
CVE string
Status string // suspected, confirmed, mitigated, patched, false_positive, not_relevant, risk_accepted
Basis string // how it was matched: scan, version, product ("" = unknown)
}
FindingRef is a finding of a device: the CVEs scan may confirm or clear on it.
type Findings ¶
type Findings interface {
List(ctx context.Context, assetID string) ([]FindingRef, error)
// ConfirmFromScan records a match and returns the id of the finding (INV-8). It is the only call: a scan without a
// match is "no match reported" and never touches a finding.
ConfirmFromScan(ctx context.Context, assetID, cve string, ev Evidence) (string, error)
}
Findings is the findings module as scan needs it. Nil: results stay in the run, nothing is confirmed (CONTRACT, behaviour when findings is off).
type IdentRow ¶
type IdentRow struct {
TargetID string `json:"target_id"`
Label string `json:"label"`
IP string `json:"ip"`
Found []string `json:"found"`
Reason *string `json:"reason"` // nil: software was recorded
Note string `json:"note"`
}
IdentRow is contract.ts RunIdentRow: per device of a Scan now run, what the identification recorded, or exactly why nothing was. The note is the backend's words; the GUI shows it as is.
type Identification ¶
Identification is what Identify found: Found in words, Why the reason no software was recorded ("" when some was): one of the IdentReason values, or an inventory refusal reason that identReason folds.
type Identifier ¶
type Identifier interface {
// Identify returns what was recorded about the device, or why nothing was. ErrIdentifyStopped (wrapped or not) says the run
// stopped it; any other error is a failure of the scanner or of storage.
Identify(ctx context.Context, assetID string) (Identification, error)
}
Identifier identifies a device before a Scan now run checks it: sensor-active's nmap device scan records what it finds (type, operating system, software with its CPE) in the inventory, and the findings module matches that before plan reads the device's findings. Without it a device known only by its address has no software, so nothing to check. cmd/vedette wires sensor-active; nil: no identification, and each device of a Scan now run says so (reason unavailable).
type Inventory ¶
type Inventory interface {
Scope(ctx context.Context) (Scope, error)
Devices(ctx context.Context) ([]Device, error)
// VulnScanPolicy is inventory.VulnScanPolicy: explicit is true for a device a person picked in Scan now.
VulnScanPolicy(ctx context.Context, assetID string, explicit bool) (Decision, error)
// VulnScanPolicies is VulnScanPolicy for many devices in one inventory read. A device that no longer
// exists is absent from the map.
VulnScanPolicies(ctx context.Context, assetIDs []string, explicit bool) (map[string]Decision, error)
// Checks reads the shared window, check rate and exclusions, the inventory's (INV-16, inventory INV-32): the one home of them.
Checks(ctx context.Context) (Checks, error)
// SaveChecks writes them inside tx, the transaction of PUT /scans/config; Settle is called once tx is over, with whether it
// committed (the inventory announces inventory.settings.changed then).
SaveChecks(ctx context.Context, tx *sql.Tx, user string, c Checks) error
Settle(ctx context.Context, tx *sql.Tx, committed bool)
}
Inventory is the part of the inventory module scan needs. cmd/vedette adapts *inventory.Service to it.
type Job ¶
type Job struct {
nucleiargv.Job
IDs []string
PackVersion, PackSHA256 string
}
Job is one nuclei run as core planned it: the argv job (template paths of the pack index, checked by nucleiargv.Build), the same templates by id in the same order, and the pack they come from. The worker's copy of the index maps the ids to its paths and refuses a job planned for another pack.
type KEVFeed ¶
type KEVFeed interface {
// NewKEVSince lists the entries announced after (at, cve), oldest first, at most limit.
NewKEVSince(ctx context.Context, at time.Time, cve string, limit int) ([]AnnouncedKEV, error)
}
KEVFeed is feeds' record of the KEV entries it announced (feeds.vuln.new_kev), read by the catch-up of the rescan job: the bus is best-effort, so an entry announced while scan was off or the process was down is found here. Nil: no catch-up, only the bus.
type OSPages ¶
OSPages is the OS each device page shows now (the inventory's ranking, through cmd/vedette). Absent from the map: no device page.
type Patch ¶
type Patch struct {
Days []int // nil: keep
From, To *string
Rate *int
Exclusions []string // nil: keep; empty: clear
StopOnUnresponsive *bool
UnresponsiveAfter *int
AutoRescan *bool
DangerousChecks *bool
Version string // the shared block's version the page read (ConfigView.Version); "" = none, no check
}
Patch is a partial PUT /scans/config: a nil field keeps the stored value (POST-3).
type ProbeView ¶
type ProbeView struct {
ID string `json:"id"`
TS string `json:"ts"`
RunID *string `json:"run_id"`
IP string `json:"ip"`
Label string `json:"label"`
Template string `json:"template"`
Request string `json:"request"`
Result string `json:"result"`
}
ProbeView is contract.ts ProbeEntry.
type Reach ¶
type Reach string
Reach says why the vulnerability scan does not reach one device, for the finding page's "why only suspected" line.
const ( ReachOutside Reach = "outside" // the device is outside the confirmed scan ranges ReachOff Reach = "off" // network scanning is off ReachNoRanges Reach = "no_ranges" // no scan ranges are confirmed yet ReachByHand Reach = "by_hand" // the device was added by hand and is not scanned ReachDeviceOff Reach = "device_off" // this device's own network scan setting is off ReachUnknown Reach = "" )
The Reach values. ReachUnknown is every other answer, including "allowed": the inventory's one-device answer does not say whether the device is approved or excluded, so the page then says nothing about the scan rather than guess.
type RunEvent ¶
type RunEvent struct {
RunID string `json:"run_id"`
Status string `json:"status"`
Matched int `json:"matched"`
}
RunEvent is the payload of scan.run.*.
type RunHead ¶
type RunHead struct {
ID, Trigger, Status, StartedAt string
EndedAt *string
Total, Done, Matched int
Progress *progress.View // the running run's current device; nil otherwise
}
RunHead is a run without its per-device rows.
type RunRow ¶
type RunRow struct {
TargetID string `json:"target_id"`
Label string `json:"label"`
IP string `json:"ip"`
Template *string `json:"template"`
Result string `json:"result"` // matched | not_matched | not_applicable | no_template | no_response | skipped
FindingID *string `json:"finding_id"`
Note string `json:"note"`
}
RunRow is contract.ts RunResultRow.
type RunView ¶
type RunView struct {
ID string `json:"id"`
Trigger string `json:"trigger"`
TriggerNote *string `json:"trigger_note"`
StartedAt string `json:"started_at"`
StartedBy string `json:"started_by"`
EndedAt *string `json:"ended_at"`
Status string `json:"status"`
Total int `json:"total"`
Done int `json:"done"`
Current *Current `json:"current"`
// Progress is how far the current device is (#830): its phase, how far into it, an estimate of the end. Only while the run
// goes on in this process; null otherwise. It lives in memory and goes with the run.
Progress *progress.View `json:"progress"`
Results []RunRow `json:"results"`
Matched int `json:"matched"`
StopReason *string `json:"stop_reason"`
// Identification is one row per device of a Scan now run: what it was identified as, or why it was not. Empty for
// schedules and KEV rescans, which do not identify, and while the run is going.
Identification []IdentRow `json:"identification"`
}
RunView is contract.ts ScanRun.
type ScanHandlers ¶
type ScanHandlers struct {
// contains filtered or unexported fields
}
ScanHandlers implements the operations of the scan module (modules/scan/CONTRACT.md). Embed it in the composite handler. Roles are enforced by the server pipeline before a handler runs, never here.
func NewScanHandlers ¶
func NewScanHandlers(svc *Service) *ScanHandlers
NewScanHandlers returns the handlers of svc.
func (*ScanHandlers) ScanGetScansConfig ¶
func (h *ScanHandlers) ScanGetScansConfig(ctx context.Context) (*oas.ScanGetScansConfigOK, error)
ScanGetScansConfig implements scan_get_scans_config (viewer).
func (*ScanHandlers) ScanGetScansEvents ¶
func (h *ScanHandlers) ScanGetScansEvents(ctx context.Context) (*oas.ScanGetScansEventsOK, error)
ScanGetScansEvents implements scan_get_scans_events (viewer): the log of automatic rescans (S-SCAN-2).
func (*ScanHandlers) ScanGetScansProbes ¶
func (h *ScanHandlers) ScanGetScansProbes(ctx context.Context) (*oas.ScanGetScansProbesOK, error)
ScanGetScansProbes implements scan_get_scans_probes (viewer).
func (*ScanHandlers) ScanGetScansProbesCsv ¶
func (h *ScanHandlers) ScanGetScansProbesCsv(ctx context.Context) (oas.ScanGetScansProbesCsvOK, error)
ScanGetScansProbesCsv implements scan_get_scans_probes_csv (viewer).
func (*ScanHandlers) ScanGetScansRuns ¶
func (h *ScanHandlers) ScanGetScansRuns(ctx context.Context, params oas.ScanGetScansRunsParams) (*oas.ScanGetScansRunsOK, error)
ScanGetScansRuns implements scan_get_scans_runs (viewer); with asset, only the runs of that device.
func (*ScanHandlers) ScanGetScansTargets ¶
func (h *ScanHandlers) ScanGetScansTargets(ctx context.Context) (*oas.ScanGetScansTargetsOK, error)
ScanGetScansTargets implements scan_get_scans_targets (viewer).
func (*ScanHandlers) ScanPostScansRuns ¶
func (h *ScanHandlers) ScanPostScansRuns(ctx context.Context, req *oas.ScanPostScansRunsReq) (*oas.ScanPostScansRunsCreated, error)
ScanPostScansRuns implements scan_post_scans_runs (operator): Scan now.
func (*ScanHandlers) ScanPostScansRunsIDStop ¶
func (h *ScanHandlers) ScanPostScansRunsIDStop(ctx context.Context, params oas.ScanPostScansRunsIDStopParams) (*oas.ScanPostScansRunsIDStopOK, error)
ScanPostScansRunsIDStop implements scan_post_scans_runs_id_stop (operator): Stop now.
func (*ScanHandlers) ScanPutScansConfig ¶
func (h *ScanHandlers) ScanPutScansConfig(ctx context.Context, req *oas.ScanPutScansConfigReq) (*oas.ScanPutScansConfigOK, error)
ScanPutScansConfig implements scan_put_scans_config (admin): a partial update.
type Scope ¶
type Scope struct {
Networks []string // lan_ranges
ConfirmedAt string // ISO time of the commitment; "" when it is not ticked
ConfirmedBy string
}
Scope is what the inventory says about the scan scope (INV-11: scan only reads it, never writes the commitment).
type ScopeView ¶
type ScopeView struct {
Networks []string `json:"networks"`
Commitment *Commitment `json:"commitment"`
}
ScopeView is contract.ts ScanScope.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service owns the scan_ tables. Every mutation runs in one transaction with its core_audit row (SYS-3).
func NewService ¶
NewService returns the service. DB, Audit, Inventory and Log are required.
func (*Service) Config ¶
func (s *Service) Config(ctx context.Context) (ConfigView, error)
Config returns the settings with the scope, the commitment, and whether a scan can start.
func (*Service) DeviceChanged ¶
DeviceChanged stops the check of assetID when it is the device being checked now and the inventory no longer lets it be scanned (its network scan turned off; also never, excluded, moved, gone). The probes on their way are closed as stopped and its row says why; the run goes on with the next device. A read that fails stops it too (fail closed).
func (*Service) Engine ¶
func (s *Service) Engine(ctx context.Context) (EngineView, error)
Engine reads EngineView: two indexed rows of core_run and the configuration view, nothing per device.
func (*Service) Events ¶
Events is the rescan log, newest first (S-SCAN-2). Events still waiting or running are not listed yet.
func (*Service) OnNewKEV ¶
OnNewKEV records a new KEV entry that has a scan template, for the rescan job (PRE-4). The handler only writes a row: the bus gives it 5 seconds, a scan takes longer.
func (*Service) Probes ¶
Probes returns the probe log, newest first (INV-7). Requests still on their way have no result yet and are left out here; the CSV lists them as in_progress.
func (*Service) ProbesCSV ¶
ProbesCSV is the whole probe log as CSV, newest first: time, target, name, template, request, result.
func (*Service) Reach ¶
Reach reads the inventory's scan policy for the one device, as a scan a person picked would meet it: one read, no list of devices. A read that fails is ReachUnknown.
func (*Service) RecordExternalProbes ¶
func (s *Service) RecordExternalProbes(ctx context.Context, ps []ExternalProbe) error
RecordExternalProbes writes probes of the external-surface scan: before they go out (result no_response, "sent, no answer yet": a box that stops mid-scan leaves that), and again with the same IDs after, when something answered (banner) and with the request completed (the open ports). The time of a row is the first write. Texts are cut to the table's limits.
func (*Service) RunRecover ¶
RunRecover closes the probe rows of a run that a restart cut (review M4, INV-7): they show stopped.
func (*Service) RunRescans ¶
RunRescans moves every pending KEV event on (INV-9, POST-4): auto rescan off → skipped_off; no device with an open finding for the CVE that may be scanned without a pick → no_match; otherwise one new_kev run with only that CVE's templates, outside the time window; when the run has ended → matched or clear.
func (*Service) RunRetention ¶
RunRetention deletes probe rows older than RetentionDays and rescan events older than a year (INV-7).
func (*Service) Runs ¶
Runs returns the newest runs, newest first, with their per-device results (S-SCAN-3).
func (*Service) RunsOf ¶
RunsOf returns the newest runs that checked this device (the device page's Last checks), newest first, however many runs of other devices came after.
func (*Service) SaveConfig ¶
SaveConfig applies a partial update (PRE-3, POST-3): dangerous checks are refused first (INV-4), then the merged configuration must pass INV-5 as a whole. The change and its audit row are one transaction.
func (*Service) ScheduleOwner ¶
ScheduleOwner is what the vulnerability checks register with core/schedule: when they come due is the person's rule (the shared editor); what starts is one run over every device that may be scanned without a pick. By default they run on Sundays at 23:00 inside the scan window, and the first check of a new box is in its first open window. The window is always the scan window. A refusal that passes (no scope yet, a check running, the scanner not ready, the window just closed) holds the due time instead of using it up, so the check starts as soon as it can.
func (*Service) StartRun ¶
StartRun starts a scan of the targets a person picked in Scan now (PRE-1, POST-1): the commitment, 1..200 known targets that can be picked (INV-1..INV-3), the scanner ready. The pick is the consent for each device; it is audited with the person and the ids.
type Settings ¶
type Settings struct {
Window Window `json:"window"`
Rate int `json:"rate"` // requests per second
Exclusions []string `json:"exclusions"`
StopOnUnresponsive bool `json:"stop_on_unresponsive"`
UnresponsiveAfter int `json:"unresponsive_after"`
AutoRescan bool `json:"auto_rescan"`
// Version is the shared block's version read with the window, rate and exclusions above, in the same read (Checks; review #860
// r2 L3); "" without SharedChecks. Not part of the stored row or of contract.ts ScanConfig.
Version string `json:"-"`
}
Settings is the scan configuration (contract.ts ScanConfig).
type TargetView ¶
type TargetView struct {
ID string `json:"id"`
Kind string `json:"kind"` // internal | external
DeviceKind *string `json:"device_kind"`
Label string `json:"label"`
IP string `json:"ip"`
Fragile bool `json:"fragile"`
Findings int `json:"findings"`
// What a vulnerability check of the device can do (checkCount): its suspected findings, how many of them have a safe check,
// and how many confirmed ones have a check to run again. Zero for an external target.
Suspected int `json:"suspected"`
Checkable int `json:"checkable"`
Again int `json:"again"`
Selectable bool `json:"selectable"`
PickOnly bool `json:"pick_only"` // only a person's tick picks it; the GUI never ticks it for them
Box bool `json:"box"` // the Vedette box itself: pick-only, the GUI says so
Reason *string `json:"reason"`
// For the picker's search and filters; nil (false for Approved) on an external target.
MAC *string `json:"mac"`
Vendor *string `json:"vendor"`
Approved bool `json:"approved"`
LastSeen *string `json:"last_seen"`
}
TargetView is contract.ts ScanTarget.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package commonports is the fixed list of TCP ports Vedette always probes on the box's own public IP: the scan module's surface scan connects to each of them (and reads web titles and certificates there), and sensor-active's external nmap shape reads all of them in its first -sV batches, next to nmap's own most common ports its discovery probed (nmapargv.External).
|
Package commonports is the fixed list of TCP ports Vedette always probes on the box's own public IP: the scan module's surface scan connects to each of them (and reads web titles and certificates there), and sensor-active's external nmap shape reads all of them in its first -sV batches, next to nmap's own most common ports its discovery probed (nmapargv.External). |
|
Package nucleiargv builds and checks the only nuclei command line Vedette ever runs.
|
Package nucleiargv builds and checks the only nuclei command line Vedette ever runs. |
|
Package nucleiout reads what the worker's nuclei run printed (-jsonl -ms) into results core can trust ( INV-8, INV-10).
|
Package nucleiout reads what the worker's nuclei run printed (-jsonl -ms) into results core can trust ( INV-8, INV-10). |
|
Package pack reads the index of the safe nuclei template pack: the list of templates the signed scan image carries, built at release time with the pack.
|
Package pack reads the index of the safe nuclei template pack: the list of templates the signed scan image carries, built at release time with the pack. |
|
Package surface is the external-surface scan of the scan module, the exposure.Runner behind "Scan now" of External exposure (S-EXP-1).
|
Package surface is the external-surface scan of the scan module, the exposure.Runner behind "Scan now" of External exposure (S-EXP-1). |