Architecture¶
This page gives an overview of how the sigma package is structured and how its parts work
together. pySigma parses Sigma rules into an object model, rewrites them with processing pipelines
to fit the data model of a target environment, and then hands them to a backend (to generate
queries), the matcher (to evaluate events directly) or the validator. Backends and pipelines for
specific SIEMs live in separate plugin packages.
Layers¶
- 1. Rule model
Sigma YAML is loaded into a
SigmaCollectionthat containsSigmaRule,SigmaCorrelationRuleandSigmaFilterobjects, all derived fromSigmaRuleBase. A rule consists of a log source, detections (SigmaDetections›SigmaDetection›SigmaDetectionItem) and conditions, which are parsed into a tree (sigma.conditions). Modifiers (sigma.modifiers) turn raw values into Sigma types (sigma.types).- 2. Processing
The
ProcessingPipelineResolverresolves pipeline specifications (YAML files, plugin IDs or Python code), sorts them by priority and joins them into oneProcessingPipeline. A pipeline has three stages: processing items (transformations with conditions) applied to the rule, postprocessing items applied to each generated query, and finalizers applied to the whole output. ASigmaPolicycontrols the regex engine and whether templates may use variables or external sources; the default is the restrictiveSafePolicy. See Writing Processing Pipelines and SigmaPolicy.- 3. Execution
Three consumers work on the (processed) rules:
BackendandTextQueryBackendconvert rules into queries. Backend plugins subclassTextQueryBackendand define tokens, operators and correlation templates as class attributes. See Building a Backend.SigmaMatcherevaluates events directly against rules, including correlation rules with sliding time-window state. See Matching Events Against Rules.SigmaValidatorchecks rules with the validators fromsigma.validators.core, using the MITRE ATT&CK and D3FEND data fromsigma.data. See Validating Sigma Rules.
- 4. Extension
InstalledSigmaPlugins.autodiscover()loads backends, pipelines and validators from the namespace packagessigma.backends,sigma.pipelinesandsigma.validators.SigmaPluginDirectoryinstalls plugin packages from PyPI. See Plugin System.- Cross-cutting
All layers report errors through the
SigmaErrorhierarchy insigma.exceptions, which carries aSigmaRuleLocationpointing to the affected rule.
Conversion flow¶
Backend.convert() runs these steps:
Build the pipeline (
init_processing_pipeline()): the backend’s own pipeline, the user-supplied pipeline and the output format pipeline are added together. The variablesbackendandoutput_formatare set in the pipeline.Resolve references (
SigmaCollection.resolve_rule_references()): correlation rules are linked to the rules they reference, and filters are applied to the affected rules.Transform the rule (
ProcessingPipeline.apply()): every processing item checks its conditions and applies its transformation, for example field mapping or log source replacement.Convert the condition (
convert_condition(),finish_query()): the parsed condition is translated recursively into a query.ConversionStatecollects state, andDeferredQueryExpressionholds back parts that are inserted at the end.Postprocess the query (
finalize_query()): the format-specificfinalize_query_<format>method runs, followed by the pipeline’s postprocessing items.Finalize the output (
finalize()): all queries are combined byfinalize_output_<format>and passed through the pipeline’s finalizers.