pySigma-backend-signals 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pysigma_backend_signals-0.1.0/LICENSE +166 -0
- pysigma_backend_signals-0.1.0/PKG-INFO +18 -0
- pysigma_backend_signals-0.1.0/pyproject.toml +23 -0
- pysigma_backend_signals-0.1.0/sigma/backends/signals/__init__.py +1 -0
- pysigma_backend_signals-0.1.0/sigma/backends/signals/signals.py +272 -0
- pysigma_backend_signals-0.1.0/sigma/pipelines/signals/__init__.py +1 -0
- pysigma_backend_signals-0.1.0/sigma/pipelines/signals/mappings.py +157 -0
- pysigma_backend_signals-0.1.0/sigma/pipelines/signals/signals.py +49 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
|
|
2
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
3
|
+
Version 3, 29 June 2007
|
|
4
|
+
|
|
5
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
6
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
7
|
+
of this license document, but changing it is not allowed.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
This version of the GNU Lesser General Public License incorporates
|
|
11
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
12
|
+
License, supplemented by the additional permissions listed below.
|
|
13
|
+
|
|
14
|
+
0. Additional Definitions.
|
|
15
|
+
|
|
16
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
17
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
18
|
+
General Public License.
|
|
19
|
+
|
|
20
|
+
"The Library" refers to a covered work governed by this License,
|
|
21
|
+
other than an Application or a Combined Work as defined below.
|
|
22
|
+
|
|
23
|
+
An "Application" is any work that makes use of an interface provided
|
|
24
|
+
by the Library, but which is not otherwise based on the Library.
|
|
25
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
26
|
+
of using an interface provided by the Library.
|
|
27
|
+
|
|
28
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
29
|
+
Application with the Library. The particular version of the Library
|
|
30
|
+
with which the Combined Work was made is also called the "Linked
|
|
31
|
+
Version".
|
|
32
|
+
|
|
33
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
34
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
35
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
36
|
+
based on the Application, and not on the Linked Version.
|
|
37
|
+
|
|
38
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
39
|
+
object code and/or source code for the Application, including any data
|
|
40
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
41
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
42
|
+
|
|
43
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
44
|
+
|
|
45
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
46
|
+
without being bound by section 3 of the GNU GPL.
|
|
47
|
+
|
|
48
|
+
2. Conveying Modified Versions.
|
|
49
|
+
|
|
50
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
51
|
+
facility refers to a function or data to be supplied by an Application
|
|
52
|
+
that uses the facility (other than as an argument passed when the
|
|
53
|
+
facility is invoked), then you may convey a copy of the modified
|
|
54
|
+
version:
|
|
55
|
+
|
|
56
|
+
a) under this License, provided that you make a good faith effort to
|
|
57
|
+
ensure that, in the event an Application does not supply the
|
|
58
|
+
function or data, the facility still operates, and performs
|
|
59
|
+
whatever part of its purpose remains meaningful, or
|
|
60
|
+
|
|
61
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
62
|
+
this License applicable to that copy.
|
|
63
|
+
|
|
64
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
65
|
+
|
|
66
|
+
The object code form of an Application may incorporate material from
|
|
67
|
+
a header file that is part of the Library. You may convey such object
|
|
68
|
+
code under terms of your choice, provided that, if the incorporated
|
|
69
|
+
material is not limited to numerical parameters, data structure
|
|
70
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
71
|
+
(ten or fewer lines in length), you do both of the following:
|
|
72
|
+
|
|
73
|
+
a) Give prominent notice with each copy of the object code that the
|
|
74
|
+
Library is used in it and that the Library and its use are
|
|
75
|
+
covered by this License.
|
|
76
|
+
|
|
77
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
78
|
+
document.
|
|
79
|
+
|
|
80
|
+
4. Combined Works.
|
|
81
|
+
|
|
82
|
+
You may convey a Combined Work under terms of your choice that,
|
|
83
|
+
taken together, effectively do not restrict modification of the
|
|
84
|
+
portions of the Library contained in the Combined Work and reverse
|
|
85
|
+
engineering for debugging such modifications, if you also do each of
|
|
86
|
+
the following:
|
|
87
|
+
|
|
88
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
89
|
+
the Library is used in it and that the Library and its use are
|
|
90
|
+
covered by this License.
|
|
91
|
+
|
|
92
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
93
|
+
document.
|
|
94
|
+
|
|
95
|
+
c) For a Combined Work that displays copyright notices during
|
|
96
|
+
execution, include the copyright notice for the Library among
|
|
97
|
+
these notices, as well as a reference directing the user to the
|
|
98
|
+
copies of the GNU GPL and this license document.
|
|
99
|
+
|
|
100
|
+
d) Do one of the following:
|
|
101
|
+
|
|
102
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
103
|
+
License, and the Corresponding Application Code in a form
|
|
104
|
+
suitable for, and under terms that permit, the user to
|
|
105
|
+
recombine or relink the Application with a modified version of
|
|
106
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
107
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
108
|
+
Corresponding Source.
|
|
109
|
+
|
|
110
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
111
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
112
|
+
a copy of the Library already present on the user's computer
|
|
113
|
+
system, and (b) will operate properly with a modified version
|
|
114
|
+
of the Library that is interface-compatible with the Linked
|
|
115
|
+
Version.
|
|
116
|
+
|
|
117
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
118
|
+
be required to provide such information under section 6 of the
|
|
119
|
+
GNU GPL, and only to the extent that such information is
|
|
120
|
+
necessary to install and execute a modified version of the
|
|
121
|
+
Combined Work produced by recombining or relinking the
|
|
122
|
+
Application with a modified version of the Linked Version. (If
|
|
123
|
+
you use option 4d0, the Installation Information must accompany
|
|
124
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
125
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
126
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
127
|
+
for conveying Corresponding Source.)
|
|
128
|
+
|
|
129
|
+
5. Combined Libraries.
|
|
130
|
+
|
|
131
|
+
You may place library facilities that are a work based on the
|
|
132
|
+
Library side by side in a single library together with other library
|
|
133
|
+
facilities that are not Applications and are not covered by this
|
|
134
|
+
License, and convey such a combined library under terms of your
|
|
135
|
+
choice, if you do both of the following:
|
|
136
|
+
|
|
137
|
+
a) Accompany the combined library with a copy of the same work based
|
|
138
|
+
on the Library, uncombined with any other library facilities,
|
|
139
|
+
conveyed under the terms of this License.
|
|
140
|
+
|
|
141
|
+
b) Give prominent notice with the combined library that part of it
|
|
142
|
+
is a work based on the Library, and explaining where to find the
|
|
143
|
+
accompanying uncombined form of the same work.
|
|
144
|
+
|
|
145
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
146
|
+
|
|
147
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
148
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
149
|
+
versions will be similar in spirit to the present version, but may
|
|
150
|
+
differ in detail to address new problems or concerns.
|
|
151
|
+
|
|
152
|
+
Each version is given a distinguishing version number. If the
|
|
153
|
+
Library as you received it specifies that a certain numbered version
|
|
154
|
+
of the GNU Lesser General Public License "or any later version"
|
|
155
|
+
applies to it, you have the option of following the terms and
|
|
156
|
+
conditions either of that published version or of any later version
|
|
157
|
+
published by the Free Software Foundation. If the Library as you
|
|
158
|
+
received it does not specify a version number of the GNU Lesser
|
|
159
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
160
|
+
General Public License ever published by the Free Software Foundation.
|
|
161
|
+
|
|
162
|
+
If the Library as you received it specifies that a proxy can decide
|
|
163
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
164
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
165
|
+
permanent authorization for you to choose that version for the
|
|
166
|
+
Library.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pySigma-backend-signals
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: pySigma signals backend
|
|
5
|
+
License: LGPL-3.0-only
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Author: Wayne Silva
|
|
8
|
+
Author-email: wayne@csrs.ltd
|
|
9
|
+
Requires-Python: >=3.10,<4.0
|
|
10
|
+
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Requires-Dist: pysigma (>=1.0.0)
|
|
18
|
+
Project-URL: Repository, https://github.com/wayne-csrs/pySigma-backend-signals
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "pySigma-backend-signals"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "pySigma signals backend"
|
|
5
|
+
authors = ["Wayne Silva <wayne@csrs.ltd>"]
|
|
6
|
+
license = "LGPL-3.0-only"
|
|
7
|
+
repository = "https://github.com/wayne-csrs/pySigma-backend-signals"
|
|
8
|
+
packages = [
|
|
9
|
+
{ include = "sigma" }
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[tool.poetry.dependencies]
|
|
13
|
+
python = ">=3.10,<4.0"
|
|
14
|
+
pysigma = ">=1.0.0"
|
|
15
|
+
|
|
16
|
+
[tool.poetry.group.dev.dependencies]
|
|
17
|
+
defusedxml = "^0.7"
|
|
18
|
+
pytest = "^8.0.0"
|
|
19
|
+
pytest-cov = "^7.1.0"
|
|
20
|
+
|
|
21
|
+
[build-system]
|
|
22
|
+
requires = ["poetry-core>=1.8.1"]
|
|
23
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .signals import SignalsBackend, signalsBackend
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from sigma.conversion.base import TextQueryBackend
|
|
3
|
+
from sigma.conversion.state import ConversionState
|
|
4
|
+
from sigma.conditions import ConditionItem, ConditionAND, ConditionOR, ConditionNOT
|
|
5
|
+
from sigma.correlations import SigmaCorrelationRule
|
|
6
|
+
from sigma.pipelines.signals import signals_pipeline
|
|
7
|
+
from sigma.rule import SigmaRule
|
|
8
|
+
from sigma.types import SigmaCompareExpression, SigmaRegularExpressionFlag
|
|
9
|
+
import re
|
|
10
|
+
from typing import Any, ClassVar, Dict, List, Optional, Pattern, Tuple, Union
|
|
11
|
+
|
|
12
|
+
# Future backend imports you may enable later:
|
|
13
|
+
# from sigma.conversion.state import ConversionState
|
|
14
|
+
# from sigma.rule import SigmaRule
|
|
15
|
+
# from sigma.types import SigmaRegularExpression
|
|
16
|
+
|
|
17
|
+
class SignalsBackend(TextQueryBackend):
|
|
18
|
+
"""Signals backend."""
|
|
19
|
+
|
|
20
|
+
name: ClassVar[str] = "signals backend"
|
|
21
|
+
formats: Dict[str, str] = {
|
|
22
|
+
"default": "Plain signals queries",
|
|
23
|
+
"json": "JSON output with query and Sigma metadata",
|
|
24
|
+
}
|
|
25
|
+
requires_pipeline: ClassVar[bool] = True
|
|
26
|
+
backend_processing_pipeline = signals_pipeline()
|
|
27
|
+
|
|
28
|
+
precedence: ClassVar[Tuple[ConditionItem, ConditionItem, ConditionItem]] = (
|
|
29
|
+
ConditionNOT,
|
|
30
|
+
ConditionAND,
|
|
31
|
+
ConditionOR,
|
|
32
|
+
)
|
|
33
|
+
group_expression: ClassVar[str] = "({expr})"
|
|
34
|
+
|
|
35
|
+
token_separator: str = " "
|
|
36
|
+
or_token: ClassVar[str] = "OR"
|
|
37
|
+
and_token: ClassVar[str] = "AND"
|
|
38
|
+
not_token: ClassVar[str] = "NOT"
|
|
39
|
+
eq_token: ClassVar[str] = "="
|
|
40
|
+
|
|
41
|
+
field_quote: ClassVar[str] = '"'
|
|
42
|
+
field_quote_pattern: ClassVar[Pattern] = re.compile(r"^[A-Za-z0-9_.]+$")
|
|
43
|
+
field_quote_pattern_negation: ClassVar[bool] = True
|
|
44
|
+
|
|
45
|
+
field_escape: ClassVar[str] = "\\"
|
|
46
|
+
field_escape_quote: ClassVar[bool] = True
|
|
47
|
+
field_escape_pattern: ClassVar[Pattern] = re.compile(r"\s")
|
|
48
|
+
|
|
49
|
+
str_quote: ClassVar[str] = "'"
|
|
50
|
+
escape_char: ClassVar[str] = "\\"
|
|
51
|
+
wildcard_multi: ClassVar[str] = "*"
|
|
52
|
+
wildcard_single: ClassVar[str] = "?"
|
|
53
|
+
add_escaped: ClassVar[str] = "\\"
|
|
54
|
+
filter_chars: ClassVar[str] = ""
|
|
55
|
+
bool_values: ClassVar[Dict[bool, str]] = {
|
|
56
|
+
True: "true",
|
|
57
|
+
False: "false",
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
startswith_expression: ClassVar[str] = "{field} starts with {value}"
|
|
61
|
+
endswith_expression: ClassVar[str] = "{field} ends with {value}"
|
|
62
|
+
contains_expression: ClassVar[str] = "{field} contains {value}"
|
|
63
|
+
wildcard_match_expression: ClassVar[str] = "{field} matches {value}"
|
|
64
|
+
|
|
65
|
+
# Regular expressions
|
|
66
|
+
# Regular expression query as format string with placeholders {field}, {regex}, {flag_x} where x
|
|
67
|
+
# is one of the flags shortcuts supported by Sigma (currently i, m and s) and refers to the
|
|
68
|
+
# token stored in the class variable re_flags.
|
|
69
|
+
re_expression: ClassVar[str] = "{field} matches regex {regex}"
|
|
70
|
+
re_escape_char: ClassVar[str] = "\\"
|
|
71
|
+
re_escape: ClassVar[Tuple[str, ...]] = ()
|
|
72
|
+
re_escape_escape_char: bool = True
|
|
73
|
+
re_flag_prefix: bool = True
|
|
74
|
+
# Mapping from SigmaRegularExpressionFlag values to static string templates that are used in
|
|
75
|
+
# flag_x placeholders in re_expression template.
|
|
76
|
+
# By default, i, m and s are defined. If a flag is not supported by the target query language,
|
|
77
|
+
# remove it from re_flags or don't define it to ensure proper error handling in case of appearance.
|
|
78
|
+
re_flags: Dict[SigmaRegularExpressionFlag, str] = {
|
|
79
|
+
SigmaRegularExpressionFlag.IGNORECASE: "i",
|
|
80
|
+
SigmaRegularExpressionFlag.MULTILINE: "m",
|
|
81
|
+
SigmaRegularExpressionFlag.DOTALL: "s",
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# Case sensitive string matching expression. String is quoted/escaped like a normal string.
|
|
85
|
+
# Placeholders {field} and {value} are replaced with field name and quoted/escaped string.
|
|
86
|
+
case_sensitive_match_expression: ClassVar[str] = "{field} = {value}"
|
|
87
|
+
case_sensitive_startswith_expression: ClassVar[str] = "{field} starts with {value}"
|
|
88
|
+
case_sensitive_endswith_expression: ClassVar[str] = "{field} ends with {value}"
|
|
89
|
+
case_sensitive_contains_expression: ClassVar[str] = "{field} contains {value}"
|
|
90
|
+
|
|
91
|
+
# CIDR expressions: define CIDR matching if backend has native support. Else pySigma expands
|
|
92
|
+
# CIDR values into string wildcard matches.
|
|
93
|
+
cidr_expression: ClassVar[Optional[str]] = None
|
|
94
|
+
|
|
95
|
+
# Numeric comparison operators
|
|
96
|
+
compare_op_expression: ClassVar[str] = "{field} {operator} {value}"
|
|
97
|
+
compare_operators: ClassVar[Dict[SigmaCompareExpression.CompareOperators, str]] = {
|
|
98
|
+
SigmaCompareExpression.CompareOperators.LT: "<",
|
|
99
|
+
SigmaCompareExpression.CompareOperators.LTE: "<=",
|
|
100
|
+
SigmaCompareExpression.CompareOperators.GT: ">",
|
|
101
|
+
SigmaCompareExpression.CompareOperators.GTE: ">=",
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
# Expression for comparing two event fields
|
|
105
|
+
field_equals_field_expression: ClassVar[Optional[str]] = None
|
|
106
|
+
field_equals_field_escaping_quoting: Tuple[bool, bool] = (True, True)
|
|
107
|
+
|
|
108
|
+
# Null/None expressions
|
|
109
|
+
field_null_expression: ClassVar[str] = "{field} is null"
|
|
110
|
+
|
|
111
|
+
# Field existence condition expressions.
|
|
112
|
+
field_exists_expression: ClassVar[str] = "{field} exists"
|
|
113
|
+
field_not_exists_expression: ClassVar[str] = "{field} not exists"
|
|
114
|
+
|
|
115
|
+
# Field value in list, e.g. "field in (value list)" or "field containsall (value list)"
|
|
116
|
+
convert_or_as_in: ClassVar[bool] = False
|
|
117
|
+
convert_and_as_in: ClassVar[bool] = False
|
|
118
|
+
in_expressions_allow_wildcards: ClassVar[bool] = False
|
|
119
|
+
field_in_list_expression: ClassVar[str] = "{field} {op} ({list})"
|
|
120
|
+
or_in_operator: ClassVar[str] = "in"
|
|
121
|
+
and_in_operator: ClassVar[str] = "in"
|
|
122
|
+
list_separator: ClassVar[str] = ", "
|
|
123
|
+
|
|
124
|
+
# Value not bound to a field
|
|
125
|
+
unbound_value_str_expression: ClassVar[str] = "{value}"
|
|
126
|
+
unbound_value_num_expression: ClassVar[str] = "{value}"
|
|
127
|
+
unbound_value_re_expression: ClassVar[str] = "{value}"
|
|
128
|
+
|
|
129
|
+
# Query finalization: appending and concatenating deferred query part
|
|
130
|
+
deferred_start: ClassVar[str] = "\n| "
|
|
131
|
+
deferred_separator: ClassVar[str] = "\n| "
|
|
132
|
+
deferred_only_query: ClassVar[str] = "*"
|
|
133
|
+
|
|
134
|
+
correlation_methods: ClassVar[Dict[str, str]] = {
|
|
135
|
+
"default": "Test correlation method",
|
|
136
|
+
}
|
|
137
|
+
default_correlation_method: ClassVar[str] = "default"
|
|
138
|
+
default_correlation_query: ClassVar[str] = {"default": "{search}\n{aggregate}\n{condition}"}
|
|
139
|
+
temporal_correlation_query: ClassVar[str] = {"default": "{search}\n\n{aggregate}\n\n{condition}"}
|
|
140
|
+
|
|
141
|
+
correlation_search_single_rule_expression: ClassVar[str] = "{query}"
|
|
142
|
+
correlation_search_multi_rule_expression: ClassVar[str] = "{queries}"
|
|
143
|
+
correlation_search_multi_rule_query_expression: ClassVar[
|
|
144
|
+
str
|
|
145
|
+
] = 'subsearch (( {query} | set event_type="{ruleid}"{normalization} ))'
|
|
146
|
+
correlation_search_multi_rule_query_expression_joiner: ClassVar[str] = "\n"
|
|
147
|
+
|
|
148
|
+
correlation_search_field_normalization_expression: ClassVar[str] = " | set {alias}={field}"
|
|
149
|
+
correlation_search_field_normalization_expression_joiner: ClassVar[str] = ""
|
|
150
|
+
|
|
151
|
+
event_count_aggregation_expression: ClassVar[Dict[str, str]] = {
|
|
152
|
+
"default": "| aggregate window={timespan} count() as event_count{groupby}"
|
|
153
|
+
}
|
|
154
|
+
value_count_aggregation_expression: ClassVar[Dict[str, str]] = {
|
|
155
|
+
"default": "| aggregate window={timespan} value_count({field}) as value_count{groupby}"
|
|
156
|
+
}
|
|
157
|
+
temporal_aggregation_expression: ClassVar[Dict[str, str]] = {
|
|
158
|
+
"default": "| temporal window={timespan} eventtypes={referenced_rules}{groupby}"
|
|
159
|
+
}
|
|
160
|
+
temporal_ordered_aggregation_expression: ClassVar[Dict[str, str]] = {
|
|
161
|
+
"default": "| temporal ordered=true window={timespan} eventtypes={referenced_rules}{groupby}"
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
timespan_mapping: ClassVar[Dict[str, str]] = {
|
|
165
|
+
"m": "min",
|
|
166
|
+
}
|
|
167
|
+
referenced_rules_expression: ClassVar[Dict[str, str]] = {"default": "{ruleid}"}
|
|
168
|
+
referenced_rules_expression_joiner: ClassVar[Dict[str, str]] = {"default": ","}
|
|
169
|
+
|
|
170
|
+
groupby_expression: ClassVar[Dict[str, str]] = {"default": " by {fields}"}
|
|
171
|
+
groupby_field_expression: ClassVar[Dict[str, str]] = {"default": "{field}"}
|
|
172
|
+
groupby_field_expression_joiner: ClassVar[Dict[str, str]] = {"default": ", "}
|
|
173
|
+
|
|
174
|
+
event_count_condition_expression: ClassVar[Dict[str, str]] = {
|
|
175
|
+
"default": "| where event_count {op} {count}"
|
|
176
|
+
}
|
|
177
|
+
value_count_condition_expression: ClassVar[Dict[str, str]] = {
|
|
178
|
+
"default": "| where value_count {op} {count}"
|
|
179
|
+
}
|
|
180
|
+
temporal_condition_expression: ClassVar[Dict[str, str]] = {
|
|
181
|
+
"default": "| where eventtype_count {op} {count}"
|
|
182
|
+
}
|
|
183
|
+
temporal_ordered_condition_expression: ClassVar[Dict[str, str]] = {
|
|
184
|
+
"default": "| where eventtype_count {op} {count} and eventtype_order={referenced_rules}"
|
|
185
|
+
}
|
|
186
|
+
### Correlation end ###
|
|
187
|
+
|
|
188
|
+
@staticmethod
|
|
189
|
+
def _extract_mitre_technique_ids(rule: SigmaRule) -> List[str]:
|
|
190
|
+
technique_ids: List[str] = []
|
|
191
|
+
for tag in rule.tags or []:
|
|
192
|
+
tag_value = str(tag).lower()
|
|
193
|
+
if not tag_value.startswith("attack.t"):
|
|
194
|
+
continue
|
|
195
|
+
technique_id = tag_value.split(".", 1)[1].upper()
|
|
196
|
+
technique_ids.append(technique_id)
|
|
197
|
+
return technique_ids
|
|
198
|
+
|
|
199
|
+
@staticmethod
|
|
200
|
+
def _extract_mitre_tactics(rule: SigmaRule) -> List[str]:
|
|
201
|
+
tactics: List[str] = []
|
|
202
|
+
for tag in rule.tags or []:
|
|
203
|
+
tag_value = str(tag).lower()
|
|
204
|
+
if not tag_value.startswith("attack."):
|
|
205
|
+
continue
|
|
206
|
+
attack_tag = tag_value.split(".", 1)[1]
|
|
207
|
+
# Tactics are ATT&CK tags like "attack.execution", not technique IDs.
|
|
208
|
+
if attack_tag.startswith("t"):
|
|
209
|
+
continue
|
|
210
|
+
if attack_tag not in tactics:
|
|
211
|
+
tactics.append(attack_tag)
|
|
212
|
+
return tactics
|
|
213
|
+
|
|
214
|
+
def finalize_query_json(
|
|
215
|
+
self,
|
|
216
|
+
rule: Union[SigmaRule, SigmaCorrelationRule],
|
|
217
|
+
query: str,
|
|
218
|
+
index: int,
|
|
219
|
+
state: ConversionState,
|
|
220
|
+
) -> Dict[str, Any]:
|
|
221
|
+
if isinstance(rule, SigmaCorrelationRule):
|
|
222
|
+
return {
|
|
223
|
+
"name": rule.name or "",
|
|
224
|
+
"description": "",
|
|
225
|
+
"status": "",
|
|
226
|
+
"level": "",
|
|
227
|
+
"text": query,
|
|
228
|
+
"platforms": [],
|
|
229
|
+
"date": "",
|
|
230
|
+
"modified": "",
|
|
231
|
+
"author": "",
|
|
232
|
+
"reference": [],
|
|
233
|
+
"falsepositives": [],
|
|
234
|
+
"mitreAttack": {
|
|
235
|
+
"technique_ids": [],
|
|
236
|
+
"tactics": [],
|
|
237
|
+
},
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
platforms: List[str] = []
|
|
241
|
+
if rule.logsource is not None:
|
|
242
|
+
for value in (rule.logsource.product, rule.logsource.service):
|
|
243
|
+
if value:
|
|
244
|
+
platforms.append(value)
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
"name": rule.title or "",
|
|
248
|
+
"description": str(getattr(rule, "description", "") or ""),
|
|
249
|
+
"status": str(getattr(rule, "status", "") or ""),
|
|
250
|
+
"level": str(getattr(rule, "level", "") or ""),
|
|
251
|
+
"text": query,
|
|
252
|
+
"platforms": platforms,
|
|
253
|
+
"date": str(getattr(rule, "date", "") or ""),
|
|
254
|
+
"modified": str(getattr(rule, "modified", "") or ""),
|
|
255
|
+
"author": str(getattr(rule, "author", "") or ""),
|
|
256
|
+
"reference": [str(reference) for reference in (rule.references or [])],
|
|
257
|
+
"falsepositives": [
|
|
258
|
+
str(falsepositive) for falsepositive in (rule.falsepositives or [])
|
|
259
|
+
],
|
|
260
|
+
"mitreAttack": {
|
|
261
|
+
"technique_ids": self._extract_mitre_technique_ids(rule),
|
|
262
|
+
"tactics": self._extract_mitre_tactics(rule),
|
|
263
|
+
},
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
def finalize_output_json(self, queries: List[Dict[str, Any]]) -> str:
|
|
267
|
+
return json.dumps(queries, indent=2)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
# Backward-compatible alias for existing imports.
|
|
271
|
+
signalsBackend = SignalsBackend
|
|
272
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .signals import signals_pipeline
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
from sigma.pipelines.common import (
|
|
2
|
+
logsource_linux_file_create,
|
|
3
|
+
logsource_linux_network_connection,
|
|
4
|
+
logsource_linux_process_creation,
|
|
5
|
+
logsource_macos_file_create,
|
|
6
|
+
logsource_macos_process_creation,
|
|
7
|
+
logsource_windows_file_event,
|
|
8
|
+
logsource_windows_image_load,
|
|
9
|
+
logsource_windows_network_connection,
|
|
10
|
+
logsource_windows_process_creation,
|
|
11
|
+
logsource_windows_registry_event,
|
|
12
|
+
logsource_windows_registry_set,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
# Future logsource helpers we may enable later:
|
|
16
|
+
# from sigma.pipelines.common import (
|
|
17
|
+
# logsource_windows_file_access,
|
|
18
|
+
# logsource_windows_file_change,
|
|
19
|
+
# logsource_windows_file_delete,
|
|
20
|
+
# logsource_windows_file_rename,
|
|
21
|
+
# logsource_windows_registry_add,
|
|
22
|
+
# logsource_windows_registry_delete,
|
|
23
|
+
# )
|
|
24
|
+
|
|
25
|
+
# Rule categories -> rule conditions
|
|
26
|
+
CATEGORY_TO_CONDITIONS_MAPPINGS = {
|
|
27
|
+
"windows_process_creation": logsource_windows_process_creation(),
|
|
28
|
+
"windows_image_load": logsource_windows_image_load(),
|
|
29
|
+
"windows_file_event": logsource_windows_file_event(),
|
|
30
|
+
"windows_network_connection": logsource_windows_network_connection(),
|
|
31
|
+
"windows_registry_event": logsource_windows_registry_event(),
|
|
32
|
+
"windows_registry_set": logsource_windows_registry_set(),
|
|
33
|
+
"linux_process_creation": logsource_linux_process_creation(),
|
|
34
|
+
"linux_network_connection": logsource_linux_network_connection(),
|
|
35
|
+
"linux_file_create": logsource_linux_file_create(),
|
|
36
|
+
"macos_process_creation": logsource_macos_process_creation(),
|
|
37
|
+
"macos_file_create": logsource_macos_file_create(),
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
# Generic mappings that apply to all rule categories.
|
|
41
|
+
GENERIC_FIELD_MAPPINGS = {
|
|
42
|
+
"User": "user.name",
|
|
43
|
+
"UserName": "user.name",
|
|
44
|
+
"LogonId": "user.logon_id",
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
# Rule category -> field mappings
|
|
48
|
+
CATEGORY_FIELD_MAPPINGS = {
|
|
49
|
+
"windows_process_creation": {
|
|
50
|
+
"Image": "process.path",
|
|
51
|
+
"ProcessName": "process.name",
|
|
52
|
+
"CommandLine": "process.command_line",
|
|
53
|
+
"ParentImage": "process.parent.path",
|
|
54
|
+
"ParentProcessName": "process.parent.name",
|
|
55
|
+
"ParentCommandLine": "process.parent.command_line",
|
|
56
|
+
"CurrentDirectory": "process.working_directory",
|
|
57
|
+
"IntegrityLevel": "process.integrity_level",
|
|
58
|
+
"sha256": "process.hash.sha256",
|
|
59
|
+
"sha1": "process.hash.sha1",
|
|
60
|
+
"md5": "process.hash.md5",
|
|
61
|
+
},
|
|
62
|
+
"windows_image_load": {
|
|
63
|
+
"Image": "process.path",
|
|
64
|
+
"ImageLoaded": "module.path",
|
|
65
|
+
"ProcessName": "process.name",
|
|
66
|
+
"CommandLine": "process.command_line",
|
|
67
|
+
"sha256": "module.hash.sha256",
|
|
68
|
+
"sha1": "module.hash.sha1",
|
|
69
|
+
"md5": "module.hash.md5",
|
|
70
|
+
},
|
|
71
|
+
"windows_file_event": {
|
|
72
|
+
"Image": "process.path",
|
|
73
|
+
"TargetFilename": "file.path",
|
|
74
|
+
"FileName": "file.name",
|
|
75
|
+
"sha256": "file.hash.sha256",
|
|
76
|
+
"sha1": "file.hash.sha1",
|
|
77
|
+
"md5": "file.hash.md5",
|
|
78
|
+
},
|
|
79
|
+
"windows_network_connection": {
|
|
80
|
+
"Image": "process.path",
|
|
81
|
+
"ProcessName": "process.name",
|
|
82
|
+
"CommandLine": "process.command_line",
|
|
83
|
+
"Protocol": "network.protocol",
|
|
84
|
+
"SourceIp": "network.source.ip",
|
|
85
|
+
"SourcePort": "network.source.port",
|
|
86
|
+
"DestinationIp": "network.destination.ip",
|
|
87
|
+
"DestinationPort": "network.destination.port",
|
|
88
|
+
"DestinationHostname": "network.destination.domain",
|
|
89
|
+
},
|
|
90
|
+
"windows_registry_event": {
|
|
91
|
+
"Image": "process.path",
|
|
92
|
+
"TargetObject": "registry.key.path",
|
|
93
|
+
"RegistryKey": "registry.key.path",
|
|
94
|
+
"RegistryValueName": "registry.value.name",
|
|
95
|
+
"RegistryValueData": "registry.value.data",
|
|
96
|
+
"Details": "registry.value.data",
|
|
97
|
+
},
|
|
98
|
+
"windows_registry_set": {
|
|
99
|
+
"Image": "process.path",
|
|
100
|
+
"TargetObject": "registry.key.path",
|
|
101
|
+
"RegistryKey": "registry.key.path",
|
|
102
|
+
"RegistryValueName": "registry.value.name",
|
|
103
|
+
"RegistryValueData": "registry.value.data",
|
|
104
|
+
"Details": "registry.value.data",
|
|
105
|
+
},
|
|
106
|
+
"linux_process_creation": {
|
|
107
|
+
"Image": "process.path",
|
|
108
|
+
"ProcessName": "process.name",
|
|
109
|
+
"CommandLine": "process.command_line",
|
|
110
|
+
"ParentImage": "process.parent.path",
|
|
111
|
+
"ParentProcessName": "process.parent.name",
|
|
112
|
+
"ParentCommandLine": "process.parent.command_line",
|
|
113
|
+
"CurrentDirectory": "process.working_directory",
|
|
114
|
+
"sha256": "process.hash.sha256",
|
|
115
|
+
"sha1": "process.hash.sha1",
|
|
116
|
+
"md5": "process.hash.md5",
|
|
117
|
+
},
|
|
118
|
+
"linux_network_connection": {
|
|
119
|
+
"Image": "process.path",
|
|
120
|
+
"ProcessName": "process.name",
|
|
121
|
+
"CommandLine": "process.command_line",
|
|
122
|
+
"Protocol": "network.protocol",
|
|
123
|
+
"SourceIp": "network.source.ip",
|
|
124
|
+
"SourcePort": "network.source.port",
|
|
125
|
+
"DestinationIp": "network.destination.ip",
|
|
126
|
+
"DestinationPort": "network.destination.port",
|
|
127
|
+
"DestinationHostname": "network.destination.domain",
|
|
128
|
+
},
|
|
129
|
+
"linux_file_create": {
|
|
130
|
+
"Image": "process.path",
|
|
131
|
+
"TargetFilename": "file.path",
|
|
132
|
+
"FileName": "file.name",
|
|
133
|
+
"sha256": "file.hash.sha256",
|
|
134
|
+
"sha1": "file.hash.sha1",
|
|
135
|
+
"md5": "file.hash.md5",
|
|
136
|
+
},
|
|
137
|
+
"macos_process_creation": {
|
|
138
|
+
"Image": "process.path",
|
|
139
|
+
"ProcessName": "process.name",
|
|
140
|
+
"CommandLine": "process.command_line",
|
|
141
|
+
"ParentImage": "process.parent.path",
|
|
142
|
+
"ParentProcessName": "process.parent.name",
|
|
143
|
+
"ParentCommandLine": "process.parent.command_line",
|
|
144
|
+
"CurrentDirectory": "process.working_directory",
|
|
145
|
+
"sha256": "process.hash.sha256",
|
|
146
|
+
"sha1": "process.hash.sha1",
|
|
147
|
+
"md5": "process.hash.md5",
|
|
148
|
+
},
|
|
149
|
+
"macos_file_create": {
|
|
150
|
+
"Image": "process.path",
|
|
151
|
+
"TargetFilename": "file.path",
|
|
152
|
+
"FileName": "file.name",
|
|
153
|
+
"sha256": "file.hash.sha256",
|
|
154
|
+
"sha1": "file.hash.sha1",
|
|
155
|
+
"md5": "file.hash.md5",
|
|
156
|
+
},
|
|
157
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from sigma.pipelines.base import Pipeline
|
|
2
|
+
from sigma.processing.pipeline import ProcessingItem, ProcessingPipeline
|
|
3
|
+
from sigma.processing.transformations import FieldMappingTransformation
|
|
4
|
+
from sigma.pipelines.signals.mappings import (
|
|
5
|
+
CATEGORY_FIELD_MAPPINGS,
|
|
6
|
+
CATEGORY_TO_CONDITIONS_MAPPINGS,
|
|
7
|
+
GENERIC_FIELD_MAPPINGS,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
# Future pipeline imports you may enable later:
|
|
11
|
+
# from sigma.processing.conditions import (
|
|
12
|
+
# IncludeFieldCondition,
|
|
13
|
+
# ExcludeFieldCondition,
|
|
14
|
+
# RuleProcessingItemAppliedCondition,
|
|
15
|
+
# )
|
|
16
|
+
# from sigma.processing.postprocessing import EmbedQueryTransformation
|
|
17
|
+
# from sigma.processing.pipeline import QueryPostprocessingItem
|
|
18
|
+
# from sigma.processing.transformations import (
|
|
19
|
+
# AddConditionTransformation,
|
|
20
|
+
# DetectionItemFailureTransformation,
|
|
21
|
+
# RuleFailureTransformation,
|
|
22
|
+
# SetStateTransformation,
|
|
23
|
+
# )
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@Pipeline
|
|
27
|
+
def signals_pipeline() -> ProcessingPipeline:
|
|
28
|
+
items = [
|
|
29
|
+
ProcessingItem(
|
|
30
|
+
identifier="signals_base_field_mapping",
|
|
31
|
+
transformation=FieldMappingTransformation(GENERIC_FIELD_MAPPINGS),
|
|
32
|
+
)
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
for category, field_mappings in CATEGORY_FIELD_MAPPINGS.items():
|
|
36
|
+
items.append(
|
|
37
|
+
ProcessingItem(
|
|
38
|
+
identifier=f"signals_field_mapping_{category}",
|
|
39
|
+
transformation=FieldMappingTransformation(field_mappings),
|
|
40
|
+
rule_conditions=[CATEGORY_TO_CONDITIONS_MAPPINGS[category]],
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
return ProcessingPipeline(
|
|
45
|
+
name="Tanium Signals field mapping",
|
|
46
|
+
allowed_backends=frozenset({"signals"}),
|
|
47
|
+
priority=20,
|
|
48
|
+
items=items,
|
|
49
|
+
)
|