Documentation
¶
Overview ¶
Package fireeye provides a detection-only rule engine for matching arbitrary string-valued event fields.
Callers own all behavior after detection, including alerting, blocking, routing, and response generation. The root package owns rule preparation, indexing, matching, and the RuleProvider contract. Filesystem, HTTP, and watcher adapters live in rulefile, httpfields, and rulewatch respectively.
Index ¶
- Constants
- type DetectionMatch
- type DetectionOptions
- type DetectionResult
- type Engine
- func (t *Engine) Detect(eventData map[string]string) DetectionResult
- func (t *Engine) DetectAllDetailed(eventData map[string]string, maxMatches int) MultiDetectionResult
- func (t *Engine) DetectAllDetailedWithOptions(eventData map[string]string, opts MultiDetectionOptions) MultiDetectionResult
- func (t *Engine) DetectDetailed(eventData map[string]string) (DetectionResult, ThreatRule)
- func (t *Engine) DetectDetailedWithOptions(eventData map[string]string, opts DetectionOptions) (DetectionResult, ThreatRule)
- func (t *Engine) DetectWithOptions(eventData map[string]string, opts DetectionOptions) DetectionResult
- func (tm *Engine) IndexStats() IndexStats
- func (t *Engine) LoadFromProvider(ctx context.Context, provider RuleProvider, opts LoadOptions) error
- func (tm *Engine) PrimaryFields() []string
- func (tm *Engine) RebuildIndex()
- func (t *Engine) RemoveRule(ruleID string) bool
- func (t *Engine) ReplaceRules(bundle RuleBundle, opts LoadOptions) error
- func (tm *Engine) SetPrimaryFields(fields []string)
- func (t *Engine) UpsertRule(rule ThreatRule, opts LoadOptions) error
- type ExtractionNode
- type ExtractionRule
- type ExtractionType
- type FieldIndexStats
- type GlobalConfig
- type GroupLogic
- type IndexStats
- type LoadOptions
- type MatchType
- type Meta
- type MultiDetectionOptions
- type MultiDetectionResult
- type Priority
- type Rule
- type RuleBundle
- type RuleGroup
- type RuleHitStats
- type RuleProvider
- type ThreatRule
Examples ¶
Constants ¶
const RegexMatchTimeout = 100 * time.Millisecond
RegexMatchTimeout limits regexp2 matching to avoid pathological rule matches.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DetectionMatch ¶
type DetectionMatch struct {
Detection DetectionResult `json:"detection"`
Rule ThreatRule `json:"rule"`
}
DetectionMatch is one fully matched rule and its isolated detection result.
type DetectionOptions ¶
type DetectionOptions struct {
// SensitiveFieldsMatchByPresence makes a sensitive field predicate match
// when the field exists, without comparing its configured values.
SensitiveFieldsMatchByPresence bool
}
DetectionOptions controls one detection operation.
type DetectionResult ¶
type DetectionResult struct {
Matched bool `json:"matched"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
References []string `json:"references,omitempty"`
Level string `json:"level,omitempty"`
Remediation string `json:"remediation,omitempty"`
EventType string `json:"event_type,omitempty"`
Tags []string `json:"tags,omitempty"`
RuleID string `json:"rule_id,omitempty"`
ExtractedFields map[string]string `json:"extracted_fields,omitempty"`
ProcessingTimeMicros int64 `json:"processing_time_us"`
AttemptedRules int `json:"attempted_rules"`
}
DetectionResult is the structured result of one detection run.
func (DetectionResult) JSON ¶
func (r DetectionResult) JSON() string
JSON returns an indented JSON representation of the result.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine owns rule loading, indexing, and detection state.
func (*Engine) Detect ¶
func (t *Engine) Detect(eventData map[string]string) DetectionResult
Detect detects one event using value comparison for sensitive fields.
Example ¶
package main
import (
"fmt"
fireeye "github.com/phil-fly/FireEye"
)
func main() {
engine := fireeye.NewEngine()
err := engine.UpsertRule(fireeye.ThreatRule{
ID: "admin-path-probe",
Enabled: true,
Priority: fireeye.PriorityHigh,
Meta: fireeye.Meta{
Title: "Admin path probe",
},
Rules: map[string]fireeye.Rule{
"Path": {
Type: fireeye.MatchContains,
Values: []any{"/admin"},
},
},
}, fireeye.LoadOptions{})
if err != nil {
panic(err)
}
result := engine.Detect(map[string]string{"Path": "/admin/login"})
fmt.Println(result.Matched, result.RuleID)
}
Output: true admin-path-probe
func (*Engine) DetectAllDetailed ¶
func (t *Engine) DetectAllDetailed(eventData map[string]string, maxMatches int) MultiDetectionResult
DetectAllDetailed returns a deterministic list of fully matched rules. A positive maxMatches limits the returned list while TotalMatches remains complete. Returned rules are clones and can be safely mutated.
func (*Engine) DetectAllDetailedWithOptions ¶
func (t *Engine) DetectAllDetailedWithOptions(eventData map[string]string, opts MultiDetectionOptions) MultiDetectionResult
DetectAllDetailedWithOptions is the configurable detailed multi-match API.
func (*Engine) DetectDetailed ¶
func (t *Engine) DetectDetailed(eventData map[string]string) (DetectionResult, ThreatRule)
DetectDetailed returns the detection result and the matched rule.
func (*Engine) DetectDetailedWithOptions ¶
func (t *Engine) DetectDetailedWithOptions(eventData map[string]string, opts DetectionOptions) (DetectionResult, ThreatRule)
DetectDetailedWithOptions detects one event and returns a cloned matched rule.
func (*Engine) DetectWithOptions ¶
func (t *Engine) DetectWithOptions(eventData map[string]string, opts DetectionOptions) DetectionResult
DetectWithOptions detects one event using explicit operation options.
func (*Engine) IndexStats ¶
func (tm *Engine) IndexStats() IndexStats
IndexStats returns an inspection snapshot without exposing index internals.
func (*Engine) LoadFromProvider ¶
func (t *Engine) LoadFromProvider(ctx context.Context, provider RuleProvider, opts LoadOptions) error
LoadFromProvider loads rules from a caller-managed source.
func (*Engine) PrimaryFields ¶
PrimaryFields returns a snapshot of the ordered index fields.
func (*Engine) RebuildIndex ¶
func (tm *Engine) RebuildIndex()
RebuildIndex rebuilds the match index from the current rule snapshot.
func (*Engine) RemoveRule ¶
RemoveRule deletes one rule and rebuilds the match index.
func (*Engine) ReplaceRules ¶
func (t *Engine) ReplaceRules(bundle RuleBundle, opts LoadOptions) error
ReplaceRules atomically replaces the in-memory rule snapshot.
func (*Engine) SetPrimaryFields ¶
SetPrimaryFields replaces the ordered fields used to build the rule index.
func (*Engine) UpsertRule ¶
func (t *Engine) UpsertRule(rule ThreatRule, opts LoadOptions) error
UpsertRule prepares and stores one rule with the current global config.
type ExtractionNode ¶
type ExtractionNode struct {
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"` // template reference, for example extraction_templates.name
Field string `json:"field" yaml:"field"`
Rules []ExtractionRule `json:"rules" yaml:"rules"`
}
ExtractionNode defines a named extraction flow.
type ExtractionRule ¶
type ExtractionRule struct {
Type ExtractionType `json:"type" yaml:"type"` // regexp base64
Expression string `json:"data,omitempty" yaml:"data,omitempty"`
}
ExtractionRule defines one extraction step.
type ExtractionType ¶
type ExtractionType string
ExtractionType identifies a supported extraction step.
const ( ExtractionBase64Decode ExtractionType = "base64" // Base64 decode ExtractionRegexp ExtractionType = "regexp" // regular expression extraction ExtractionURLDecode ExtractionType = "urldecode" // URL decode ExtractionGJSON ExtractionType = "gjson" // JSON path extraction )
type FieldIndexStats ¶
type FieldIndexStats struct {
ExactMatchRules int `json:"exact_match_rules"`
RegexpRules int `json:"regexp_rules"`
ScanRules int `json:"scan_rules"`
}
FieldIndexStats describes the index entries for one event field.
type GlobalConfig ¶
type GlobalConfig struct {
Version string `yaml:"version"` // config version
Patterns map[string]string `yaml:"patterns"` // pattern variables
RuleTemplates map[string]Rule `yaml:"rule_templates"` // rule templates
ExtractionTemplates map[string]ExtractionNode `yaml:"extraction_templates"` // extraction templates
}
GlobalConfig contains reusable patterns and templates.
func NewGlobalConfig ¶
func NewGlobalConfig() *GlobalConfig
NewGlobalConfig creates an empty global config.
type GroupLogic ¶
type GroupLogic string
GroupLogic identifies how rules inside one RuleGroup are combined.
const ( GroupLogicAND GroupLogic = "AND" GroupLogicOR GroupLogic = "OR" )
type IndexStats ¶
type IndexStats struct {
RuleCount int `json:"rule_count"`
DefaultRuleCount int `json:"default_rule_count"`
Fields map[string]FieldIndexStats `json:"fields"`
HotRules []RuleHitStats `json:"hot_rules"`
}
IndexStats is a read-only snapshot of the engine's match index.
type LoadOptions ¶
type LoadOptions struct {
// SkipSensitiveRules excludes rules marked sensitive from the new snapshot.
SkipSensitiveRules bool
}
LoadOptions controls rule loading behavior.
type MatchType ¶
type MatchType string
MatchType identifies how a rule compares field values.
const ( MatchString MatchType = "string" // exact string match MatchRegexp MatchType = "regexp" // regular expression match MatchStartsWith MatchType = "startswith" // prefix match MatchEndsWith MatchType = "endswith" // suffix match MatchContains MatchType = "contains" // substring match MatchContainsAll MatchType = "contains_all" // all configured substrings must be present MatchExists MatchType = "exists" // field-presence match )
type Meta ¶
type Meta struct {
Title string `json:"title" yaml:"title"` // display name
Author string `json:"author,omitempty" yaml:"author,omitempty"` // rule author
Description string `json:"description,omitempty" default:"nil." yaml:"description,omitempty"` // description
Remediation string `json:"remediation,omitempty" default:"nil." yaml:"remediation,omitempty"` // remediation guidance
References []string `json:"references,omitempty" yaml:"references,omitempty"` // references
}
Meta contains rule metadata.
type MultiDetectionOptions ¶
type MultiDetectionOptions struct {
DetectionOptions
// MaxMatches limits retained and returned matches. Values less than one
// return every match. TotalMatches always reports the complete match count.
MaxMatches int
}
MultiDetectionOptions controls one detailed multi-match detection operation.
type MultiDetectionResult ¶
type MultiDetectionResult struct {
Matches []DetectionMatch `json:"matches"`
TotalMatches int `json:"total_matches"`
Truncated bool `json:"truncated"`
AttemptedRules int `json:"attempted_rules"`
ProcessingTimeMicros int64 `json:"processing_time_us"`
}
MultiDetectionResult reports deterministic matches and overflow state.
type Priority ¶
type Priority int
Priority is the rule priority range, from 1 to 100.
const ( PriorityLowest Priority = 1 // lowest priority PriorityLow Priority = 25 // low priority PriorityMedium Priority = 50 // medium priority PriorityHigh Priority = 75 // high priority PriorityHighest Priority = 100 // highest priority // Priority band boundaries. PriorityLowMax Priority = 24 // maximum low-priority value PriorityMediumMax Priority = 74 // maximum medium-priority value PriorityHighMax Priority = 100 // maximum high-priority value )
Canonical priority values.
type Rule ¶
type Rule struct {
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"` // template reference, for example rule_templates.name
Sensitivity bool `json:"sensitivity,omitempty" default:"false" yaml:"sensitivity,omitempty"`
ValueExtraction bool `json:"value_extraction,omitempty" default:"false" yaml:"value_extraction,omitempty"`
Extraction []ExtractionRule `json:"extractionflow,omitempty" yaml:"extractionflow,omitempty"`
Type MatchType `json:"type" yaml:"type"`
Values []any `json:"data,omitempty" yaml:"data,omitempty"`
Negate bool `json:"notIs,omitempty" yaml:"notIs,omitempty"`
}
Rule defines one field matching rule.
type RuleBundle ¶
type RuleBundle struct {
GlobalConfig *GlobalConfig
Rules []ThreatRule
}
RuleBundle contains a caller-provided rule snapshot.
func DecodeRuleBundle ¶
func DecodeRuleBundle(data []byte) (RuleBundle, error)
DecodeRuleBundle strictly decodes one rule or a rules bundle from YAML or JSON bytes.
type RuleGroup ¶
type RuleGroup struct {
Logic GroupLogic `json:"logic" yaml:"logic"`
Rules map[string]Rule `json:"rules" yaml:"rules"`
}
RuleGroup is one alternative field-rule set within a logical threat rule.
type RuleHitStats ¶
RuleHitStats reports one rule's in-process match count.
type RuleProvider ¶
type RuleProvider interface {
Load(ctx context.Context) (RuleBundle, error)
}
RuleProvider lets callers supply rules from any backing store.
type ThreatRule ¶
type ThreatRule struct {
ID string `json:"id,omitempty" yaml:"id,omitempty"`
Meta `json:"meta" yaml:"meta"` // rule metadata
Enabled bool `json:"enabled" yaml:"enabled"` // enabled state
RequireAll bool `json:"and,omitempty" yaml:"and,omitempty"` // AND semantics when true
Priority Priority `json:"priority,omitempty" default:"middle" yaml:"priority,omitempty"` // priority
Sensitivity bool `json:"sensitivity,omitempty" default:"false" yaml:"sensitivity,omitempty"` // sensitivity flag
Rules map[string]Rule `json:"rules,omitempty" yaml:"rules,omitempty"` // field matching rules
Groups []RuleGroup `json:"groups,omitempty" yaml:"groups,omitempty"` // alternative field-rule sets
Extraction map[string]ExtractionNode `json:"extraction,omitempty" yaml:"extraction,omitempty"` // extraction flows
Source string `json:"source,omitempty" yaml:"source,omitempty"` // rule source
System string `json:"system,omitempty" yaml:"system,omitempty"` // matching system
Level string `json:"level,omitempty" yaml:"level,omitempty"` // threat level
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"` // tags
EventType string `json:"event_type,omitempty" yaml:"event_type,omitempty"` // event type
Expressions []string `json:"exp,omitempty" yaml:"exp,omitempty"` // expressions
// contains filtered or unexported fields
}
ThreatRule is the complete rule definition.
func (*ThreatRule) ExtractFields ¶
func (t *ThreatRule) ExtractFields(event map[string]string) map[string]string
ExtractFields runs this rule's configured extraction flows against an event.
func (*ThreatRule) HasExplicitPriority ¶
func (t *ThreatRule) HasExplicitPriority() bool
HasExplicitPriority reports whether priority was present in decoded YAML or JSON.
func (*ThreatRule) Validate ¶
func (t *ThreatRule) Validate() error
Validate checks the complete public rule contract.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package httpfields converts HTTP requests into FireEye event fields.
|
Package httpfields converts HTTP requests into FireEye event fields. |
|
Package rulefile provides strict filesystem adapters for FireEye rules.
|
Package rulefile provides strict filesystem adapters for FireEye rules. |
|
Package rulewatch reloads a FireEye engine when a rule directory changes.
|
Package rulewatch reloads a FireEye engine when a rule directory changes. |
|
tools
|
|
|
fireeye_rule_exp_verify
command
|
|
|
fireeye_rule_migrate
command
|