Transformations¶
Transformations modify Sigma rules during pipeline processing.
Base Classes¶
- class sigma.processing.transformations.base.Transformation[source]¶
Bases:
ProcessingRegularExpressionMixin,ABCBase class for processing steps used in pipelines. Override apply with transformation that is applied to the whole rule.
- processing_item: 'ProcessingItemBase' | None = None¶
- set_pipeline(pipeline)[source]¶
- Parameters:
pipeline (ProcessingPipeline)
- Return type:
None
- set_processing_item(processing_item)[source]¶
- Parameters:
processing_item (ProcessingItemBase)
- Return type:
None
- processing_item_applied(d)[source]¶
Mark detection item or detection as applied.
- Parameters:
d (SigmaRule | SigmaDetection | SigmaDetectionItem | 'SigmaCondition' | SigmaCorrelationRule)
- Return type:
None
- __init__()¶
- Return type:
None
- class sigma.processing.transformations.base.PreprocessingTransformation[source]¶
Bases:
Transformation,ABCIntermediate base class for preprocessing transformations.
- abstractmethod apply(rule)[source]¶
Apply transformation on Sigma rule.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
None
- __init__()¶
- Return type:
None
- class sigma.processing.transformations.base.DetectionItemTransformation[source]¶
Bases:
PreprocessingTransformationIterates over all detection items of a Sigma rule and calls the apply_detection_item method for each of them if the detection item condition associated with the processing item evaluates to true. It also takes care to recurse into detections nested into detections.
The apply_detection_item method can directly change the detection or return a replacement object, which can be a SigmaDetection or a SigmaDetectionItem.
The processing item is automatically added to the applied items of the detection items if a replacement value was returned. In the other case the apply_detection_item method must take care of this to make conditional decisions in the processing pipeline working. This can be done with the detection_item_applied() method.
A detection item transformation also marks the item as unconvertible to plain data types.
- processing_item: 'ProcessingItem' | None = None¶
- abstractmethod apply_detection_item(detection_item)[source]¶
Apply transformation on detection item.
- Parameters:
detection_item (SigmaDetectionItem)
- Return type:
SigmaDetection | SigmaDetectionItem | None
- apply_detection(detection)[source]¶
- Parameters:
detection (SigmaDetection)
- Return type:
None
- apply(rule)[source]¶
Apply transformation on Sigma rule.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
None
- __init__()¶
- Return type:
None
- class sigma.processing.transformations.base.FieldMappingTransformationBase[source]¶
Bases:
DetectionItemTransformationTransformation that is applied to detection items and additionally the field list of a Sigma rule.
- strict: bool = False¶
- abstractmethod apply_field_name(field)[source]¶
Map a field name to one or multiple field names. The result is used in detection items, references as well as in the field list of the Sigma rule. If the result is None, the field name is passed through unchanged (unless strict mode is enabled). If the result is an empty list, the field name is dropped from the transformed result.
- Parameters:
field (str | None)
- Return type:
None | str | list[str]
- apply_detection(detection)[source]¶
- Parameters:
detection (SigmaDetection)
- Return type:
None
- apply(rule)[source]¶
Apply field name transformations to Sigma rule field names listed in ‘fields’ attribute.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
None
- apply_detection_item(detection_item)[source]¶
Apply field name transformations to field references in detection item values.
- Parameters:
detection_item (SigmaDetectionItem)
- Return type:
SigmaDetection | SigmaDetectionItem | None
- __init__(*, strict=False)¶
- Parameters:
strict (bool)
- Return type:
None
- class sigma.processing.transformations.base.ValueTransformation[source]¶
Bases:
DetectionItemTransformationIterates over all values in all detection items of a Sigma rule and call apply_value method for each of them. The apply_value method can return a single value or a list of values which are inserted into the value list or None if the original value should be passed through. An empty list should be returned by apply_value to drop the value from the transformed results.
- apply_detection_item(detection_item)[source]¶
Call apply_value for each value and integrate results into value list.
- Parameters:
detection_item (SigmaDetectionItem)
- Return type:
SigmaDetectionItem | None
- apply_detection(detection)[source]¶
- Parameters:
detection (SigmaDetection)
- Return type:
None
- abstractmethod apply_value(field, val)[source]¶
Perform a value transformation. This method can return:
None to drop the value
a single SigmaType object which replaces the original value.
an iterable of SigmaType objects. These objects are used as replacement for the original value.
The type annotation of the val argument is used to skip incompatible values.
- __init__()¶
- Return type:
None
- class sigma.processing.transformations.base.StringValueTransformation[source]¶
Bases:
ValueTransformationBase class for transformations that operate on SigmaString values.
- apply_value(field, val)[source]¶
Perform a value transformation. This method can return:
None to drop the value
a single SigmaType object which replaces the original value.
an iterable of SigmaType objects. These objects are used as replacement for the original value.
The type annotation of the val argument is used to skip incompatible values.
- abstractmethod apply_string_value(field, val)[source]¶
Perform a value transformation. This method can return:
None to drop the value
a single SigmaType object which replaces the original value.
a list of SigmaType objects. These objects are used as replacement for the original value.
- Parameters:
field (str | None)
val (SigmaString)
- Return type:
- class sigma.processing.transformations.base.ConditionTransformation[source]¶
Bases:
PreprocessingTransformationIterates over all rule conditions and calls the apply_condition method for each condition. Automatically takes care of marking condition as applied by processing item.
- apply(rule)[source]¶
Apply transformation on Sigma rule.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
None
- abstractmethod apply_condition(cond)[source]¶
This method is invoked for each condition and can change it.
- Parameters:
cond (SigmaCondition)
- Return type:
None
- __init__()¶
- Return type:
None
Field Transformations¶
- class sigma.processing.transformations.fields.FieldMappingTransformation[source]¶
Bases:
FieldMappingTransformationBaseMap a field name to one or multiple different.
- mapping: dict[str | None, str | list[str]]¶
- apply_field_name(field)[source]¶
Map a field name to one or multiple field names. The result is used in detection items, references as well as in the field list of the Sigma rule. If the result is None, the field name is passed through unchanged (unless strict mode is enabled). If the result is an empty list, the field name is dropped from the transformed result.
- Parameters:
field (str | None)
- Return type:
None | str | list[str]
- __init__(mapping, *, strict=False)¶
- Parameters:
mapping (dict[str | None, str | list[str]])
strict (bool)
- Return type:
None
- class sigma.processing.transformations.fields.FieldPrefixMappingTransformation[source]¶
Bases:
FieldMappingTransformationMap a field name prefix to one or multiple different prefixes.
- apply_field_name(field)[source]¶
Map a field name to one or multiple field names. The result is used in detection items, references as well as in the field list of the Sigma rule. If the result is None, the field name is passed through unchanged (unless strict mode is enabled). If the result is an empty list, the field name is dropped from the transformed result.
- Parameters:
field (str | None)
- Return type:
None | str | list[str]
- __init__(mapping, *, strict=False)¶
- Parameters:
mapping (dict[str | None, str | list[str]])
strict (bool)
- Return type:
None
- class sigma.processing.transformations.fields.FieldFunctionTransformation[source]¶
Bases:
FieldMappingTransformationMap a field name to another using provided transformation function. An explicit mapping overrides the function, which is only called for unmapped fields.
- transform_func: Callable[[str | None], str]¶
- apply_keyword: bool = False¶
- apply_field_name(field)[source]¶
Map a field name to one or multiple field names. The result is used in detection items, references as well as in the field list of the Sigma rule. If the result is None, the field name is passed through unchanged (unless strict mode is enabled). If the result is an empty list, the field name is dropped from the transformed result.
- Parameters:
field (str | None)
- Return type:
None | str | list[str]
- __init__(mapping, transform_func, apply_keyword=False, *, strict=False)¶
- Parameters:
mapping (dict[str | None, str | list[str]])
transform_func (Callable[[str | None], str])
apply_keyword (bool)
strict (bool)
- Return type:
None
- class sigma.processing.transformations.fields.AddFieldnameSuffixTransformation[source]¶
Bases:
FieldMappingTransformationBaseAdd field name suffix.
- suffix: str¶
- apply_field_name(field)[source]¶
Map a field name to one or multiple field names. The result is used in detection items, references as well as in the field list of the Sigma rule. If the result is None, the field name is passed through unchanged (unless strict mode is enabled). If the result is an empty list, the field name is dropped from the transformed result.
- Parameters:
field (str | None)
- Return type:
str | None
- __init__(suffix, *, strict=False)¶
- Parameters:
suffix (str)
strict (bool)
- Return type:
None
- class sigma.processing.transformations.fields.AddFieldnamePrefixTransformation[source]¶
Bases:
FieldMappingTransformationBaseAdd field name prefix.
- prefix: str¶
- apply_field_name(field)[source]¶
Map a field name to one or multiple field names. The result is used in detection items, references as well as in the field list of the Sigma rule. If the result is None, the field name is passed through unchanged (unless strict mode is enabled). If the result is an empty list, the field name is dropped from the transformed result.
- Parameters:
field (str | None)
- Return type:
str | None
- __init__(prefix, *, strict=False)¶
- Parameters:
prefix (str)
strict (bool)
- Return type:
None
- class sigma.processing.transformations.fields.AddFieldTransformation[source]¶
Bases:
PreprocessingTransformationAdd one or multiple fields to the Sigma rule. The field is added to the fields list of the rule:
- field: str | list[str]¶
- apply(rule)[source]¶
Apply transformation on Sigma rule.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
None
- __init__(field)¶
- Parameters:
field (str | list[str])
- Return type:
None
- class sigma.processing.transformations.fields.RemoveFieldTransformation[source]¶
Bases:
PreprocessingTransformationRemove one or multiple fields from the Sigma rules field list. If a given field is not in the rules list, it is ignored.
- field: str | list[str]¶
- apply(rule)[source]¶
Apply transformation on Sigma rule.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
None
- __init__(field)¶
- Parameters:
field (str | list[str])
- Return type:
None
- class sigma.processing.transformations.fields.SetFieldTransformation[source]¶
Bases:
PreprocessingTransformationSet fields to the Sigma rule. The fields are set to the fields list of the transformation.
- fields: list[str]¶
- apply(rule)[source]¶
Apply transformation on Sigma rule.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
None
- __init__(fields)¶
- Parameters:
fields (list[str])
- Return type:
None
Value Transformations¶
- class sigma.processing.transformations.values.HashesFieldsDetectionItemTransformation[source]¶
Bases:
DetectionItemTransformationTransforms the ‘Hashes’ field in Sigma rules by creating separate detection items for each hash type.
This transformation replaces the generic ‘Hashes’ field with specific fields for each hash algorithm, optionally prefixing the field names. It supports various hash formats and can auto-detect hash types based on their length.
- valid_hash_algos¶
List of supported hash algorithms.
- Type:
list[str]
- field_prefix¶
Prefix to add to the new field names.
- Type:
str
- drop_algo_prefix¶
If True, omits the algorithm name from the new field name.
- Type:
bool
- field_to_parse¶
List of field names to parse for hash values. Defaults to [“Hashes”, “Hash”].
- Type:
list[str]
- hash_lengths¶
Mapping of hash lengths to their corresponding algorithms.
- Type:
dict[int, str]
Example
- Input:
- Hashes:
‘SHA1=5F1CBC3D99558307BC1250D084FA968521482025’
‘MD5=987B65CD9B9F4E9A1AFD8F8B48CF64A7’
- Output:
FileSHA1: ‘5F1CBC3D99558307BC1250D084FA968521482025’ FileMD5: ‘987B65CD9B9F4E9A1AFD8F8B48CF64A7’
- valid_hash_algos: list[str]¶
- field_prefix: str = ''¶
- drop_algo_prefix: bool = False¶
- field_to_parse: list[str]¶
- hash_lengths: ClassVar[dict[int, str]] = {32: 'MD5', 40: 'SHA1', 64: 'SHA256', 128: 'SHA512'}¶
- apply_detection_item(detection_item)[source]¶
Applies the transformation to a single detection item.
- Parameters:
detection_item (SigmaDetectionItem) – The detection item to transform.
- Returns:
A new SigmaDetection object containing the transformed detection items, or None if no valid hashes were found.
- Return type:
(SigmaDetection | SigmaDetectionItem) | None
- Raises:
Exception – If no valid hash algorithms were found in the detection item.
- __init__(valid_hash_algos, field_prefix='', drop_algo_prefix=False, field_to_parse=<factory>)¶
- Parameters:
valid_hash_algos (list[str])
field_prefix (str)
drop_algo_prefix (bool)
field_to_parse (list[str])
- Return type:
None
- class sigma.processing.transformations.values.ReplaceStringTransformation[source]¶
Bases:
StringValueTransformationReplace string part matched by regular expresssion with replacement string that can reference capture groups. Normally, the replacement operates on the plain string representation of the SigmaString. This allows also to include special characters and placeholders in the replacement. By enabling the skip_special parameter, the replacement is only applied to the plain string parts of a SigmaString and special characters and placeholders are left untouched. The interpret_special option determines for skip_special if special characters and placeholders are interpreted in the replacement result or not.
The replacement is implemented with re.sub() and can use all features available there.
- regex: str¶
- replacement: str¶
- skip_special: bool = False¶
- interpret_special: bool = False¶
- apply_value(field, val)[source]¶
Perform a value transformation. This method can return:
None to drop the value
a single SigmaType object which replaces the original value.
an iterable of SigmaType objects. These objects are used as replacement for the original value.
The type annotation of the val argument is used to skip incompatible values.
- apply_string_value(field, val)[source]¶
Perform a value transformation. This method can return:
None to drop the value
a single SigmaType object which replaces the original value.
a list of SigmaType objects. These objects are used as replacement for the original value.
- Parameters:
field (str | None)
val (SigmaString)
- Return type:
- __init__(regex, replacement, skip_special=False, interpret_special=False)¶
- Parameters:
regex (str)
replacement (str)
skip_special (bool)
interpret_special (bool)
- Return type:
None
- class sigma.processing.transformations.values.MapStringTransformation[source]¶
Bases:
StringValueTransformationMap static string value to one or multiple other strings.
- mapping: dict[str, str | list[str]]¶
- apply_string_value(field, val)[source]¶
Perform a value transformation. This method can return:
None to drop the value
a single SigmaType object which replaces the original value.
a list of SigmaType objects. These objects are used as replacement for the original value.
- Parameters:
field (str | None)
val (SigmaString)
- Return type:
- __init__(mapping)¶
- Parameters:
mapping (dict[str, str | list[str]])
- Return type:
None
- class sigma.processing.transformations.values.RegexTransformation[source]¶
Bases:
StringValueTransformationTransform a string value to a case insensitive regular expression. The following methods are available and can be selected with the method parameter:
plain: Convert the string to a regular expression without any change to its case. In most cases this should result in a case-sensitive match of the string.
case_insensitive_flag: Add the case insensitive flag to the regular expression.
case_insensitive_brackets (default): Wrap each character in a bracket expression like [aA] to match both case variants.
This transformation is intended to be used to emulate case insensitive matching in backends that don’t support it natively.
- method: Literal['plain', 'ignore_case_flag', 'ignore_case_brackets'] = 'ignore_case_brackets'¶
- apply_string_value(field, val)[source]¶
Perform a value transformation. This method can return:
None to drop the value
a single SigmaType object which replaces the original value.
a list of SigmaType objects. These objects are used as replacement for the original value.
- Parameters:
field (str | None)
val (SigmaString)
- Return type:
SigmaType | None
- __init__(method='ignore_case_brackets')¶
- Parameters:
method (Literal['plain', 'ignore_case_flag', 'ignore_case_brackets'])
- Return type:
None
- class sigma.processing.transformations.values.SetValueTransformation[source]¶
Bases:
ValueTransformationSet value to a fixed value. The type of the value can be enforced to str or num with the force_type parameter.
- value: dataclasses.InitVar[str | int | float | bool | None]¶
- force_type: Literal['str', 'num'] | None = None¶
- apply_value(field, val)[source]¶
Perform a value transformation. This method can return:
None to drop the value
a single SigmaType object which replaces the original value.
an iterable of SigmaType objects. These objects are used as replacement for the original value.
The type annotation of the val argument is used to skip incompatible values.
- __init__(value, force_type=None)¶
- Parameters:
value (dataclasses.InitVar[str | int | float | bool | None])
force_type (Literal['str', 'num'] | None)
- Return type:
None
- class sigma.processing.transformations.values.ConvertTypeTransformation[source]¶
Bases:
ValueTransformationConvert type of value. The conversion into strings and numbers is currently supported.
- target_type: Literal['str', 'num']¶
- apply_value(field, val)[source]¶
Perform a value transformation. This method can return:
None to drop the value
a single SigmaType object which replaces the original value.
an iterable of SigmaType objects. These objects are used as replacement for the original value.
The type annotation of the val argument is used to skip incompatible values.
- Parameters:
field (str | None)
val (SigmaType)
- Return type:
SigmaString | SigmaNumber | SigmaExpansion | None
- __init__(target_type)¶
- Parameters:
target_type (Literal['str', 'num'])
- Return type:
None
- class sigma.processing.transformations.values.CaseTransformation[source]¶
Bases:
StringValueTransformationTransform a string value to a lower or upper or snake case.
- method: Literal['lower', 'upper', 'snake_case'] = 'lower'¶
- apply_string_value(field, val)[source]¶
Perform a value transformation. This method can return:
None to drop the value
a single SigmaType object which replaces the original value.
a list of SigmaType objects. These objects are used as replacement for the original value.
- Parameters:
field (str | None)
val (SigmaString)
- Return type:
SigmaString | None
- __init__(method='lower')¶
- Parameters:
method (Literal['lower', 'upper', 'snake_case'])
- Return type:
None
- class sigma.processing.transformations.values.ExtractFieldsTransformation[source]¶
Bases:
DetectionItemTransformationTransforms values matching a regex pattern with named groups into separate detection items.
Extracts named capture groups from a regex match and creates one detection item per group. Each item uses the field prefix followed by the group name: - {field_prefix}.{group_name}: captured value
Example
regex = r”(?P<type>[A-Za-z]+):(?P<valeur>[0-9]+)” field_prefix = “reg” Input: reg: “Dword:00001” Output: reg.type: “Dword”, reg.valeur: “00001”
Multiple values are each transformed independently. Each value’s extracted fields are AND-linked within a nested SigmaDetection, and the outer linking follows the detection item’s value_linking (default OR).
The regex pattern must contain at least one named group. Groups without names are ignored.
Type conversion for captured values: - “null”, “none”, or empty string -> SigmaNull - Integer strings (without leading zeros, except “0”) -> SigmaNumber(int) - Float strings (without leading zeros) -> SigmaNumber(float) - All other strings -> SigmaString
Strings with leading zeros (e.g., “00001”, “03.14”) are preserved as SigmaString to avoid losing the leading zero information.
To restrict this transformation to specific fields, use the
IncludeFieldConditionin the processing item’s field_name_conditions instead of a field list attribute on the transformation.- regex¶
Regex pattern with named groups (e.g., (?P<name>pattern)).
- Type:
str
- field_prefix¶
Prefix for field names. Used as {field_prefix}.{group_name}. If None, only the group name is used as the field name.
- Type:
str | None
- preserve_unmatched¶
If True, values that don’t match the regex are preserved as-is in the original field. If False (default), non-matching values are dropped.
- Type:
bool
- regex: str¶
- field_prefix: str | None = None¶
- preserve_unmatched: bool = False¶
- apply_detection_item(detection_item)[source]¶
Apply transformation on detection item.
- Parameters:
detection_item (SigmaDetectionItem)
- Return type:
SigmaDetection | None
- __init__(regex, field_prefix=None, preserve_unmatched=False)¶
- Parameters:
regex (str)
field_prefix (str | None)
preserve_unmatched (bool)
- Return type:
None
Condition Transformations¶
- class sigma.processing.transformations.condition.AddConditionTransformation[source]¶
Bases:
ConditionTransformationAdd a condition expression to rule conditions.
If template is set to True the condition values are interpreted as string templates and the following placeholders are replaced:
$category, $product and $service: with the corresponding values of the Sigma rule log source.
- conditions: dict[str, int | str | list[str]]¶
- name: str¶
- template: bool = False¶
- negated: bool = False¶
- apply(rule)[source]¶
Apply transformation on Sigma rule.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
None
- apply_condition(cond)[source]¶
This method is invoked for each condition and can change it.
- Parameters:
cond (SigmaCondition)
- Return type:
None
- __init__(conditions=<factory>, name=<factory>, template=False, negated=False)¶
- Parameters:
conditions (dict[str, int | str | list[str]])
name (str)
template (bool)
negated (bool)
- Return type:
None
Detection Item Transformations¶
- class sigma.processing.transformations.detection_item.DeleteSigmaDetectionItem[source]¶
Bases:
SigmaDetectionItemClass is used to mark detection item as to be deleted. It’s just for having all the detection item functionality available.
- class sigma.processing.transformations.detection_item.DropDetectionItemTransformation[source]¶
Bases:
DetectionItemTransformationDeletes detection items. This should only used in combination with a detection item condition.
- apply_detection_item(detection_item)[source]¶
This function only marks detection items for deletion.
- Parameters:
detection_item (SigmaDetectionItem)
- Return type:
SigmaDetectionItem | None
- apply_detection(detection)[source]¶
- Parameters:
detection (SigmaDetection)
- Return type:
None
- __init__()¶
- Return type:
None
Rule Transformations¶
- class sigma.processing.transformations.rule.ChangeLogsourceTransformation[source]¶
Bases:
PreprocessingTransformationReplace log source as defined in transformation parameters.
- category: str | None = None¶
- product: str | None = None¶
- service: str | None = None¶
- apply(rule)[source]¶
Apply transformation on Sigma rule.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
None
- __init__(category=None, product=None, service=None)¶
- Parameters:
category (str | None)
product (str | None)
service (str | None)
- Return type:
None
- class sigma.processing.transformations.rule.SetCustomAttributeTransformation[source]¶
Bases:
PreprocessingTransformationSets an arbitrary custom attribute on a rule, that can be used by a backend during processing.
- attribute: str¶
- value: Any¶
- apply(rule)[source]¶
Apply transformation on Sigma rule.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
None
- __init__(attribute, value)¶
- Parameters:
attribute (str)
value (Any)
- Return type:
None
State Transformations¶
- class sigma.processing.transformations.state.SetStateTransformation[source]¶
Bases:
PreprocessingTransformationSet pipeline state key to value.
- key: str¶
- val: Any¶
- apply(rule)[source]¶
Apply transformation on Sigma rule.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
None
- __init__(key, val)¶
- Parameters:
key (str)
val (Any)
- Return type:
None
Placeholder Transformations¶
- class sigma.processing.transformations.placeholder.PlaceholderIncludeExcludeMixin[source]¶
Bases:
objectPlaceholderIncludeExcludeMixin(include: list[str] | None = None, exclude: list[str] | None = None)
- include: list[str] | None = None¶
- exclude: list[str] | None = None¶
- __init__(include=None, exclude=None)¶
- Parameters:
include (list[str] | None)
exclude (list[str] | None)
- Return type:
None
- class sigma.processing.transformations.placeholder.BasePlaceholderTransformation[source]¶
Bases:
ValueTransformation,PlaceholderIncludeExcludeMixinPlaceholder base transformation. The parameters include and exclude can contain variable names that are handled by this transformation. Unhandled placeholders are left as they are and must be handled by later transformations.
- apply_value(field, val)[source]¶
Perform a value transformation. This method can return:
None to drop the value
a single SigmaType object which replaces the original value.
an iterable of SigmaType objects. These objects are used as replacement for the original value.
The type annotation of the val argument is used to skip incompatible values.
- Parameters:
field (str | None)
val (SigmaType)
- Return type:
None | SigmaString | Iterable[SigmaString] | SigmaRegularExpression | Iterable[SigmaRegularExpression]
- placeholder_replacements_base(p)[source]¶
Base placeholder replacement callback. Calls real callback if placeholder is included or not excluded, else it passes the placeholder back to caller.
- Parameters:
p (Placeholder)
- Return type:
Iterator[str | SpecialChars | Placeholder | SigmaString]
- abstractmethod placeholder_replacements(p)[source]¶
Placeholder replacement callback used by SigmaString.replace_placeholders(). This must return one of the following object types:
Plain strings
SpecialChars instances for insertion of wildcards
Placeholder instances, it may even return the same placeholder. These must be handled by following processing pipeline items or the backend or the conversion will fail.
SigmaString instances, these are used to replace the placeholder with a SigmaString that may contain plain strings, placeholders and special characters.
- Parameters:
p (Placeholder)
- Return type:
Iterable[str | SpecialChars | Placeholder | SigmaString]
- __init__(include=None, exclude=None)¶
- Parameters:
include (list[str] | None)
exclude (list[str] | None)
- Return type:
None
- class sigma.processing.transformations.placeholder.WildcardPlaceholderTransformation[source]¶
Bases:
BasePlaceholderTransformationReplaces placeholders with wildcards. This transformation is useful if remaining placeholders should be replaced with something meaningful to make conversion of rules possible without defining the placeholders content.
- placeholder_replacements(p)[source]¶
Placeholder replacement callback used by SigmaString.replace_placeholders(). This must return one of the following object types:
Plain strings
SpecialChars instances for insertion of wildcards
Placeholder instances, it may even return the same placeholder. These must be handled by following processing pipeline items or the backend or the conversion will fail.
SigmaString instances, these are used to replace the placeholder with a SigmaString that may contain plain strings, placeholders and special characters.
- Parameters:
p (Placeholder)
- Return type:
Iterable[SpecialChars]
- __init__(include=None, exclude=None)¶
- Parameters:
include (list[str] | None)
exclude (list[str] | None)
- Return type:
None
- class sigma.processing.transformations.placeholder.ValueListPlaceholderTransformation[source]¶
Bases:
BasePlaceholderTransformationReplaces placeholders with values contained in variables defined in the configuration.
- placeholder_replacements(p)[source]¶
Placeholder replacement callback used by SigmaString.replace_placeholders(). This must return one of the following object types:
Plain strings
SpecialChars instances for insertion of wildcards
Placeholder instances, it may even return the same placeholder. These must be handled by following processing pipeline items or the backend or the conversion will fail.
SigmaString instances, these are used to replace the placeholder with a SigmaString that may contain plain strings, placeholders and special characters.
- Parameters:
p (Placeholder)
- Return type:
Iterable[SigmaString]
- __init__(include=None, exclude=None)¶
- Parameters:
include (list[str] | None)
exclude (list[str] | None)
- Return type:
None
- class sigma.processing.transformations.placeholder.QueryExpressionPlaceholderTransformation[source]¶
Bases:
StringValueTransformation,PlaceholderIncludeExcludeMixinReplaces a placeholder with a plain query containing the placeholder or an identifier mapped from the placeholder name. The main purpose is the generation of arbitrary list lookup expressions which are passed to the resulting query.
Parameters: * expression: string that contains query expression with {field} and {id} placeholder where placeholder identifier or a mapped identifier is inserted. * mapping: Mapping between placeholders and identifiers that should be used in the expression. If no mapping is provided the placeholder name is used. In this case the placeholder name is inserted into the expression unchanged and must therefore only consist of letters, digits, ‘_’, ‘.’ and ‘-’, otherwise a SigmaValueError is raised.
- expression: str = ''¶
- mapping: dict[str, str]¶
- unmapped_name_pattern: ClassVar[Pattern[str]] = re.compile('[A-Za-z0-9_.\\-]+')¶
- apply_string_value(field, val)[source]¶
Perform a value transformation. This method can return:
None to drop the value
a single SigmaType object which replaces the original value.
a list of SigmaType objects. These objects are used as replacement for the original value.
- Parameters:
field (str | None)
val (SigmaString)
- Return type:
SigmaType | None
- __init__(include=None, exclude=None, expression='', mapping=<factory>)¶
- Parameters:
include (list[str] | None)
exclude (list[str] | None)
expression (str)
mapping (dict[str, str])
- Return type:
None
Failure Transformations¶
- class sigma.processing.transformations.failure.RuleFailureTransformation[source]¶
Bases:
PreprocessingTransformationRaise a SigmaTransformationError with the provided message. This enables transformation pipelines to signalize that a certain situation can’t be handled, e.g. only a subset of values is allowed because the target data model doesn’t offers all possibilities.
This is a rule transformation. Detection item and field name conditions are not evaluated if this is used.
- message: str¶
- apply(rule)[source]¶
Apply transformation on Sigma rule.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
None
- __init__(message)¶
- Parameters:
message (str)
- Return type:
None
- class sigma.processing.transformations.failure.DetectionItemFailureTransformation[source]¶
Bases:
DetectionItemTransformationRaise a SigmaTransformationError with the provided message. This enables transformation pipelines to signalize that a certain situation can’t be handled, e.g. only a subset of values is allowed because the target data model doesn’t offers all possibilities.
This is a detection item transformation that should be used if detection item or field name conditions are used.
- message: str¶
- apply_detection_item(detection_item)[source]¶
Apply transformation on detection item.
- Parameters:
detection_item (SigmaDetectionItem)
- Return type:
None
- __init__(message)¶
- Parameters:
message (str)
- Return type:
None
- class sigma.processing.transformations.failure.StrictFieldMappingFailure[source]¶
Bases:
PreprocessingTransformationStrictFieldMappingFailure()
- message = 'The field mapping is not strict. Please check the field mapping in the configuration file.'¶
- apply(rule)[source]¶
Apply transformation on Sigma rule.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
None
- __init__()¶
- Return type:
None
Meta Transformations¶
- class sigma.processing.transformations.meta.NestedProcessingTransformation[source]¶
Bases:
PreprocessingTransformationExecutes a nested processing pipeline as transformation. Main purpose is to apply a whole set of transformations that match the given conditions of the enclosng processing item.
- items: InitVar[list[dict[str, Any] | 'ProcessingItem']]¶
- apply(rule)[source]¶
Apply transformation on Sigma rule.
- Parameters:
rule (SigmaRule | SigmaCorrelationRule)
- Return type:
None
- __init__(items)¶
- Parameters:
items (InitVar[list[dict[str, Any] | 'ProcessingItem']])
- Return type:
None
External Source Transformations¶
External data source placeholder transformations.
These transformations replace Sigma placeholders with values fetched from external sources such as local files, HTTP endpoints, or command output.
Security note: Because these transformations access external sources, they are disabled by
default and must be explicitly enabled by using a
SigmaPolicy with allow_external_sources=True when loading a
ProcessingPipeline or by setting the
environment variable PYSIGMA_ALLOW_EXTERNAL_SOURCES=1.
- class sigma.processing.transformations.external.ExternalSourceBaseTransformation[source]¶
Bases:
BasePlaceholderTransformationBase class for placeholder transformations that fetch replacement values from an external source (file, HTTP, command).
Supported formats (controlled by the format parameter):
"plaintext"— one value per line."csv"— CSV data; csv_column selects the column (column header name or 0-based integer index); csv_has_header (defaultTrue) controls whether the first row is treated as a header."json"— JSON data; jq_expression selects the value(s)."yaml"— YAML data; jq_expression selects the value(s).
An optional filter regex is applied to every extracted value after parsing, regardless of format; only values that match (via
re.search()) are kept. Values that do not match are silently dropped. An invalid regex pattern raisesSigmaConfigurationErrorat pipeline-load time.Security: external-source transformations are disabled by default. Enable them by setting
allow_external_sources=Truein theSigmaPolicyused for the pipeline or by setting the environment variablePYSIGMA_ALLOW_EXTERNAL_SOURCES=1.- format: str = 'plaintext'¶
- filter: str | None = None¶
- csv_column: str | int | None = None¶
- csv_has_header: bool = True¶
- jq_expression: str | None = None¶
- policy: SigmaPolicy | None = None¶
- placeholder_replacements(p)[source]¶
Placeholder replacement callback used by SigmaString.replace_placeholders(). This must return one of the following object types:
Plain strings
SpecialChars instances for insertion of wildcards
Placeholder instances, it may even return the same placeholder. These must be handled by following processing pipeline items or the backend or the conversion will fail.
SigmaString instances, these are used to replace the placeholder with a SigmaString that may contain plain strings, placeholders and special characters.
- Parameters:
p (Placeholder)
- Return type:
Iterable[SigmaString]
- __init__(include=None, exclude=None, format='plaintext', filter=None, csv_column=None, csv_has_header=True, jq_expression=None, policy=None)¶
- Parameters:
include (list[str] | None)
exclude (list[str] | None)
format (str)
filter (str | None)
csv_column (str | int | None)
csv_has_header (bool)
jq_expression (str | None)
policy (SigmaPolicy | None)
- Return type:
None
- class sigma.processing.transformations.external.FilePlaceholderTransformation[source]¶
Bases:
ExternalSourceBaseTransformationReplace placeholders with values read from a local file.
- Parameters:
path (str) – Path to the file (required).
format (str) – Data format:
"plaintext"(default),"csv","json","yaml".filter (str, optional) – Regex; only extracted values that match are kept (all formats).
csv_column (str or int, optional) – Column name (str) or 0-based index (int) for CSV format.
csv_has_header (bool) – Whether the first CSV row is a header (default
True).jq_expression (str, optional) – Path expression for JSON/YAML formats (e.g.
.items[]).include (list, optional) – Placeholder name inclusion list.
exclude (list, optional) – Placeholder name exclusion list.
- path: str = ''¶
- __init__(include=None, exclude=None, format='plaintext', filter=None, csv_column=None, csv_has_header=True, jq_expression=None, policy=None, path='')¶
- Parameters:
include (list[str] | None)
exclude (list[str] | None)
format (str)
filter (str | None)
csv_column (str | int | None)
csv_has_header (bool)
jq_expression (str | None)
policy (SigmaPolicy | None)
path (str)
- Return type:
None
- class sigma.processing.transformations.external.HTTPPlaceholderTransformation[source]¶
Bases:
ExternalSourceBaseTransformationReplace placeholders with values fetched from an HTTP(S) endpoint.
- Parameters:
url (str) – URL to fetch (required).
method (str) – HTTP method (default:
"GET").timeout (int) – Request timeout in seconds (default: 10).
headers (dict, optional) – Custom HTTP request headers.
params (dict, optional) – URL query parameters.
form_data (dict, optional) – Form-encoded request body (
application/x-www-form-urlencoded).json_body (dict, optional) – JSON request body (
application/json).max_body_size (int) – Maximum response body size in bytes (default 10 MiB).
format (str) – Data format:
"plaintext"(default),"csv","json","yaml".filter (str, optional) – Regex; only extracted values that match are kept (all formats).
csv_column (str or int, optional) – Column name (str) or 0-based index (int) for CSV format.
csv_has_header (bool) – Whether the first CSV row is a header (default
True).jq_expression (str, optional) – Path expression for JSON/YAML formats.
include (list, optional) – Placeholder name inclusion list.
exclude (list, optional) – Placeholder name exclusion list.
- url: str = ''¶
- method: str = 'GET'¶
- timeout: int = 10¶
- headers: dict[str, str] | None = None¶
- params: dict[str, str] | None = None¶
- form_data: dict[str, Any] | None = None¶
- json_body: dict[str, Any] | None = None¶
- max_body_size: int = 10485760¶
- __init__(include=None, exclude=None, format='plaintext', filter=None, csv_column=None, csv_has_header=True, jq_expression=None, policy=None, url='', method='GET', timeout=10, headers=None, params=None, form_data=None, json_body=None, max_body_size=10485760)¶
- Parameters:
include (list[str] | None)
exclude (list[str] | None)
format (str)
filter (str | None)
csv_column (str | int | None)
csv_has_header (bool)
jq_expression (str | None)
policy (SigmaPolicy | None)
url (str)
method (str)
timeout (int)
headers (dict[str, str] | None)
params (dict[str, str] | None)
form_data (dict[str, Any] | None)
json_body (dict[str, Any] | None)
max_body_size (int)
- Return type:
None
- class sigma.processing.transformations.external.CommandPlaceholderTransformation[source]¶
Bases:
ExternalSourceBaseTransformationReplace placeholders with the stdout output of a shell command.
- Parameters:
cmd (str or list) – Command string (passed to
/bin/sh -c) or a list of arguments (required).timeout (int) – Maximum execution time in seconds (default: 30).
max_stdout (int) – Maximum accepted stdout size in bytes (default 10 MiB).
format (str) – Data format:
"plaintext"(default),"csv","json","yaml".filter (str, optional) – Regex; only extracted values that match are kept (all formats).
csv_column (str or int, optional) – Column name (str) or 0-based index (int) for CSV format.
csv_has_header (bool) – Whether the first CSV row is a header (default
True).jq_expression (str, optional) – Path expression for JSON/YAML formats.
include (list, optional) – Placeholder name inclusion list.
exclude (list, optional) – Placeholder name exclusion list.
- cmd: str | list[str] = ''¶
- timeout: int = 30¶
- max_stdout: int = 10485760¶
- __init__(include=None, exclude=None, format='plaintext', filter=None, csv_column=None, csv_has_header=True, jq_expression=None, policy=None, cmd='', timeout=30, max_stdout=10485760)¶
- Parameters:
include (list[str] | None)
exclude (list[str] | None)
format (str)
filter (str | None)
csv_column (str | int | None)
csv_has_header (bool)
jq_expression (str | None)
policy (SigmaPolicy | None)
cmd (str | list[str])
timeout (int)
max_stdout (int)
- Return type:
None