Documentation ¶
Index ¶
- Variables
- func NewRuleFileList(dirs []string) ([]string, error)
- type Branch
- type Config
- type ContentPattern
- type Correlation
- type Detection
- type ErrBulkParseYaml
- type ErrEmptyDetection
- type ErrIncompleteDetection
- type ErrIncompleteTokenSeq
- type ErrInvalidKeywordConstruct
- type ErrInvalidKind
- type ErrInvalidRegex
- type ErrInvalidSelectionConstruct
- type ErrInvalidTokenSeq
- type ErrMissingCondition
- type ErrMissingConditionItem
- type ErrMissingDetection
- type ErrParseYaml
- type ErrUnsupportedExpression
- type ErrUnsupportedToken
- type ErrWip
- type Event
- type GlobPattern
- type Item
- type Keyword
- type Keyworder
- type Logsource
- type Matcher
- type NodeAnd
- type NodeNot
- type NodeOr
- type NodeSimpleAnd
- type NodeSimpleOr
- type NumMatcher
- type NumMatchers
- type NumPattern
- type PrefixPattern
- type RegexPattern
- type Result
- type Results
- type Rule
- type Ruleset
- type Selection
- type SelectionNumItem
- type SelectionStringItem
- type Selector
- type SimplePattern
- type SimpleRule
- type StringMatcher
- type StringMatchers
- type StringMatchersConj
- type SuffixPattern
- type Tags
- type TextPatternModifier
- type Token
- type Tree
Constants ¶
This section is empty.
Variables ¶
var ErrUnableToReflect = errors.New("unable to reflect on pattern kind")
ErrUnableToReflect indicates that kind reflection could not be done, as typeOf returned a nil value likely a missing pattern
Functions ¶
func NewRuleFileList ¶
NewRuleFileList finds all yaml files from defined root directories Subtree is scanned recursively No file validation, other than suffix matching
Types ¶
type Branch ¶
type Branch interface { Matcher }
Branch implements Matcher with additional methods for walking and debugging the tree
func NewSelectionBranch ¶
type Config ¶
type Config struct { // root directory for recursive rule search // rules must be readable files with "yml" suffix Directory []string }
Config is used as argument to creating a new ruleset
type ContentPattern ¶
ContentPattern is a token for literal content matching
func (ContentPattern) StringMatch ¶
func (c ContentPattern) StringMatch(msg string) bool
StringMatch implements StringMatcher
type Correlation ¶
type Correlation struct { Name string `yaml:"name" json:"name"` // Action will be correlation for correlations, and empty for rules. Action actions.Action `yaml:"action" json:"action"` // event_count, value_count, temporal Type ruleTypes.RuleType `yaml:"type" json:"type"` Condition map[conditionTypes.ConditionType]interface{} `yaml:"condition" json:"condition"` // RulesString exists for a first step of getting rules of a correlation RulesString []string `yaml:"rules" json:"-"` Matchers []Matcher `yaml:"-" json:"rules"` GroupBy []string `yaml:"group-by" json:"group_by"` // Timespan defines a time period in which the correlation should be applied. // The following format must be used: number + letter (in lowercase) // Xs seconds // Xm minutes // Xh hours // Xd days Timespan *time.Duration `yaml:"timespan" json:"timespan"` }
func (Correlation) NewTree ¶
func (c Correlation) NewTree() (*Tree, error)
NewTree parses rule handle into an abstract syntax tree
type Detection ¶
type Detection map[string]interface{}
Detection represents the detection field in sigma rule contains condition expression and identifier fields for building AST
func (Detection) ExtractCondition ¶
type ErrBulkParseYaml ¶
type ErrBulkParseYaml struct {
Errs []ErrParseYaml
}
ErrGotBrokenYamlFiles is a bulk error handler for dealing with broken sigma rules Some rules are bound to fail, no reason to exit entire application Individual errors can be collected and returned at the end Called decides if they should be only reported or it warrants full exit
func (ErrBulkParseYaml) Error ¶
func (e ErrBulkParseYaml) Error() string
type ErrEmptyDetection ¶
type ErrEmptyDetection struct{}
ErrEmptyDetection indicates detection field present but empty
func (ErrEmptyDetection) Error ¶
func (e ErrEmptyDetection) Error() string
type ErrIncompleteDetection ¶
ErrIncompleteDetection indicates a rule has defined identifiers that are missing in detection map
func (ErrIncompleteDetection) Error ¶
func (e ErrIncompleteDetection) Error() string
type ErrIncompleteTokenSeq ¶
ErrIncompleteTokenSeq is invoked when lex channel drain does not end with EOF thus indicating incomplete lexing sequence
func (ErrIncompleteTokenSeq) Error ¶
func (e ErrIncompleteTokenSeq) Error() string
type ErrInvalidKeywordConstruct ¶
type ErrInvalidKeywordConstruct struct { Msg string Expr interface{} }
ErrInvalidKeywordConstruct indicates that parser found a keyword expression that did not match any known keyword rule structure could be unmarshal issue
func (ErrInvalidKeywordConstruct) Error ¶
func (e ErrInvalidKeywordConstruct) Error() string
type ErrInvalidKind ¶
ErrInvalidKind indicates that type switching function received an unsupported or unhandled data type Contains the type in question, arbitrary error text and keyword/selection indicator Critical is used to indicate if this error should cause an exit or can simply be handled as a warning for future improvements
func (ErrInvalidKind) Error ¶
func (e ErrInvalidKind) Error() string
type ErrInvalidRegex ¶
ErrInvalidRegex contextualizes broken regular expressions presented by the user
type ErrInvalidSelectionConstruct ¶
type ErrInvalidSelectionConstruct struct { Msg string Expr interface{} }
ErrInvalidSelectionConstruct indicates that parser found a selection expression that did not match any known selection rule structure could be unmarshal issue
func (ErrInvalidSelectionConstruct) Error ¶
func (e ErrInvalidSelectionConstruct) Error() string
type ErrInvalidTokenSeq ¶
ErrInvalidTokenSeq indicates expression syntax error from rule writer For example, two indents should be separated by a logical AND / OR operator
func (ErrInvalidTokenSeq) Error ¶
func (e ErrInvalidTokenSeq) Error() string
type ErrMissingCondition ¶
type ErrMissingCondition struct{}
ErrMissingCondition indicates missing condition field
func (ErrMissingCondition) Error ¶
func (e ErrMissingCondition) Error() string
type ErrMissingConditionItem ¶
type ErrMissingConditionItem struct {
Key string
}
ErrMissingConditionItem indicates that identifier in condition is missing in detection map
func (ErrMissingConditionItem) Error ¶
func (e ErrMissingConditionItem) Error() string
type ErrMissingDetection ¶
type ErrMissingDetection struct{}
ErrMissingDetection indicates missing detection field
func (ErrMissingDetection) Error ¶
func (e ErrMissingDetection) Error() string
type ErrParseYaml ¶
ErrParseYaml indicates YAML parsing error
func (ErrParseYaml) Error ¶
func (e ErrParseYaml) Error() string
type ErrUnsupportedExpression ¶
ErrUnsupportedExpression indicates that rule expression is not yet supported by parser mostly a type issue
func (ErrUnsupportedExpression) Error ¶
func (e ErrUnsupportedExpression) Error() string
type ErrUnsupportedToken ¶
type ErrUnsupportedToken struct{ Msg string }
ErrUnsupportedToken is a parser error indicating lexical token that is not yet supported Meant to be used as informational warning, rather than application breaking error
func (ErrUnsupportedToken) Error ¶
func (e ErrUnsupportedToken) Error() string
type ErrWip ¶
type ErrWip struct{}
ErrWip indicates a rule expression that is currently Work In Progress Functions like ErrUnsupportedToken but indicates that feature is under active development Non-critical escape hatch while debugging
type Event ¶
Event implements sigma rule types by embedding Keyworder and Selector Used by rules to extract relevant fields
type GlobPattern ¶
GlobPattern is similar to ContentPattern but allows for asterisk wildcards
func (GlobPattern) StringMatch ¶
func (g GlobPattern) StringMatch(msg string) bool
StringMatch implements StringMatcher
type Item ¶
Item is lexical token along with respective plaintext value Item is communicated between lexer and parser
type Keyword ¶
type Keyword struct { S StringMatcher // contains filtered or unexported fields }
Keyword is a container for patterns joined by logical disjunction
func NewKeyword ¶
type Keyworder ¶
Keyworder implements keywords sigma rule type on arbitrary event Should return list of fields that are relevant for rule matching
type Logsource ¶
type Logsource struct { Product string `yaml:"product" json:"product"` Category string `yaml:"category" json:"category"` Service string `yaml:"service" json:"service"` Definition string `yaml:"definition" json:"definition"` }
Logsource represents the logsource field in sigma rule It defines relevant event streams and is used for pre-filtering
type NodeAnd ¶
type NodeAnd struct {
L, R Branch
}
NodeAnd is a two element node of a binary tree with Left and Right branches connected via logical conjunction
type NodeOr ¶
type NodeOr struct {
L, R Branch
}
NodeOr is a two element node of a binary tree with Left and Right branches connected via logical disjunction
type NodeSimpleAnd ¶
type NodeSimpleAnd []Branch
NodeSimpleAnd is a list of matchers connected with logical conjunction
func (NodeSimpleAnd) Match ¶
func (n NodeSimpleAnd) Match(e Event) (bool, bool)
Match implements Matcher
func (NodeSimpleAnd) Reduce ¶
func (n NodeSimpleAnd) Reduce() Branch
Reduce cleans up unneeded slices Static structures can be used if node only holds one or two elements Avoids pointless runtime loops
type NodeSimpleOr ¶
type NodeSimpleOr []Branch
NodeSimpleOr is a list of matchers connected with logical disjunction
func (NodeSimpleOr) Match ¶
func (n NodeSimpleOr) Match(e Event) (bool, bool)
Match implements Matcher
func (NodeSimpleOr) Reduce ¶
func (n NodeSimpleOr) Reduce() Branch
Reduce cleans up unneeded slices Static structures can be used if node only holds one or two elements Avoids pointless runtime loops
type NumMatcher ¶
NumMatcher is an atomic pattern for numeric item or list of items
func NewNumMatcher ¶
func NewNumMatcher(patterns ...int) (NumMatcher, error)
type NumMatchers ¶
type NumMatchers []NumMatcher
NumMatchers holds multiple numeric matchers
func (NumMatchers) NumMatch ¶
func (n NumMatchers) NumMatch(val int) bool
NumMatch implements NumMatcher
type NumPattern ¶
type NumPattern struct {
Val int
}
NumPattern matches on numeric value
func (NumPattern) NumMatch ¶
func (n NumPattern) NumMatch(val int) bool
NumMatch implements NumMatcher
type PrefixPattern ¶
PrefixPattern is a token for literal content matching
func (PrefixPattern) StringMatch ¶
func (c PrefixPattern) StringMatch(msg string) bool
StringMatch implements StringMatcher
type RegexPattern ¶
RegexPattern is for matching messages with regular expresions
func (RegexPattern) StringMatch ¶
func (r RegexPattern) StringMatch(msg string) bool
StringMatch implements StringMatcher
type Result ¶
type Result struct { Tags `json:"tags"` ID string `json:"id"` Title string `json:"title"` Description string `json:"description"` }
Result is an object returned on positive sigma match
type Results ¶
type Results []Result
Results should be returned when single event matches multiple rules
type Rule ¶
func RulesFromFiles ¶
RulesFromFiles reads a list of sigma rule paths and parses them to rule objects
type Ruleset ¶
type Ruleset struct { Rules []*Tree // contains filtered or unexported fields }
Ruleset is a collection of rules
func NewRuleset ¶
NewRuleset instanciates a Ruleset object
type Selection ¶
type Selection struct { N []SelectionNumItem S []SelectionStringItem // contains filtered or unexported fields }
type SelectionNumItem ¶
type SelectionNumItem struct { Key string Pattern NumMatcher }
type SelectionStringItem ¶
type SelectionStringItem struct { Key string Pattern StringMatcher }
type SimplePattern ¶
SimplePattern is a reference type to illustrate StringMatcher
func (SimplePattern) StringMatch ¶
func (s SimplePattern) StringMatch(msg string) bool
StringMatch implements StringMatcher
type SimpleRule ¶
type SimpleRule struct { Name string `yaml:"name" json:"name"` Author string `yaml:"author" json:"author"` // Date *time.Time `yaml:"date" json:"date"` // Modified *time.Time `yaml:"modified" json:"modified"` Description string `yaml:"description" json:"description"` Falsepositives []string `yaml:"falsepositives" json:"falsepositives"` Fields []string `yaml:"fields" json:"fields"` ID string `yaml:"id" json:"id"` Level string `yaml:"level" json:"level"` Title string `yaml:"title" json:"title"` Status string `yaml:"status" json:"status"` References []string `yaml:"references" json:"references"` Logsource Logsource `yaml:"logsource" json:"logsource"` Detection Detection `yaml:"detection" json:"detection"` Tags Tags `yaml:"tags" json:"tags"` }
Rule defines raw rule conforming to sigma rule specification https://github.com/Neo23x0/sigma/wiki/Specification only meant to be used for parsing yaml that matches Sigma rule definition
func (SimpleRule) NewTree ¶
func (r SimpleRule) NewTree() (*Tree, error)
NewTree parses rule handle into an abstract syntax tree
type StringMatcher ¶
StringMatcher is an atomic pattern that could implement glob, literal or regex matchers
func NewStringMatcher ¶
func NewStringMatcher( mod TextPatternModifier, lower, all, noCollapseWS bool, patterns ...string, ) (StringMatcher, error)
type StringMatchers ¶
type StringMatchers []StringMatcher
StringMatchers holds multiple atomic matchers Patterns are meant to be list of possibilities thus, objects are joined with logical disjunctions
func (StringMatchers) Optimize ¶
func (s StringMatchers) Optimize() StringMatchers
Optimize creates a new StringMatchers slice ordered by matcher type First match wins, thus we can optimize by making sure fast string patterns are executed first, then globs, and finally slow regular expressions
func (StringMatchers) StringMatch ¶
func (s StringMatchers) StringMatch(msg string) bool
StringMatch implements StringMatcher
type StringMatchersConj ¶
type StringMatchersConj []StringMatcher
StringMatchersConj is similar to StringMatcher but elements are joined with conjunction, i.e. all patterns must match used to implement "all" specifier for selection types
func (StringMatchersConj) Optimize ¶
func (s StringMatchersConj) Optimize() StringMatchersConj
Optimize creates a new StringMatchers slice ordered by matcher type First match wins, thus we can optimize by making sure fast string patterns are executed first, then globs, and finally slow regular expressions
func (StringMatchersConj) StringMatch ¶
func (s StringMatchersConj) StringMatch(msg string) bool
StringMatch implements StringMatcher
type SuffixPattern ¶
SuffixPattern is a token for literal content matching
func (SuffixPattern) StringMatch ¶
func (c SuffixPattern) StringMatch(msg string) bool
StringMatch implements StringMatcher
type Tags ¶
type Tags []string
Tags contains a metadata list for tying positive matches together with other threat intel sources For example, for attaching MITRE ATT&CK tactics or techniques to the event
type TextPatternModifier ¶
type TextPatternModifier int
const ( TextPatternNone TextPatternModifier = iota TextPatternContains TextPatternPrefix TextPatternSuffix TextPatternAll TextPatternRegex TextPatternKeyword )
type Token ¶
type Token int
Token is a lexical token extracted from condition field
const ( TokBegin Token = iota // Helpers for internal stuff TokErr TokUnsupp TokNil // user-defined word TokIdentifier TokIdentifierWithWildcard TokIdentifierAll // Literals TokLitEof // Separators TokSepLpar TokSepRpar TokSepPipe // Operators TokOpEq TokOpGt TokOpGte TokOpLt TokOpLte // Keywords TokKeywordAnd TokKeywordOr TokKeywordNot TokKeywordAgg // TODO TokKeywordNear TokKeywordBy // Statements TokStOne TokStAll )