yara

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FailClosed        = "fail_closed"
	FailOpenWithAlert = "fail_open_with_alert"
)

FailClosed / FailOpenWithAlert are the two posture strings for the on_timeout and on_saturation policies.

Variables

This section is empty.

Functions

func GetAlertDegraded

func GetAlertDegraded() bool

GetAlertDegraded reports whether degraded-mode alerts are enabled.

func GetEnabled

func GetEnabled() bool

GetEnabled reports whether the YARA engine is enabled.

func GetMaxInflight

func GetMaxInflight() int64

GetMaxInflight returns the in-flight regex-goroutine cap.

func GetOnSaturation

func GetOnSaturation() string

GetOnSaturation returns the on-saturation posture (FailClosed | FailOpenWithAlert).

func GetOnTimeout

func GetOnTimeout() string

GetOnTimeout returns the on-timeout posture (FailClosed | FailOpenWithAlert).

func GetTimeoutSecs

func GetTimeoutSecs() int64

GetTimeoutSecs returns the per-regex match timeout in seconds.

func Inflight

func Inflight() int64

Inflight returns the current count of in-flight regex-match goroutines (observability; surfaced in the security-scan stats map).

func SetAlertDegraded

func SetAlertDegraded(v bool)

SetAlertDegraded toggles degraded-mode alerting.

func SetEnabled

func SetEnabled(v bool)

SetEnabled toggles the YARA engine on/off.

func SetMaxInflight

func SetMaxInflight(n int64)

SetMaxInflight sets the in-flight regex-goroutine cap.

func SetOnSaturation

func SetOnSaturation(v string)

SetOnSaturation sets the on-saturation posture (FailClosed | FailOpenWithAlert).

func SetOnTimeout

func SetOnTimeout(v string)

SetOnTimeout sets the on-timeout posture (FailClosed | FailOpenWithAlert).

func SetTimeoutSecs

func SetTimeoutSecs(n int64)

SetTimeoutSecs sets the per-regex match timeout in seconds.

func ValidateSource

func ValidateSource(src string) (names []string, warnings []string, err error)

ValidateSource parses a YARA rule source string without loading it into the global rule set. Used by the admin UI's "validate" feature so operators can check a rule before persisting it. Tier 3.1.

Returns the list of rule names successfully parsed and any parser warnings. Returns an error only when the source contains no valid rules at all; a non-empty warnings slice with a non-empty names slice indicates a source that loaded some rules but skipped others.

Types

type RuleSet

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

RuleSet holds compiled YARA rules loaded from a directory. All methods are safe for concurrent use.

func NewRuleSet

func NewRuleSet() *RuleSet

NewRuleSet returns an empty RuleSet.

func (*RuleSet) Count

func (y *RuleSet) Count() int

Count returns the number of loaded rules.

func (*RuleSet) DeleteRule

func (y *RuleSet) DeleteRule(name string) error

DeleteRule removes the named rule file from disk and reloads. Tier 3.2.

func (*RuleSet) Dir

func (y *RuleSet) Dir() string

Dir returns the directory the rule set was loaded from.

func (*RuleSet) Enabled

func (y *RuleSet) Enabled() bool

Enabled reports whether any rules are currently loaded.

func (*RuleSet) FileRules

func (y *RuleSet) FileRules() map[string][]string

FileRules returns a map from file stem to the list of rule names defined in that file. Tier 3.2: lets the GUI show "sample_rules.yar → [EICAR_Test_File, WebShell_…]" without a second round trip. File stems with no parsable rules (parse failures, empty files) map to an empty slice.

func (*RuleSet) Files

func (y *RuleSet) Files() []string

Files returns the basenames (without extension) of every *.yar / *.yara file in the configured rules directory. Tier 3.2: the GUI rule editor lists *files*, not the rule names inside them — otherwise ReadRule fails whenever a single file bundles multiple rules (the common case for starter kits). The returned list is sorted and de-duplicated across the two extensions.

func (*RuleSet) LoadDir

func (y *RuleSet) LoadDir(dir string) error

LoadDir loads all *.yar and *.yara files from dir, replacing current rules atomically. Errors in individual rule files are logged and captured in y.warnings so admins can see which files failed to parse; the remaining rules are still loaded.

func (*RuleSet) LoadSource

func (y *RuleSet) LoadSource(src string) ([]string, error)

LoadSource compiles rules from a literal source string and installs them, replacing the current rule set; it returns any parser warnings. It is the directory-free counterpart to LoadDir, used for programmatic/test rule loading (the package-main test suite builds rule sets this way).

func (*RuleSet) Match

func (y *RuleSet) Match(data []byte) []string

Match returns the names of every rule that matches data.

func (*RuleSet) Names

func (y *RuleSet) Names() []string

Names returns the names of all currently loaded rules. Tier 2.1: exposes the rule set so admins can verify which rules are active.

func (*RuleSet) ReadRule

func (y *RuleSet) ReadRule(name string) (string, error)

ReadRule returns the raw source of the named rule file. Tier 3.2.

func (*RuleSet) SetDir

func (y *RuleSet) SetDir(dir string)

SetDir updates the rules directory without loading. Used on first-time startup when /data/yara/ does not yet exist and the admin wants to create rules via the API. Tier 3.2.

func (*RuleSet) Warnings

func (y *RuleSet) Warnings() []string

Warnings returns a copy of any parse/load warnings from the most recent LoadDir call. Empty when all rule files loaded cleanly. Tier 2.1: lets admins surface silently-skipped rules in the UI.

func (*RuleSet) WriteRule

func (y *RuleSet) WriteRule(name, src string) ([]string, error)

WriteRule validates and persists a YARA rule file, then reloads the rule set atomically. Tier 3.2. Uses tmp+rename for crash-safety. Returns the parser warnings (if any) so the admin can see what was skipped inside the rule file even on success.

Jump to

Keyboard shortcuts

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