Documentation
¶
Index ¶
- Constants
- Variables
- func CheckVulnerabilities(s *types.Software, hasVulns bool)
- func EnhanceSoftwareRecord(s *types.Software)
- func InitializeWebtech() webtech.Status
- func InitializeWebtechWith(root string, trust ed25519.PublicKey, now time.Time) webtech.Status
- func LookupUserAgent(raw string) *userAgent
- func ObserveWebtech(o webtech.Observation, body io.Reader, encoding, authority, flow, cid string, ...) webtech.Report
- func ParseUserAgent(ua string) *userAgent
- func RenderWebtech(m webtech.Result, authority, flow, cid string, ts int64) *types.Software
- func ResetCaches()
- func StorePassiveSoftware(records []*types.Software) int
- func WebtechDiagnostics() (webtech.Status, map[string]uint64)
- func WriteHTTPSoftware(items []*AtomicSoftware, flow, communityID string)
- func WriteSoftware(software []*AtomicSoftware, update func(s *AtomicSoftware))
- type AtomicSoftware
- type CMSHyperscanBuildStats
- type CMSHyperscanStatus
Constants ¶
const ( BehaviorServer = "server" BehaviorClient = "client" BehaviorProxy = "proxy" BehaviorScanner = "scanner" BehaviorBot = "bot" BehaviorCrawler = "crawler" BehaviorUnknown = "unknown" )
Software behavioral profiles
const ( ConfidenceHigh = "high" ConfidenceMedium = "medium" ConfidenceLow = "low" )
Detection confidence levels
const ( SupportActive = "active" SupportMaintenance = "maintenance" SupportEOL = "eol" SupportUnknown = "unknown" )
Support status values
Variables ¶
var ( // UserAgentCache contains parsed user agents at runtime. UserAgentCache = make(map[string]*userAgent) // RegexGenericVersion is a regular expression for anything that could be a product / version indicator. RegexGenericVersion = regexp.MustCompile(`(?m)(?:^)(.*?)(\d+)\.(\d+)\.(\d+)(.*?)(?:$)`) )
var ( // Store SoftwareStore hold all connections. Store = &atomicSoftwareMap{ Items: make(map[string]*AtomicSoftware), } // UserAgentParserMutex ensures atomic access to the user agent parser. UserAgentParserMutex sync.Mutex // HashDBMap contains SSH fingerprint digests mapped to software products at runtime. HashDBMap map[string][]sshSoftware )
var CMSCookies = make(map[string]struct{})
CMSCookies contains the names of identifying cookies for CMSs and frontend frameworks nolint
var CMSHeaders = make(map[string]struct{})
CMSHeaders cmsHeadersList is the list of identifying headers for Content Management Systems and Web Servers. the header names will be loaded from the CMS JSON db this map is populated once at init and not supposed to change during runtime so it is safe for concurrent access. nolint
var Decoder = &decoder.AbstractDecoder{ Type: types.Type_NC_Software, Name: "Software", Description: "A software product that was observed on the network", PostInit: func(d *decoder.AbstractDecoder) error { var err error softwareLog, _, err = logger.InitZapLogger( decoderconfig.Instance.Out, "software", decoderconfig.Instance.Debug, ) if err != nil { return err } data, err := ioutil.ReadFile(filepath.Join(resolvers.DataBaseFolderPath, "hasshdb.json")) hasshDB = nil if err == nil { err = json.Unmarshal(data, &hasshDB) } if err != nil { softwareLog.Warn("SSH fingerprint enrichment disabled", zap.Error(err)) hasshDB = nil } HashDBMap = make(map[string][]sshSoftware) for _, v := range hasshDB { HashDBMap[v.Hash] = v.Software } softwareLog.Info("loaded SSH fingerprint digests", zap.Int("total", len(HashDBMap))) _ = loadCmsDB() softwareLog.Warn("legacy CMS dataset inactive; bounded passive webtech advertisements enabled") buildCMSHSIndex() indexName := db.Path(resolvers.DataBaseFolderPath) db.VulnerabilitiesIndex, err = db.Open(indexName) if err != nil { db.VulnerabilitiesIndex = nil softwareLog.Warn("vulnerability lookups disabled", zap.String("path", indexName), zap.Error(err)) } return nil }, DeInit: func(e *decoder.AbstractDecoder) error { Store.operations.Lock() defer Store.operations.Unlock() if softwareState() != nil { err := walkStoredSoftware(func(s *types.Software) error { return flushSoftware(e, s) }) db.Close(db.VulnerabilitiesIndex) writeWebtechDiagnostics() return errors.Join(err, softwareLog.Sync()) } // flush writer var err error idents := make([]string, 0, len(Store.Items)) for ident := range Store.Items { idents = append(idents, ident) } sort.Strings(idents) for _, ident := range idents { item := Store.Items[ident] item.Lock() err = errors.Join(err, flushSoftware(e, item.Software)) if err != nil { softwareLog.Error("failed to flush software audit record", zap.Error(err)) } item.Unlock() } db.Close(db.VulnerabilitiesIndex) writeWebtechDiagnostics() return errors.Join(err, softwareLog.Sync()) }, }
Decoder for protocol analysis and writing audit records to disk.
Functions ¶
func CheckVulnerabilities ¶
CheckVulnerabilities sets the HasKnownVulnerabilities flag This should be called after vulnerability lookup
func EnhanceSoftwareRecord ¶
EnhanceSoftwareRecord adds detection context and behavioral fields to a Software record
func InitializeWebtech ¶
InitializeWebtech snapshots optional data before capture workers start.
func InitializeWebtechWith ¶
func LookupUserAgent ¶ added in v0.16.9
func LookupUserAgent(raw string) *userAgent
LookupUserAgent caches parser results under a bounded encoded-size budget.
func ObserveWebtech ¶
func ObserveWebtech(o webtech.Observation, body io.Reader, encoding, authority, flow, cid string, ts int64) webtech.Report
ObserveWebtech is called on a paired response before payload disposal. No raw HTML, header value, cookie, URL query or external dependency is retained.
func ParseUserAgent ¶
func ParseUserAgent(ua string) *userAgent
ParseUserAgent processes a raw user agent string and returned a structured instance.
func RenderWebtech ¶
func ResetCaches ¶
func ResetCaches()
ResetCaches clears all global caches to prevent memory accumulation between multi-file processing runs. CRITICAL: This must be called between file processing to prevent unbounded memory growth.
func StorePassiveSoftware ¶ added in v0.16.9
StorePassiveSoftware retains observations that do not authorize CVE lookups.
func WebtechDiagnostics ¶
WebtechDiagnostics contains counts and catalogue identity, never body/cookies.
func WriteHTTPSoftware ¶ added in v0.16.9
func WriteHTTPSoftware(items []*AtomicSoftware, flow, communityID string)
WriteHTTPSoftware appends observed flow memberships without decoding old lists.
func WriteSoftware ¶
func WriteSoftware(software []*AtomicSoftware, update func(s *AtomicSoftware))
WriteSoftware can be used to write software to the software audit record writer.
Types ¶
type AtomicSoftware ¶
AtomicSoftware wraps a types.Software to provide atomic access.
func WhatSoftwareHTTP ¶
func WhatSoftwareHTTP(flowIdent string, h *types.HTTP) (s []*AtomicSoftware)
WhatSoftwareHTTP TODO: pass in the device profile.
type CMSHyperscanBuildStats ¶
type CMSHyperscanBuildStats struct {
HeaderPatterns int `json:"header_patterns"`
HeaderRejections int `json:"header_rejections"`
CookiePatterns int `json:"cookie_patterns"`
CookieRejections int `json:"cookie_rejections"`
HeaderProductCandidates int `json:"header_product_candidates"`
CookieProductCandidates int `json:"cookie_product_candidates"`
}
CMSHyperscanBuildStats describes the outcome of buildCMSHSIndex.
Re-exported in stub builds so the web UI handler can render the same schema regardless of how netcap was compiled.
type CMSHyperscanStatus ¶
type CMSHyperscanStatus struct {
Enabled bool `json:"enabled"`
LibVersion string `json:"lib_version"`
Build CMSHyperscanBuildStats `json:"build"`
BuildError string `json:"build_error,omitempty"`
HeaderScans uint64 `json:"header_scans"`
HeaderMatches uint64 `json:"header_matches"`
HeaderErrors uint64 `json:"header_errors"`
CookieScans uint64 `json:"cookie_scans"`
CookieMatches uint64 `json:"cookie_matches"`
CookieErrors uint64 `json:"cookie_errors"`
ScanFallbacks uint64 `json:"scan_fallbacks"`
}
CMSHyperscanStatus is the JSON-friendly snapshot of the CMS Hyperscan integration. In stub builds, Enabled is false and counters are zero.
func GetCMSHyperscanStatus ¶
func GetCMSHyperscanStatus() CMSHyperscanStatus
GetCMSHyperscanStatus returns a "disabled" snapshot.