Post-Processing and Finalization

Post-processing transformations operate on generated query strings, and finalizers operate on the complete set of queries.

Query Post-Processing

class sigma.processing.postprocessing.QueryPostprocessingTransformation[source]

Bases: Transformation

Query post processing transformation base class.

processing_item: 'QueryPostprocessingItem' | None = None
abstractmethod apply(rule, query)[source]

Applies post-processing transformation to arbitrary typed query.

Record the processing item on the rule so later processing_item_applied conditions can match it.

Parameters:
Returns:

Transformed query.

Return type:

Any

__init__()
Return type:

None

class sigma.processing.postprocessing.EmbedQueryTransformation[source]

Bases: QueryPostprocessingTransformation

Embeds a query between a given prefix and suffix. Only applicable to string queries.

prefix: str = ''
suffix: str = ''
apply(rule, query)[source]

Applies post-processing transformation to arbitrary typed query.

Record the processing item on the rule so later processing_item_applied conditions can match it.

Parameters:
Returns:

Transformed query.

Return type:

Any

__init__(prefix='', suffix='')
Parameters:
  • prefix (str)

  • suffix (str)

Return type:

None

class sigma.processing.postprocessing.QuerySimpleTemplateTransformation[source]

Bases: QueryPostprocessingTransformation

Replace query with template that can refer to the following placeholders:

  • query: the postprocessed query.

  • rule: the Sigma rule including all its attributes like rule.title.

  • pipeline: the Sigma processing pipeline where this transformation is applied including all current state information in pipeline.state.

The Python format string syntax (str.format()) is used. Field lookups are sandboxed: access to underscore-prefixed attributes (e.g. __globals__) is denied and format specifications with excessive widths or precisions are rejected.

template: str
apply(rule, query)[source]

Applies post-processing transformation to arbitrary typed query.

Record the processing item on the rule so later processing_item_applied conditions can match it.

Parameters:
Returns:

Transformed query.

Return type:

Any

__init__(template)
Parameters:

template (str)

Return type:

None

class sigma.processing.postprocessing.QueryTemplateTransformation[source]

Bases: QueryPostprocessingTransformation, TemplateBase

Apply Jinja2 template provided as template object variable to a query. The following variables are available in the context:

  • query: the postprocessed query.

  • rule: the Sigma rule including all its attributes like rule.title.

  • pipeline: the Sigma processing pipeline where this transformation is applied including all current state information in pipeline.state.

if path is given, template is considered as a relative path to a template file below the specified path. If it is not provided, the template is specified as plain string. autoescape controls the Jinja2 HTML/XML auto-escaping.

if vars is given, it should point to a Python file containing helper functions and variables to be made available in the Jinja2 template context. See TemplateBase for details on the format.

apply(rule, query)[source]

Applies post-processing transformation to arbitrary typed query.

Record the processing item on the rule so later processing_item_applied conditions can match it.

Parameters:
Returns:

Transformed query.

Return type:

Any

__init__(template, path=None, autoescape=False, vars=None, policy=None, restrict_template_path=False)
Parameters:
  • template (str)

  • path (str | None)

  • autoescape (bool)

  • vars (str | None)

  • policy (SigmaPolicy | None)

  • restrict_template_path (bool)

Return type:

None

class sigma.processing.postprocessing.EmbedQueryInJSONTransformation[source]

Bases: QueryPostprocessingTransformation

Embeds a query into a JSON structure defined as string. the placeholder value %QUERY% is replaced with the query.

json_template: str
apply(rule, query)[source]

Applies post-processing transformation to arbitrary typed query.

Record the processing item on the rule so later processing_item_applied conditions can match it.

Parameters:
Returns:

Transformed query.

Return type:

Any

__init__(json_template)
Parameters:

json_template (str)

Return type:

None

class sigma.processing.postprocessing.ReplaceQueryTransformation[source]

Bases: QueryPostprocessingTransformation

Replace query part specified by regular expression with a given string.

pattern: str
replacement: str
apply(rule, query)[source]

Applies post-processing transformation to arbitrary typed query.

Record the processing item on the rule so later processing_item_applied conditions can match it.

Parameters:
Returns:

Transformed query.

Return type:

Any

__init__(pattern, replacement)
Parameters:
  • pattern (str)

  • replacement (str)

Return type:

None

class sigma.processing.postprocessing.NestedQueryPostprocessingTransformation[source]

Bases: QueryPostprocessingTransformation

Applies a list of query postprocessing transformations to the query in a nested manner.

items: list['QueryPostprocessingItem']
classmethod from_dict(d)[source]
Parameters:

d (dict[str, Any])

Return type:

NestedQueryPostprocessingTransformation

apply(rule, query)[source]

Applies post-processing transformation to arbitrary typed query.

Record the processing item on the rule so later processing_item_applied conditions can match it.

Parameters:
Returns:

Transformed query.

Return type:

Any

__init__(items)
Parameters:

items (list['QueryPostprocessingItem'])

Return type:

None

Finalizers

class sigma.processing.finalization.Finalizer[source]

Bases: object

Conversion output transformation base class.

classmethod from_dict(d)[source]
Parameters:

d (dict[str, Any])

Return type:

Finalizer

set_pipeline(pipeline)[source]
Parameters:

pipeline (ProcessingPipeline)

Return type:

None

abstractmethod apply(queries)[source]

Finalize output by applying a transformation to the list of generated and postprocessed queries.

Parameters:

queries (list[Any]) – List of converted and postprocessed queries that should be finalized.

Returns:

Output that can be used in further processing of the conversion result.

Return type:

Any

__init__()
Return type:

None

class sigma.processing.finalization.ConcatenateQueriesFinalizer[source]

Bases: Finalizer

Concatenate queries with a given separator and embed result within a prefix or suffix string.

separator: str = '\n'
prefix: str = ''
suffix: str = ''
apply(queries)[source]

Finalize output by applying a transformation to the list of generated and postprocessed queries.

Parameters:

queries (list[Any]) – List of converted and postprocessed queries that should be finalized.

Returns:

Output that can be used in further processing of the conversion result.

Return type:

Any

__init__(separator='\n', prefix='', suffix='')
Parameters:
  • separator (str)

  • prefix (str)

  • suffix (str)

Return type:

None

class sigma.processing.finalization.JSONFinalizer[source]

Bases: Finalizer

JSONFinalizer(indent: ‘int | None’ = None)

indent: int | None = None
apply(queries)[source]

Finalize output by applying a transformation to the list of generated and postprocessed queries.

Parameters:

queries (list[Any]) – List of converted and postprocessed queries that should be finalized.

Returns:

Output that can be used in further processing of the conversion result.

Return type:

Any

__init__(indent=None)
Parameters:

indent (int | None)

Return type:

None

class sigma.processing.finalization.YAMLFinalizer[source]

Bases: Finalizer

YAMLFinalizer(indent: ‘int | None’ = None)

indent: int | None = None
apply(queries)[source]

Finalize output by applying a transformation to the list of generated and postprocessed queries.

Parameters:

queries (list[Any]) – List of converted and postprocessed queries that should be finalized.

Returns:

Output that can be used in further processing of the conversion result.

Return type:

Any

__init__(indent=None)
Parameters:

indent (int | None)

Return type:

None

class sigma.processing.finalization.TemplateFinalizer[source]

Bases: Finalizer, TemplateBase

Apply Jinja2 template provided as template object variable to the queries. The following variables are available in the context:

  • queries: all post-processed queries generated by the backend.

  • pipeline: the Sigma processing pipeline where this transformation is applied including all current state information in pipeline.state.

if path is given, template is considered as a relative path to a template file below the specified path. If it is not provided, the template is specified as plain string. autoescape controls the Jinja2 HTML/XML auto-escaping.

if vars is given, it should point to a Python file containing helper functions and variables to be made available in the Jinja2 template context. See TemplateBase for details on the format.

apply(queries)[source]

Finalize output by applying a transformation to the list of generated and postprocessed queries.

Parameters:

queries (list[Any]) – List of converted and postprocessed queries that should be finalized.

Returns:

Output that can be used in further processing of the conversion result.

Return type:

Any

__init__(template, path=None, autoescape=False, vars=None, policy=None, restrict_template_path=False)
Parameters:
  • template (str)

  • path (str | None)

  • autoescape (bool)

  • vars (str | None)

  • policy (SigmaPolicy | None)

  • restrict_template_path (bool)

Return type:

None

class sigma.processing.finalization.NestedFinalizer[source]

Bases: Finalizer

Apply a list of finalizers to the queries in a nested fashion.

finalizers: list[Finalizer]
classmethod from_dict(d, policy=None)[source]
Parameters:
Return type:

NestedFinalizer

apply(queries)[source]

Finalize output by applying a transformation to the list of generated and postprocessed queries.

Parameters:

queries (list[Any]) – List of converted and postprocessed queries that should be finalized.

Returns:

Output that can be used in further processing of the conversion result.

Return type:

Any

__init__(finalizers)
Parameters:

finalizers (list[Finalizer])

Return type:

None