pySigma-backend-elasticsearch 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.
@@ -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,16 @@
1
+ Metadata-Version: 2.1
2
+ Name: pysigma-backend-elasticsearch
3
+ Version: 0.1.0
4
+ Summary: pySigma Elasticsearch backend
5
+ Home-page: https://github.com/SigmaHQ/pySigma-backend-elasticsearch
6
+ License: LGPL-3.0-only
7
+ Author: Thomas Patzke
8
+ Author-email: thomas@patzke.org
9
+ Requires-Python: >=3.8,<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.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Requires-Dist: pysigma (>=0.7.1,<0.8.0)
16
+ Project-URL: Repository, https://github.com/SigmaHQ/pySigma-backend-elasticsearch
@@ -0,0 +1,24 @@
1
+ [tool.poetry]
2
+ name = "pySigma-backend-elasticsearch"
3
+ version = "0.1.0"
4
+ description = "pySigma Elasticsearch backend"
5
+ authors = ["Thomas Patzke <thomas@patzke.org>"]
6
+ license = "LGPL-3.0-only"
7
+ repository = "https://github.com/SigmaHQ/pySigma-backend-elasticsearch"
8
+ packages = [
9
+ { include = "sigma" }
10
+ ]
11
+
12
+ [tool.poetry.dependencies]
13
+ python = "^3.8"
14
+ pysigma = "^0.7.1"
15
+
16
+ [tool.poetry.dev-dependencies]
17
+ pytest = "^7.1.2"
18
+ pytest-cov = "^3.0.0"
19
+ coverage = "^6.4.1"
20
+ requests = "^2.28.1"
21
+
22
+ [build-system]
23
+ requires = ["poetry-core>=1.0.0"]
24
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ from setuptools import setup
3
+
4
+ packages = \
5
+ ['sigma', 'sigma.backends.elasticsearch', 'sigma.pipelines.elasticsearch']
6
+
7
+ package_data = \
8
+ {'': ['*']}
9
+
10
+ install_requires = \
11
+ ['pysigma>=0.7.1,<0.8.0']
12
+
13
+ setup_kwargs = {
14
+ 'name': 'pysigma-backend-elasticsearch',
15
+ 'version': '0.1.0',
16
+ 'description': 'pySigma Elasticsearch backend',
17
+ 'long_description': None,
18
+ 'author': 'Thomas Patzke',
19
+ 'author_email': 'thomas@patzke.org',
20
+ 'maintainer': None,
21
+ 'maintainer_email': None,
22
+ 'url': 'https://github.com/SigmaHQ/pySigma-backend-elasticsearch',
23
+ 'packages': packages,
24
+ 'package_data': package_data,
25
+ 'install_requires': install_requires,
26
+ 'python_requires': '>=3.8,<4.0',
27
+ }
28
+
29
+
30
+ setup(**setup_kwargs)
@@ -0,0 +1 @@
1
+ from .elasticsearch import LuceneBackend
@@ -0,0 +1,161 @@
1
+ from sigma.conversion.state import ConversionState
2
+ from sigma.rule import SigmaRule
3
+ from sigma.conversion.base import TextQueryBackend
4
+ from sigma.conditions import ConditionItem, ConditionAND, ConditionOR, ConditionNOT
5
+ from sigma.types import SigmaCompareExpression
6
+ import sigma
7
+ import re
8
+ import json
9
+ from typing import ClassVar, Dict, List, Optional, Pattern, Tuple
10
+
11
+ class LuceneBackend(TextQueryBackend):
12
+ """
13
+ Elasticsearch query string backend. Generates query strings described here in the Elasticsearch documentation:
14
+
15
+ https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax
16
+ """
17
+ # Operator precedence: tuple of Condition{AND,OR,NOT} in order of precedence.
18
+ # The backend generates grouping if required
19
+ precedence : ClassVar[Tuple[ConditionItem, ConditionItem, ConditionItem]] = (ConditionNOT, ConditionOR, ConditionAND)
20
+ group_expression : ClassVar[str] = "({expr})" # Expression for precedence override grouping as format string with {expr} placeholder
21
+ parenthesize: bool = True
22
+
23
+ # Generated query tokens
24
+ token_separator : str = " " # separator inserted between all boolean operators
25
+ or_token : ClassVar[str] = "OR"
26
+ and_token : ClassVar[str] = "AND"
27
+ not_token : ClassVar[str] = "NOT"
28
+ eq_token : ClassVar[str] = ":" # Token inserted between field and value (without separator)
29
+
30
+ # String output
31
+ ## Fields
32
+ ### No quoting of field names
33
+ ### Escaping
34
+ field_escape : ClassVar[str] = "\\" # Character to escape particular parts defined in field_escape_pattern.
35
+ field_escape_pattern : ClassVar[Pattern] = re.compile("[\\s*]") # All matches of this pattern are prepended with the string contained in field_escape.
36
+
37
+ ## Values
38
+ str_quote : ClassVar[str] = '' # string quoting character (added as escaping character)
39
+ escape_char : ClassVar[str] = "\\" # Escaping character for special characrers inside string
40
+ wildcard_multi : ClassVar[str] = "*" # Character used as multi-character wildcard
41
+ wildcard_single : ClassVar[str] = "?" # Character used as single-character wildcard
42
+ add_escaped : ClassVar[str] = '+-=&|!(){}[]^"~*?:\\/ ' # Characters quoted in addition to wildcards and string quote
43
+ filter_chars : ClassVar[str] = "<>" # Characters filtered
44
+ bool_values : ClassVar[Dict[bool, str]] = { # Values to which boolean values are mapped.
45
+ True: "true",
46
+ False: "false",
47
+ }
48
+
49
+ # Regular expressions
50
+ re_expression : ClassVar[str] = "{field}:/{regex}/" # Regular expression query as format string with placeholders {field} and {regex}
51
+ re_escape_char : ClassVar[str] = "\\" # Character used for escaping in regular expressions
52
+
53
+ # cidr expressions
54
+ cidr_expression : ClassVar[str] = "{field}:{network}\\/{prefixlen}" # CIDR expression query as format string with placeholders {field} = {value}
55
+
56
+ # Numeric comparison operators
57
+ compare_op_expression : ClassVar[str] = "{field}:{operator}{value}" # Compare operation query as format string with placeholders {field}, {operator} and {value}
58
+ # Mapping between CompareOperators elements and strings used as replacement for {operator} in compare_op_expression
59
+ compare_operators : ClassVar[Dict[SigmaCompareExpression.CompareOperators, str]] = {
60
+ SigmaCompareExpression.CompareOperators.LT : "<",
61
+ SigmaCompareExpression.CompareOperators.LTE : "<=",
62
+ SigmaCompareExpression.CompareOperators.GT : ">",
63
+ SigmaCompareExpression.CompareOperators.GTE : ">=",
64
+ }
65
+
66
+ # Null/None expressions
67
+ field_null_expression : ClassVar[str] = "NOT _exists_:{field}" # Expression for field has null value as format string with {field} placeholder for field name
68
+
69
+ # Field value in list, e.g. "field in (value list)" or "field containsall (value list)"
70
+ convert_or_as_in : ClassVar[bool] = True # Convert OR as in-expression
71
+ convert_and_as_in : ClassVar[bool] = False # Convert AND as in-expression
72
+ in_expressions_allow_wildcards : ClassVar[bool] = True # Values in list can contain wildcards. If set to False (default) only plain values are converted into in-expressions.
73
+ field_in_list_expression : ClassVar[str] = "{field}{op}({list})" # Expression for field in list of values as format string with placeholders {field}, {op} and {list}
74
+ or_in_operator : ClassVar[str] = ":" # Operator used to convert OR into in-expressions. Must be set if convert_or_as_in is set
75
+ list_separator : ClassVar[str] = " OR " # List element separator
76
+
77
+ # Value not bound to a field
78
+ unbound_value_str_expression : ClassVar[str] = '"{value}"' # Expression for string value not bound to a field as format string with placeholder {value}
79
+ unbound_value_num_expression : ClassVar[str] = '{value}' # Expression for number value not bound to a field as format string with placeholder {value}
80
+
81
+ def finalize_query_kibana(self, rule: SigmaRule, query: str, index: int, state: ConversionState) -> str:
82
+ # TODO: implement the per-query output for the output format kibana here. Usually, the generated query is
83
+ # embedded into a template, e.g. a JSON format with additional information from the Sigma rule.
84
+ return query
85
+
86
+ def finalize_output_kibana(self, queries: List[str]) -> str:
87
+ # TODO: implement the output finalization for all generated queries for the format kibana here. Usually,
88
+ # the single generated queries are embedded into a structure, e.g. some JSON or XML that can be imported into
89
+ # the SIEM.
90
+ return list(queries)
91
+
92
+ def finalize_query_dsl_lucene(self, rule: SigmaRule, query: str, index: int, state: ConversionState) -> str:
93
+ return {
94
+ "query": {
95
+ "bool": {
96
+ "must": [
97
+ {
98
+ "query_string": {
99
+ "query": query,
100
+ "analyze_wildcard": True
101
+ }
102
+ }
103
+ ]
104
+ }
105
+ }
106
+ }
107
+
108
+ def finalize_output_dsl_lucene(self, queries: List[str]) -> str:
109
+ return list(queries)
110
+
111
+ def finalize_query_kibana_ndjson(self, rule: SigmaRule, query: str, index: int, state: ConversionState) -> str:
112
+ # TODO: implement the per-query output for the output format kibana here. Usually, the generated query is
113
+ # embedded into a template, e.g. a JSON format with additional information from the Sigma rule.
114
+ columns = list()
115
+ index = "beats-*"
116
+ ndjson = {
117
+ "id": str(rule.id),
118
+ "type": "search",
119
+ "attributes": {
120
+ "title": "SIGMA - {}".format(rule.title),
121
+ "description": rule.description,
122
+ "hits": 0,
123
+ "columns": columns,
124
+ "sort": ["@timestamp", "desc"],
125
+ "version": 1,
126
+ "kibanaSavedObjectMeta": {
127
+ "searchSourceJSON": str(json.dumps({
128
+ "index": index,
129
+ "filter": [],
130
+ "highlight": {
131
+ "pre_tags": ["@kibana-highlighted-field@"],
132
+ "post_tags": ["@/kibana-highlighted-field@"],
133
+ "fields": { "*":{} },
134
+ "require_field_match": False,
135
+ "fragment_size": 2147483647
136
+ },
137
+ "query": {
138
+ "query_string": {
139
+ "query": query,
140
+ "analyze_wildcard": True
141
+ }
142
+ }
143
+ })
144
+ )
145
+ }
146
+ },
147
+ "references": [
148
+ {
149
+ "id": index,
150
+ "name": "kibanaSavedObjectMeta.searchSourceJSON.index",
151
+ "type": "index-pattern"
152
+ }
153
+ ]
154
+ }
155
+ return ndjson
156
+
157
+ def finalize_output_kibana_ndjson(self, queries: List[str]) -> str:
158
+ # TODO: implement the output finalization for all generated queries for the format kibana here. Usually,
159
+ # the single generated queries are embedded into a structure, e.g. some JSON or XML that can be imported into
160
+ # the SIEM.
161
+ return list(queries)
@@ -0,0 +1,226 @@
1
+ from sigma.pipelines.common import logsource_windows, windows_logsource_mapping
2
+ from sigma.processing.transformations import FieldMappingTransformation, AddFieldnamePrefixTransformation, AddConditionTransformation
3
+ from sigma.processing.conditions import LogsourceCondition, IncludeFieldCondition, ExcludeFieldCondition, RuleProcessingItemAppliedCondition
4
+ from sigma.processing.pipeline import ProcessingItem, ProcessingPipeline
5
+
6
+ ecs_windows_variable_mappings = {
7
+ "FileVersion": (
8
+ ("category", "process_creation", "process.pe.file_version"),
9
+ ("category", "image_load", "file.pe.file_version"),
10
+ ),
11
+ "Description": (
12
+ ("category", "process_creation", "process.pe.description"),
13
+ ("category", "image_load", "file.pe.description"),
14
+ ("category", "sysmon_error", "winlog.event_data.Description"),
15
+ ),
16
+ "Product": (
17
+ ("category", "process_creation", "process.pe.product"),
18
+ ("category", "image_load", "file.pe.product"),
19
+ ),
20
+ "Company": (
21
+ ("category", "process_creation", "process.pe.company"),
22
+ ("category", "image_load", "file.pe.company"),
23
+ ),
24
+ "OriginalFileName": (
25
+ ("category", "process_creation", "process.pe.original_file_name"),
26
+ ("category", "image_load", "file.pe.original_file_name"),
27
+ ),
28
+ "CommandLine": (
29
+ ("category", "process_creation", "process.command_line"),
30
+ ("service", "security", "process.command_line"),
31
+ ("service", "powershell-classic", "powershell.command.value"),
32
+ ),
33
+ "Protocol": (
34
+ ("category", "network_connection", "network.transport"),
35
+ ),
36
+ "Initiated": (
37
+ ("category", "network_connection", "network.direction"),
38
+ ),
39
+ "Signature": (
40
+ ("category", "driver_loaded", "file.code_signature.subject_name"),
41
+ ("category", "image_loaded", "file.code_signature.subject_name"),
42
+ ),
43
+ "EngineVersion": (
44
+ ("service", "powershell-classic", "powershell.engine.version"),
45
+ ),
46
+ "HostVersion": (
47
+ ("service", "powershell-classic", "powershell.process.executable_version"),
48
+ ),
49
+ "SubjectLogonId": (
50
+ ("service", "security", "winlog.logon.id"),
51
+ ),
52
+ "ServiceName": (
53
+ ("service", "security", "service.name"),
54
+ ),
55
+ "SubjectDomainName": (
56
+ ("service", "security", "user.domain"),
57
+ ),
58
+ "SubjectUserName": (
59
+ ("service", "security", "user.name"),
60
+ ),
61
+ "SubjectUserSid": (
62
+ ("service", "security", "user.id"),
63
+ ),
64
+ "TargetLogonId": (
65
+ ("service", "security", "winlog.logon.id"),
66
+ ),
67
+ }
68
+
69
+ def ecs_windows():
70
+ return ProcessingPipeline(
71
+ name="Elastic Common Schema (ECS) Windows log mappings from Winlogbeat from version 7",
72
+ priority=20,
73
+ items=[
74
+ ProcessingItem( # Windows log channels
75
+ identifier=f"elasticsearch_windows_{service}",
76
+ transformation=AddConditionTransformation({ "winlog.channel": source}),
77
+ rule_conditions=[logsource_windows(service)],
78
+ )
79
+ for service, source in windows_logsource_mapping.items()
80
+ ] + [ # Variable field mappinga depending on category/service
81
+ ProcessingItem(
82
+ identifier=f"elasticsearch_windows-{field}-{logsrc_field}-{logsrc}",
83
+ transformation=FieldMappingTransformation({
84
+ field: mapped
85
+ }),
86
+ rule_conditions=[
87
+ LogsourceCondition(**{
88
+ "product": "windows",
89
+ logsrc_field: logsrc,
90
+ }),
91
+ ]
92
+ )
93
+ for field, mappings in ecs_windows_variable_mappings.items()
94
+ for (logsrc_field, logsrc, mapped) in mappings
95
+ ] + [
96
+ ProcessingItem( # Field mappings
97
+ identifier="ecs_windows_field_mapping",
98
+ transformation=FieldMappingTransformation({
99
+ "EventID": "event.code",
100
+ "Channel": "winlog.channel",
101
+ "Provider_Name": "winlog.provider_name",
102
+ "ComputerName": "winlog.computer_name",
103
+ "FileName": "file.path",
104
+ "ProcessGuid": "process.entity_id",
105
+ "ProcessId": "process.pid",
106
+ "Image": "process.executable",
107
+ "CurrentDirectory": "process.working_directory",
108
+ "ParentProcessGuid": "process.parent.entity_id",
109
+ "ParentProcessId": "process.parent.pid",
110
+ "ParentImage": "process.parent.executable",
111
+ "ParentCommandLine": "process.parent.command_line",
112
+ "TargetFilename": "file.path",
113
+ "SourceIp": "source.ip",
114
+ "SourceHostname": "source.domain",
115
+ "SourcePort": "source.port",
116
+ "DestinationIp": "destination.ip",
117
+ "DestinationHostname": "destination.domain",
118
+ "DestinationPort": "destination.port",
119
+ "DestinationPortName": "network.protocol",
120
+ "ImageLoaded": "file.path",
121
+ "Signed": "file.code_signature.signed",
122
+ "SignatureStatus": "file.code_signature.status",
123
+ "SourceProcessGuid": "process.entity_id",
124
+ "SourceProcessId": "process.pid",
125
+ "SourceImage": "process.executable",
126
+ "Device": "file.path",
127
+ "SourceThreadId": "process.thread.id",
128
+ "TargetObject": "registry.path",
129
+ "PipeName": "file.name",
130
+ "Destination": "process.executable",
131
+ "QueryName": "dns.question.name",
132
+ "QueryStatus": "sysmon.dns.status",
133
+ "IsExecutable": "sysmon.file.is_executable",
134
+ "Archived": "sysmon.file.archived",
135
+ "CommandName": "powershell.command.name",
136
+ "CommandPath": "powershell.command.path",
137
+ "CommandType": "powershell.command.type",
138
+ "HostApplication": "process.command_line",
139
+ "HostId": "process.entity_id",
140
+ "HostName": "process.title",
141
+ "NewEngineState": "powershell.engine.new_state",
142
+ "PipelineId": "powershell.pipeline_id",
143
+ "PreviousEngineState": "powershell.engine.previous_state",
144
+ "RunspaceId": "powershell.runspace_id",
145
+ "ScriptName": "file.path",
146
+ "SequenceNumber": "event.sequence",
147
+ "NewProviderState": "powershell.provider.new_state",
148
+ "ProviderName": "powershell.provider.name",
149
+ "MessageNumber": "powershell.sequence",
150
+ "MessageTotal": "powershell.total",
151
+ "ScriptBlockText": "powershell.file.script_block_text",
152
+ "ScriptBlockId": "powershell.file.script_block_id",
153
+ "AccountDomain": "user.domain",
154
+ "AccountName": "user.name",
155
+ "Application": "process.executable",
156
+ "ClientAddress": "source.ip",
157
+ "ClientName": "source.domain",
158
+ "DestAddress": "destination.ip",
159
+ "DestPort": "destination.port",
160
+ "IpAddress": "source.ip",
161
+ "IpPort": "source.port",
162
+ "NewProcessId": "process.pid",
163
+ "NewProcessName": "process.executable",
164
+ "ParentProcessName": "process.parent.name",
165
+ "ProcessName": "process.executable",
166
+ "SourceAddress": "source.ip",
167
+ "TargetDomainName": "user.domain",
168
+ "WorkstationName": "source.domain",
169
+ }),
170
+ rule_conditions=[
171
+ LogsourceCondition(product="windows")
172
+ ],
173
+ ),
174
+ ProcessingItem( # Prepend each field that was not processed by previous field mapping transformation with "winlog.event_data."
175
+ identifier="ecs_windows_winlog_eventdata_prefix",
176
+ transformation=AddFieldnamePrefixTransformation("winlog.event_data."),
177
+ detection_item_conditions=[
178
+ RuleProcessingItemAppliedCondition("ecs_windows_field_mapping"),
179
+ IncludeFieldCondition(fields=["\\w+\\."], type="re"),
180
+ ],
181
+ detection_item_condition_negation=True,
182
+ detection_item_condition_linking=any,
183
+ rule_conditions=[
184
+ LogsourceCondition(product="windows")
185
+ ],
186
+ )
187
+ ],
188
+ )
189
+
190
+ def ecs_windows_old():
191
+ return ProcessingPipeline(
192
+ name="Elastic Common Schema (ECS) Windows log mappings from Winlogbeat up to version 6",
193
+ priority=20,
194
+ items=[
195
+ ProcessingItem( # Windows log channels
196
+ identifier=f"elasticsearch_windows_{service}",
197
+ transformation=AddConditionTransformation({ "winlog.channel": source}),
198
+ rule_conditions=[logsource_windows(service)],
199
+ )
200
+ for service, source in windows_logsource_mapping.items()
201
+ ] + [
202
+ ProcessingItem( # Field mappings
203
+ identifier="ecs_windows_field_mapping",
204
+ transformation=FieldMappingTransformation({
205
+ "EventID": "event_id",
206
+ "Channel": "winlog.channel",
207
+ }),
208
+ rule_conditions=[
209
+ LogsourceCondition(product="windows")
210
+ ],
211
+ ),
212
+ ProcessingItem( # Prepend each field that was not processed by previous field mapping transformation with "winlog.event_data."
213
+ identifier="ecs_windows_eventdata_prefix",
214
+ transformation=AddFieldnamePrefixTransformation("event_data."),
215
+ detection_item_conditions=[
216
+ RuleProcessingItemAppliedCondition("ecs_windows_field_mapping"),
217
+ IncludeFieldCondition(fields=["\\w+\\."], type="re"),
218
+ ],
219
+ detection_item_condition_negation=True,
220
+ detection_item_condition_linking=any,
221
+ rule_conditions=[
222
+ LogsourceCondition(product="windows")
223
+ ],
224
+ )
225
+ ],
226
+ )