rule

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateRuleDirectory

func ValidateRuleDirectory(directory string) (errs []error, fatalErr error)

ValidateRuleDirectory 严格验证规则目录下的所有规则文件。

行为: - 遍历目录中的所有 YAML 规则文件 - 对每个文件调用 LoadRuleStrict 收集 YAML/Matcher 的所有错误 - 不会中断整个遍历,所有问题都会被返回

fatalErr 仅在目录本身不可访问等致命场景下返回; errs 列出所有规则文件级别的问题,用于 validate 模式报告。

Types

type CompiledRule added in v1.7.0

type CompiledRule struct {
	Source  *Rule
	Runtime *Rule
}

CompiledRule is the runtime representation of a YAML Rule. The source Rule is retained for metadata and extraction, while the rule set owns only compiled runtime entries.

type Manager

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

Manager owns a sequence of immutable rules snapshots for one rule directory.

func LoadDefaultRules added in v1.6.18

func LoadDefaultRules(ctx context.Context) (*Manager, error)

LoadDefaultRules ensures the default rule repository exists and loads it.

func NewManager

func NewManager(path string) (*Manager, error)

NewManager loads the initial immutable rules snapshot from path.

func (*Manager) FindRuleByName

func (m *Manager) FindRuleByName(name string) *Rule

FindRuleByName returns the first source rule in a category, if present.

func (*Manager) GetLastLoadTime

func (m *Manager) GetLastLoadTime() time.Time

GetLastLoadTime returns when the current snapshot was published.

func (*Manager) IsLoaded

func (m *Manager) IsLoaded() bool

IsLoaded reports whether a rules snapshot is available.

func (*Manager) ReloadRules

func (m *Manager) ReloadRules() error

ReloadRules loads and publishes a new immutable rules snapshot. A failed reload leaves the last successfully loaded snapshot available to scanners.

func (*Manager) Snapshot added in v1.7.1

func (m *Manager) Snapshot() *RuleSet

Snapshot returns the latest immutable rules snapshot.

type MatchPartGetter

type MatchPartGetter func(part string, CaseSensitive bool) string

MatchPartGetter 定义了获取匹配部分的函数类型 CaseSensitive 大小写敏感

type MatchResult

type MatchResult struct {
	Rule      *Rule             // 匹配到的规则
	Extracted map[string]string // 提取的字段值
}

MatchResult 表示匹配结果

func (MatchResult) IsPlugin

func (m MatchResult) IsPlugin() bool

type Plugin

type Plugin struct {
	Path string `yaml:"path" json:"path,omitempty"`
}

type Rule

type Rule struct {
	Name              string `json:"name,omitempty"`
	Service           string `yaml:"service" json:"service,omitempty"`
	MatchersCondition string `yaml:"matchers-condition" json:"matchers_condition,omitempty"`
	// 组件太多  采用层级匹配 优化匹配速度
	Require  []string               `json:"require,omitempty"`
	Matchers []*matchers.Matcher    `json:"matchers,omitempty"`
	Plugins  []*Plugin              `yaml:"plugins"`
	Cpe      map[string]interface{} `yaml:"cpe" json:"cpe,omitempty"`
}

func LoadRule

func LoadRule(filename string) ([]*Rule, error)

func LoadRuleStrict

func LoadRuleStrict(filename string) ([]*Rule, []error)

LoadRuleStrict 与 LoadRule 类似,但用于严格校验: - 收集 YAML 解析错误 - 收集 matcher 编译错误 返回规则和累积错误(如果有)。

func (*Rule) Match

func (r *Rule) Match(getMatchPart MatchPartGetter) (bool, map[string]string)

type RuleSet added in v1.7.0

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

Finger 根据协议分组

func NewRuleSet added in v1.7.0

func NewRuleSet() *RuleSet

func ScanRuleDirectory

func ScanRuleDirectory(directory string) (*RuleSet, error)

func (RuleSet) AddRules added in v1.7.0

func (f RuleSet) AddRules(rules []*Rule)

func (RuleSet) CategoryCount added in v1.7.1

func (f RuleSet) CategoryCount() int

CategoryCount returns the number of rule categories in this immutable snapshot.

func (RuleSet) FirstRule added in v1.7.1

func (f RuleSet) FirstRule(name string) *Rule

FirstRule returns the first source rule in a category, if present.

func (RuleSet) Match added in v1.7.0

func (f RuleSet) Match(service string, getMatchPart MatchPartGetter) []*MatchResult

Match 执行指纹匹配并返回包含规则的匹配结果

func (RuleSet) RuleCount added in v1.7.1

func (f RuleSet) RuleCount() int

RuleCount returns the total number of compiled rules in this immutable snapshot.

Jump to

Keyboard shortcuts

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