behavior

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: BSD-3-Clause, GPL-3.0 Imports: 25 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.

README

Behavioral engine review

Engine.Observe consumes passive facts using capture timestamps. Monitoring compares against an explicitly approved snapshot; candidates never become trusted without ChangeAtVersion approval. The capture caller owns engine/sink shutdown.

Review area Source and invariant
Identity and discovery types.go, packet.go: sensor/interface/ordered VLAN scope; normalized IPv4/IPv6; prefixes require provenance, never an assumed mask
Lifecycle and durability engine.go, persistence.go, template.go: schema migrations, exclusive baseline ownership, atomic snapshots and immutable alert evidence
Correlation activity.go, rate.go, geography.go: bounded windows, retransmission dedup, sampled rates, capture-time administrative exemptions; encrypted attempts do not prove failed authentication
Presentation asset.go, topology.go, health.go: scoped joins, bounded responses, measured zero distinct from unavailable counters
Later evidence record_context.go: retained Connection/SMB tuple/time candidates, canonical record hash and index; legacy audit records lack scope, so no exact VLAN attribution is claimed
Reference tests testdata/qualification/: 5 cases, 38 exact positive alert records and benign PCAPs; collector tests exercise the production packet path at 1/2/4/8 workers

Early observations do not wait for flow closure. Later-record drill-down leaves the original alert unchanged and reports capture-time lag separately from unknown audit emission latency. Resource caps and overflow/error counters are part of the contract; review failure paths as well as positive fixtures.

Documentation

Overview

Package behavior maintains scoped, passive observations and approved baselines.

Index

Constants

View Source
const HealthFilename = "BehaviorHealth.json"
View Source
const SchemaVersion = 3

Variables

This section is empty.

Functions

func SeedTemplate

func SeedTemplate(source, target string) error

SeedTemplate copies a validated snapshot into a new session, never overwriting an existing session baseline or allowing that session to mutate the source.

func WriteHealth

func WriteHealth(output string, health Health) error

Types

type Activity

type Activity struct {
	Fact Fact  `json:"fact"`
	At   int64 `json:"at"`
}

type AlertSink

type AlertSink interface{ WriteAlert(*types.Alert) error }

type AssetContext

type AssetContext struct {
	Asset        string        `json:"asset"`
	Records      []AssetRecord `json:"records"`
	TotalRecords int           `json:"totalRecords"`
	Truncated    bool          `json:"truncated"`
}

func BuildAssetContext

func BuildAssetContext(state Snapshot, asset string) (AssetContext, error)

BuildAssetContext joins bindings only within their original network scope.

type AssetLabel

type AssetLabel struct {
	Fact  Fact   `json:"fact"`
	Name  string `json:"name"`
	Role  string `json:"role,omitempty"`
	Notes string `json:"notes,omitempty"`
}

type AssetRecord

type AssetRecord struct {
	ID                string      `json:"id"`
	Observation       Observation `json:"observation"`
	Label             *AssetLabel `json:"label,omitempty"`
	Direction         string      `json:"direction"`
	Prefixes          []string    `json:"prefixes,omitempty"`
	PrefixesTruncated bool        `json:"prefixesTruncated,omitempty"`
}

type CaptureHealth

type CaptureHealth struct {
	Scope          Scope   `json:"scope"`
	Packets        uint64  `json:"packets"`
	QueueDrops     *uint64 `json:"queueDrops"`
	KernelDrops    *uint64 `json:"kernelDrops"`
	KernelReceived *uint64 `json:"kernelReceived"`
	StatsAt        int64   `json:"statsAt"`
	StatsError     string  `json:"statsError,omitempty"`
	Workers        int     `json:"workers"`
	Queued         int     `json:"queued"`
	QueueCapacity  int     `json:"queueCapacity"`
}

type Config

type Config struct {
	Policy      *Policy
	Path        string
	MinLearning time.Duration
	MinSamples  uint64
	MaxFacts    int
	DedupWindow time.Duration
}

type Decision

type Decision struct {
	IDs        []string `json:"ids,omitempty"`
	At         int64    `json:"at"`
	Action     string   `json:"action"`
	Reason     string   `json:"reason"`
	Version    uint64   `json:"version"`
	BaselineID string   `json:"baselineId"`
}

type DeliveryHealth

type DeliveryHealth struct {
	Acked    uint64 `json:"acked"`
	Rejected uint64 `json:"rejected"`
	Dropped  uint64 `json:"dropped"`
	Pending  int    `json:"pending"`
}

type Engine

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

func Open

func Open(config Config, sink AlertSink) (*Engine, error)

func (*Engine) AddPrefix

func (e *Engine) AddPrefix(scope Scope, prefix, provenance string) error

AddPrefix seeds authoritative prefix metadata at the next capture timestamp.

func (*Engine) Change

func (e *Engine) Change(action string, ids []string, reason string) error

Change records an explicit analyst action and commits it atomically. ids are required for acknowledge, approve-changes, suppress and unsuppress.

func (*Engine) ChangeAtVersion

func (e *Engine) ChangeAtVersion(action string, ids []string, reason string, version uint64) error

func (*Engine) Checkpoint

func (e *Engine) Checkpoint() error

func (*Engine) Close

func (e *Engine) Close() error

func (*Engine) EditInventory

func (e *Engine) EditInventory(edit InventoryEdit) error

func (*Engine) Fail

func (e *Engine) Fail(err error)

func (*Engine) Health

func (e *Engine) Health(output string, capture *CaptureHealth, delivery *DeliveryHealth) Health

func (*Engine) Observe

func (e *Engine) Observe(at time.Time, facts ...Fact) error

Observe uses capture time, including for replay. It does not approve new facts.

func (*Engine) Snapshot

func (e *Engine) Snapshot() Snapshot

type Evidence

type Evidence struct {
	Related    []Fact `json:"related,omitempty"`
	Count      int    `json:"count,omitempty"`
	WindowNS   int64  `json:"windowNS,omitempty"`
	Schema     int    `json:"schema"`
	Detector   string `json:"detector"`
	FactID     string `json:"factId"`
	Observed   Fact   `json:"observed"`
	Expected   string `json:"expected"`
	Version    uint64 `json:"baselineVersion"`
	BaselineID string `json:"baselineId"`
}

type Fact

type Fact struct {
	LeaseSeconds uint32 `json:"leaseSeconds,omitempty"`
	Bytes        uint64 `json:"bytes,omitempty"`
	Token        string `json:"token,omitempty"`
	Scope        Scope  `json:"scope"`
	Kind         string `json:"kind"`
	SrcIP        string `json:"srcIP,omitempty"`
	DstIP        string `json:"dstIP,omitempty"`
	MAC          string `json:"mac,omitempty"`
	Protocol     string `json:"protocol,omitempty"`
	Port         uint16 `json:"port,omitempty"`
	Value        string `json:"value,omitempty"`
	Provenance   string `json:"provenance,omitempty"`
}

Fact is a reproducible observation identity. Port is a destination service port.

func PacketFacts

func PacketFacts(packet gopacket.Packet, scope Scope) []Fact

PacketFacts extracts early evidence without TCP stream closure or active probing.

type Health

type Health struct {
	Schema            int             `json:"schema"`
	SampledAt         int64           `json:"sampledAt"`
	Active            bool            `json:"active"`
	Scopes            []Scope         `json:"scopes"`
	ScopesTruncated   bool            `json:"scopesTruncated"`
	Capture           *CaptureHealth  `json:"capture"`
	Delivery          *DeliveryHealth `json:"delivery"`
	DetectorError     string          `json:"detectorError,omitempty"`
	Observations      uint64          `json:"observations"`
	FactOverflow      uint64          `json:"factOverflow"`
	WindowOverflow    uint64          `json:"windowOverflow"`
	BaselineBytes     *int64          `json:"baselineBytes"`
	BaselineWrittenAt int64           `json:"baselineWrittenAt"`
	AlertBytes        *int64          `json:"alertBytes"`
	StorageError      string          `json:"storageError,omitempty"`
}

func BuildHealth

func BuildHealth(state Snapshot, baseline, output string, active bool, capture *CaptureHealth, delivery *DeliveryHealth) Health

func ReadHealth

func ReadHealth(output string) (Health, error)

type InventoryEdit

type InventoryEdit struct {
	ID      string `json:"id"`
	Name    string `json:"name,omitempty"`
	Role    string `json:"role,omitempty"`
	Notes   string `json:"notes,omitempty"`
	Prefix  string `json:"prefix,omitempty"`
	Reason  string `json:"reason"`
	Version uint64 `json:"version"`
}

type Lease

type Lease struct {
	Fact    Fact  `json:"fact"`
	At      int64 `json:"at"`
	Expires int64 `json:"expires"`
}

type Maintenance

type Maintenance struct {
	Source string `json:"source"`
	Start  int64  `json:"start"`
	End    int64  `json:"end"`
}

type Mode

type Mode string
const (
	Learning   Mode = "learning"
	Monitoring Mode = "monitoring"
	Paused     Mode = "paused"
)

type Observation

type Observation struct {
	Fact      Fact   `json:"fact"`
	FirstSeen int64  `json:"firstSeen"`
	LastSeen  int64  `json:"lastSeen"`
	Samples   uint64 `json:"samples"`
}

type Policy

type Policy struct {
	Maintenance     []Maintenance `json:"maintenance,omitempty"`
	DeniedCountries []string      `json:"deniedCountries,omitempty"`
	DeniedASNs      []string      `json:"deniedASNs,omitempty"`
	RateWindows     uint64        `json:"rateWindows"`
	RateMultiplier  float64       `json:"rateMultiplier"`
	WindowNS        int64         `json:"windowNS"`
	Fanout          int           `json:"fanout"`
	RDPAttempts     int           `json:"rdpAttempts"`
	ApprovedSources []string      `json:"approvedSources,omitempty"`
}

func DefaultPolicy

func DefaultPolicy() Policy

func LoadPolicy

func LoadPolicy(path string) (Policy, error)

type RateModel

type RateModel struct {
	Windows     uint64  `json:"windows"`
	PacketsMean float64 `json:"packetsMean"`
	PacketsM2   float64 `json:"packetsM2"`
	BytesMean   float64 `json:"bytesMean"`
	BytesM2     float64 `json:"bytesM2"`
}

type RateStats

type RateStats struct {
	Fact    Fact      `json:"fact"`
	Start   int64     `json:"start"`
	Packets uint64    `json:"packets"`
	Bytes   uint64    `json:"bytes"`
	Model   RateModel `json:"model"`
}

type RecordContext

type RecordContext struct {
	Type           string `json:"type"`
	Index          int    `json:"index"`
	SHA256         string `json:"sha256"`
	FirstSeen      int64  `json:"firstSeen"`
	LastSeen       int64  `json:"lastSeen"`
	CaptureLagNS   int64  `json:"captureLagNS"`
	ScopeAvailable bool   `json:"scopeAvailable"`
	Outcome        string `json:"outcome"`
	Authentication string `json:"authentication"`
	Command        int32  `json:"command,omitempty"`
	Status         uint32 `json:"status,omitempty"`
	Response       bool   `json:"response,omitempty"`
	Encrypted      bool   `json:"encrypted,omitempty"`
}

RecordContext supplements immutable early evidence; legacy audit records lack network scope.

func MatchLateralRecord

func MatchLateralRecord(e Evidence, alertNS int64, record proto.Message, index int) *RecordContext

MatchLateralRecord returns a tuple/time candidate, never a scope-qualified attribution.

type Scope

type Scope struct {
	Sensor    string   `json:"sensor"`
	Interface string   `json:"interface"`
	VLANs     []uint16 `json:"vlans,omitempty"`
}

type Snapshot

type Snapshot struct {
	Labels          map[string]AssetLabel  `json:"labels"`
	Corrections     map[string]Fact        `json:"corrections"`
	Leases          map[string]Lease       `json:"leases"`
	Rates           map[string]RateStats   `json:"rates"`
	ApprovedRates   map[string]RateModel   `json:"approvedRates"`
	Policy          Policy                 `json:"policy"`
	Activity        map[string]Activity    `json:"activity"`
	WindowOverflow  uint64                 `json:"windowOverflow"`
	Error           string                 `json:"error,omitempty"`
	Schema          int                    `json:"schema"`
	Mode            Mode                   `json:"mode"`
	ResumeMode      Mode                   `json:"resumeMode,omitempty"`
	Version         uint64                 `json:"version"`
	BaselineID      string                 `json:"baselineId"`
	LearningStarted int64                  `json:"learningStarted"`
	Watermark       int64                  `json:"watermark"`
	Samples         uint64                 `json:"samples"`
	Overflow        uint64                 `json:"overflow"`
	OutOfOrder      uint64                 `json:"outOfOrder"`
	MinLearningNS   int64                  `json:"minLearningNS"`
	MinSamples      uint64                 `json:"minSamples"`
	MaxFacts        int                    `json:"maxFacts"`
	Observed        map[string]Observation `json:"observed"`
	Approved        map[string]Fact        `json:"approved"`
	Suppressed      map[string]string      `json:"suppressed"`
	Decisions       []Decision             `json:"decisions"`
}

func ReadSnapshot

func ReadSnapshot(path string) (Snapshot, error)

type Topology

type Topology struct {
	Nodes      []TopologyNode `json:"nodes"`
	Links      []TopologyLink `json:"links"`
	TotalNodes int            `json:"totalNodes"`
	TotalLinks int            `json:"totalLinks"`
	Truncated  bool           `json:"truncated"`
}

func BuildTopology

func BuildTopology(snapshot Snapshot, maxNodes int, scopeFilter string) Topology

BuildTopology keeps routed IP hosts separate from directly observed MAC devices.

type TopologyLink struct {
	Source string `json:"source"`
	Target string `json:"target"`
	Kind   string `json:"kind"`
	FactID string `json:"factId,omitempty"`
}

type TopologyNode

type TopologyNode struct {
	ID         string `json:"id"`
	Kind       string `json:"kind"`
	Name       string `json:"name"`
	Address    string `json:"address"`
	Scope      Scope  `json:"scope"`
	Provenance string `json:"provenance,omitempty"`
	FactID     string `json:"factId,omitempty"`
}

Directories

Path Synopsis
Package command supplies the capture and agent behavioral-monitoring flags.
Package command supplies the capture and agent behavioral-monitoring flags.

Jump to

Keyboard shortcuts

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