pySigma-backend-athena 0.2.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_athena-0.2.0/LICENSE +8 -0
- pysigma_backend_athena-0.2.0/PKG-INFO +300 -0
- pysigma_backend_athena-0.2.0/README.md +271 -0
- pysigma_backend_athena-0.2.0/pyproject.toml +55 -0
- pysigma_backend_athena-0.2.0/sigma/backends/athena/__init__.py +3 -0
- pysigma_backend_athena-0.2.0/sigma/backends/athena/base.py +403 -0
- pysigma_backend_athena-0.2.0/sigma/backends/athena/correlations.py +267 -0
- pysigma_backend_athena-0.2.0/sigma/pipelines/athena/__init__.py +3 -0
- pysigma_backend_athena-0.2.0/sigma/pipelines/athena/athena.py +106 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
|
|
2
|
+
Copyright 2025 Neil Smith
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pySigma-backend-athena
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: pySigma athena backend
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: sigma,pySigma,athena,aws
|
|
8
|
+
Author: Neil Smith
|
|
9
|
+
Author-email: neil@nsmith.net
|
|
10
|
+
Requires-Python: >=3.11,<4.0
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
22
|
+
Requires-Dist: pysigma (>=2.2.0,<3.0.0)
|
|
23
|
+
Project-URL: Documentation, https://github.com/nsmithuk/pySigma-backend-athena#readme
|
|
24
|
+
Project-URL: Homepage, https://github.com/nsmithuk/pySigma-backend-athena
|
|
25
|
+
Project-URL: Issues, https://github.com/nsmithuk/pySigma-backend-athena/issues
|
|
26
|
+
Project-URL: Source, https://github.com/nsmithuk/pySigma-backend-athena
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+

|
|
31
|
+

|
|
32
|
+
|
|
33
|
+
# pySigma Athena Backend
|
|
34
|
+
|
|
35
|
+
An AWS Athena backend for pySigma that converts Sigma detection rules into Athena-compatible SQL queries.
|
|
36
|
+
|
|
37
|
+
While designed for AWS Athena, it likely works with any Trino-based SQL engine.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
Most standard Sigma rule features are supported, including logical and comparison operators,
|
|
44
|
+
wildcards, regular expressions, CIDR matching, field reference matching, existence checks and case-sensitive matching.
|
|
45
|
+
A handful of operations—like full-text value-only expressions and distinct-count window
|
|
46
|
+
functions—aren't implemented; see the Limitations section below.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
## Limitations
|
|
50
|
+
|
|
51
|
+
- Full-text searches (value-only expressions) are not supported.
|
|
52
|
+
- At present, only the `event_count` correlation rule type is supported.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
[//]: # (## Installation)
|
|
57
|
+
|
|
58
|
+
[//]: # ()
|
|
59
|
+
[//]: # (Install via pip:)
|
|
60
|
+
|
|
61
|
+
[//]: # ()
|
|
62
|
+
[//]: # (```bash)
|
|
63
|
+
|
|
64
|
+
[//]: # (pip install pySigma-backend-athena)
|
|
65
|
+
|
|
66
|
+
[//]: # (```)
|
|
67
|
+
|
|
68
|
+
[//]: # ()
|
|
69
|
+
[//]: # (Or with Poetry:)
|
|
70
|
+
|
|
71
|
+
[//]: # ()
|
|
72
|
+
[//]: # (```bash)
|
|
73
|
+
|
|
74
|
+
[//]: # (poetry add pySigma-backend-athena)
|
|
75
|
+
|
|
76
|
+
[//]: # (```)
|
|
77
|
+
|
|
78
|
+
[//]: # ()
|
|
79
|
+
[//]: # (---)
|
|
80
|
+
|
|
81
|
+
## Usage
|
|
82
|
+
|
|
83
|
+
From the CLI:
|
|
84
|
+
```shell
|
|
85
|
+
sigma convert -t athena rules/cloud/aws/cloudtrail/
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
From Python:
|
|
89
|
+
```python
|
|
90
|
+
from sigma.backends.athena import athenaBackend
|
|
91
|
+
from sigma.collection import SigmaCollection
|
|
92
|
+
|
|
93
|
+
# Initialize the backend, optionally specifying table, fields, and time field
|
|
94
|
+
backend = athenaBackend()
|
|
95
|
+
|
|
96
|
+
# Load your Sigma rule collection
|
|
97
|
+
collection = SigmaCollection.from_yaml("...")
|
|
98
|
+
|
|
99
|
+
# Convert to Athena SQL
|
|
100
|
+
queries = backend.convert(collection)
|
|
101
|
+
for q in queries:
|
|
102
|
+
print(q)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Set Table Name
|
|
106
|
+
|
|
107
|
+
There are a few ways of setting the table name that will appear in the SQL.
|
|
108
|
+
|
|
109
|
+
If all of your rules use the same table name, regardless of the `logsource` set, you can pass a backend-option of `table`.
|
|
110
|
+
|
|
111
|
+
For example:
|
|
112
|
+
```python
|
|
113
|
+
athena_backend = athenaBackend(table="events")
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Will result in:
|
|
117
|
+
```sql
|
|
118
|
+
SELECT * FROM events WHERE ...
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
If you need to set your table name based on the `logsource` seen, you can use a pipeline. The backend will look for a
|
|
122
|
+
processing state value of `table_name` and, if set, will use this table name.
|
|
123
|
+
|
|
124
|
+
For example:
|
|
125
|
+
```yaml
|
|
126
|
+
name: AWS Security Lake Table Mapping
|
|
127
|
+
priority: 100
|
|
128
|
+
|
|
129
|
+
vars:
|
|
130
|
+
region: eu_west_2
|
|
131
|
+
|
|
132
|
+
transformations:
|
|
133
|
+
- id: cloudtrail_mgmt_table
|
|
134
|
+
type: set_state
|
|
135
|
+
key: table_name
|
|
136
|
+
val: "amazon_security_lake_table_{region}_cloud_trail_mgmt_2_0"
|
|
137
|
+
rule_conditions:
|
|
138
|
+
- type: logsource
|
|
139
|
+
product: aws
|
|
140
|
+
service: cloudtrail
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Set Table Name with AWS Security Lake
|
|
144
|
+
|
|
145
|
+
If you are using this backend with AWS Security Lake, a helper plugin is also provided for setting the correct table name.
|
|
146
|
+
|
|
147
|
+
For example, the following will map an AWS CloudTrail source to `amazon_security_lake_table_eu_west_2_cloud_trail_mgmt_2_0`.
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from sigma.pipelines.athena import athena_pipeline_security_lake_table_name
|
|
151
|
+
from sigma.backends.athena import athenaBackend
|
|
152
|
+
from sigma.collection import SigmaCollection
|
|
153
|
+
|
|
154
|
+
pipeline = athena_pipeline_security_lake_table_name()
|
|
155
|
+
backend = athenaBackend(
|
|
156
|
+
aws_table_region="eu-west-2", # Replace with your AWS region
|
|
157
|
+
processing_pipeline=pipeline,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
rules = SigmaCollection.load_ruleset("path/to/rules/")
|
|
161
|
+
queries = backend.convert(rules)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
This supports the following log sources:
|
|
165
|
+
* product: `aws`, service: `cloudtrail`
|
|
166
|
+
* product: `aws`, service: `cloudtrail_s3`
|
|
167
|
+
* product: `aws`, service: `cloudtrail_lambda`
|
|
168
|
+
* product: `aws`, service: `route53`
|
|
169
|
+
* product: `aws`, service: `security_hub`
|
|
170
|
+
* product: `aws`, service: `vpc_flow_logs`
|
|
171
|
+
* product: `aws`, service: `waf`
|
|
172
|
+
* product: `aws`, service: `eks_audit`
|
|
173
|
+
|
|
174
|
+
You can also use this pipeline from the CLI:
|
|
175
|
+
```shell
|
|
176
|
+
sigma convert -t athena -O aws_table_region=eu-west-2 -p athena_security_lake_table_name rules/cloud/aws/cloudtrail/
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Select Column Names
|
|
180
|
+
|
|
181
|
+
The backend supports the [fields](https://sigmahq.io/sigma-specification/specification/sigma-rules-specification.html#fields) attribute in Sigma rules.
|
|
182
|
+
If a Sigma rule specifies a list of fields, the generated Athena SQL query will SELECT only those specified fields instead of using `SELECT *`.
|
|
183
|
+
|
|
184
|
+
This is useful for optimising queries by retrieving only necessary data.
|
|
185
|
+
|
|
186
|
+
For example, if your Sigma rule includes:
|
|
187
|
+
```yaml
|
|
188
|
+
fields:
|
|
189
|
+
- uid
|
|
190
|
+
- time_dt
|
|
191
|
+
- process.command_line as command_line
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
The generated query will start with:
|
|
195
|
+
```sql
|
|
196
|
+
SELECT uid, time_dt, process.command_line as command_line FROM ...
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
If no `fields` are specified in the rule, the query defaults to `SELECT *`.
|
|
200
|
+
|
|
201
|
+
This feature is automatically applied when converting rules with the backend.
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## Supported Correlation Rules
|
|
206
|
+
|
|
207
|
+
The Athena backend currently supports **event\_count** correlation rules. Other types (`value_count`, `temporal`, `temporal_ordered`) are not implemented and will raise `NotImplementedError`.
|
|
208
|
+
|
|
209
|
+
### event\_count
|
|
210
|
+
|
|
211
|
+
- **Type**: `event_count`
|
|
212
|
+
- **Parameters**:
|
|
213
|
+
- `rules`: List of Sigma rules to correlate
|
|
214
|
+
- `group-by`: Fields to partition by
|
|
215
|
+
- `timespan`: Window duration (e.g. `15m`, `1h`)
|
|
216
|
+
- `condition`: Comparison operator and threshold (e.g. `gte: 10`)
|
|
217
|
+
|
|
218
|
+
Generates a sliding time window-function query that counts matching events within the specified timeframe.
|
|
219
|
+
|
|
220
|
+
#### Example
|
|
221
|
+
|
|
222
|
+
```yaml
|
|
223
|
+
title: Windows Failed Logon
|
|
224
|
+
id: dc9f1a2e-7d3b-4f1c-b8f4-1e23eadf4567
|
|
225
|
+
status: stable
|
|
226
|
+
logsource:
|
|
227
|
+
product: windows
|
|
228
|
+
service: security
|
|
229
|
+
detection:
|
|
230
|
+
selection:
|
|
231
|
+
EventID: 4625
|
|
232
|
+
condition: selection
|
|
233
|
+
---
|
|
234
|
+
title: Possible Brute-Force Attack via Repeated Logon Failures
|
|
235
|
+
id: e8b2c3d4-5f6a-7b8c-9d0e-f1a2b3c4d5e6
|
|
236
|
+
status: stable
|
|
237
|
+
description: Detects more than 5 failed Windows logon attempts from the same source IP within 10 minutes.
|
|
238
|
+
correlation:
|
|
239
|
+
type: event_count
|
|
240
|
+
rules:
|
|
241
|
+
- dc9f1a2e-7d3b-4f1c-b8f4-1e23eadf4567
|
|
242
|
+
group-by:
|
|
243
|
+
- SourceIp
|
|
244
|
+
timespan: 10m
|
|
245
|
+
condition:
|
|
246
|
+
gte: 5
|
|
247
|
+
```
|
|
248
|
+
Gives:
|
|
249
|
+
```sql
|
|
250
|
+
WITH combined_events AS (
|
|
251
|
+
SELECT *
|
|
252
|
+
FROM <TABLE>
|
|
253
|
+
WHERE EventID = 4625
|
|
254
|
+
),
|
|
255
|
+
event_counts AS (
|
|
256
|
+
SELECT *,
|
|
257
|
+
COUNT(*) OVER (
|
|
258
|
+
PARTITION BY SourceIp
|
|
259
|
+
ORDER BY time
|
|
260
|
+
RANGE BETWEEN INTERVAL '600' SECOND PRECEDING AND CURRENT ROW
|
|
261
|
+
) AS correlation_event_count
|
|
262
|
+
FROM combined_events
|
|
263
|
+
)
|
|
264
|
+
SELECT *
|
|
265
|
+
FROM event_counts
|
|
266
|
+
WHERE correlation_event_count >= 5;
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Specifying the DateTime column to use for the time window
|
|
270
|
+
|
|
271
|
+
By default, the `time` column is used for the rule's sliding time window. This can be changed by setting the
|
|
272
|
+
`time_field` backend-option.
|
|
273
|
+
|
|
274
|
+
For example:
|
|
275
|
+
```python
|
|
276
|
+
athena_backend = athenaBackend(time_field="time_dt")
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## Testing
|
|
282
|
+
|
|
283
|
+
Run the test suite:
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
pytest
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Maintainers
|
|
292
|
+
|
|
293
|
+
- [Neil Smith](https://github.com/nsmithuk/)
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## License
|
|
298
|
+
|
|
299
|
+
Licensed under the [MIT License](LICENSE).
|
|
300
|
+
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+

|
|
2
|
+

|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
# pySigma Athena Backend
|
|
6
|
+
|
|
7
|
+
An AWS Athena backend for pySigma that converts Sigma detection rules into Athena-compatible SQL queries.
|
|
8
|
+
|
|
9
|
+
While designed for AWS Athena, it likely works with any Trino-based SQL engine.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
Most standard Sigma rule features are supported, including logical and comparison operators,
|
|
16
|
+
wildcards, regular expressions, CIDR matching, field reference matching, existence checks and case-sensitive matching.
|
|
17
|
+
A handful of operations—like full-text value-only expressions and distinct-count window
|
|
18
|
+
functions—aren't implemented; see the Limitations section below.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Limitations
|
|
22
|
+
|
|
23
|
+
- Full-text searches (value-only expressions) are not supported.
|
|
24
|
+
- At present, only the `event_count` correlation rule type is supported.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
[//]: # (## Installation)
|
|
29
|
+
|
|
30
|
+
[//]: # ()
|
|
31
|
+
[//]: # (Install via pip:)
|
|
32
|
+
|
|
33
|
+
[//]: # ()
|
|
34
|
+
[//]: # (```bash)
|
|
35
|
+
|
|
36
|
+
[//]: # (pip install pySigma-backend-athena)
|
|
37
|
+
|
|
38
|
+
[//]: # (```)
|
|
39
|
+
|
|
40
|
+
[//]: # ()
|
|
41
|
+
[//]: # (Or with Poetry:)
|
|
42
|
+
|
|
43
|
+
[//]: # ()
|
|
44
|
+
[//]: # (```bash)
|
|
45
|
+
|
|
46
|
+
[//]: # (poetry add pySigma-backend-athena)
|
|
47
|
+
|
|
48
|
+
[//]: # (```)
|
|
49
|
+
|
|
50
|
+
[//]: # ()
|
|
51
|
+
[//]: # (---)
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
From the CLI:
|
|
56
|
+
```shell
|
|
57
|
+
sigma convert -t athena rules/cloud/aws/cloudtrail/
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
From Python:
|
|
61
|
+
```python
|
|
62
|
+
from sigma.backends.athena import athenaBackend
|
|
63
|
+
from sigma.collection import SigmaCollection
|
|
64
|
+
|
|
65
|
+
# Initialize the backend, optionally specifying table, fields, and time field
|
|
66
|
+
backend = athenaBackend()
|
|
67
|
+
|
|
68
|
+
# Load your Sigma rule collection
|
|
69
|
+
collection = SigmaCollection.from_yaml("...")
|
|
70
|
+
|
|
71
|
+
# Convert to Athena SQL
|
|
72
|
+
queries = backend.convert(collection)
|
|
73
|
+
for q in queries:
|
|
74
|
+
print(q)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Set Table Name
|
|
78
|
+
|
|
79
|
+
There are a few ways of setting the table name that will appear in the SQL.
|
|
80
|
+
|
|
81
|
+
If all of your rules use the same table name, regardless of the `logsource` set, you can pass a backend-option of `table`.
|
|
82
|
+
|
|
83
|
+
For example:
|
|
84
|
+
```python
|
|
85
|
+
athena_backend = athenaBackend(table="events")
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Will result in:
|
|
89
|
+
```sql
|
|
90
|
+
SELECT * FROM events WHERE ...
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
If you need to set your table name based on the `logsource` seen, you can use a pipeline. The backend will look for a
|
|
94
|
+
processing state value of `table_name` and, if set, will use this table name.
|
|
95
|
+
|
|
96
|
+
For example:
|
|
97
|
+
```yaml
|
|
98
|
+
name: AWS Security Lake Table Mapping
|
|
99
|
+
priority: 100
|
|
100
|
+
|
|
101
|
+
vars:
|
|
102
|
+
region: eu_west_2
|
|
103
|
+
|
|
104
|
+
transformations:
|
|
105
|
+
- id: cloudtrail_mgmt_table
|
|
106
|
+
type: set_state
|
|
107
|
+
key: table_name
|
|
108
|
+
val: "amazon_security_lake_table_{region}_cloud_trail_mgmt_2_0"
|
|
109
|
+
rule_conditions:
|
|
110
|
+
- type: logsource
|
|
111
|
+
product: aws
|
|
112
|
+
service: cloudtrail
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Set Table Name with AWS Security Lake
|
|
116
|
+
|
|
117
|
+
If you are using this backend with AWS Security Lake, a helper plugin is also provided for setting the correct table name.
|
|
118
|
+
|
|
119
|
+
For example, the following will map an AWS CloudTrail source to `amazon_security_lake_table_eu_west_2_cloud_trail_mgmt_2_0`.
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from sigma.pipelines.athena import athena_pipeline_security_lake_table_name
|
|
123
|
+
from sigma.backends.athena import athenaBackend
|
|
124
|
+
from sigma.collection import SigmaCollection
|
|
125
|
+
|
|
126
|
+
pipeline = athena_pipeline_security_lake_table_name()
|
|
127
|
+
backend = athenaBackend(
|
|
128
|
+
aws_table_region="eu-west-2", # Replace with your AWS region
|
|
129
|
+
processing_pipeline=pipeline,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
rules = SigmaCollection.load_ruleset("path/to/rules/")
|
|
133
|
+
queries = backend.convert(rules)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
This supports the following log sources:
|
|
137
|
+
* product: `aws`, service: `cloudtrail`
|
|
138
|
+
* product: `aws`, service: `cloudtrail_s3`
|
|
139
|
+
* product: `aws`, service: `cloudtrail_lambda`
|
|
140
|
+
* product: `aws`, service: `route53`
|
|
141
|
+
* product: `aws`, service: `security_hub`
|
|
142
|
+
* product: `aws`, service: `vpc_flow_logs`
|
|
143
|
+
* product: `aws`, service: `waf`
|
|
144
|
+
* product: `aws`, service: `eks_audit`
|
|
145
|
+
|
|
146
|
+
You can also use this pipeline from the CLI:
|
|
147
|
+
```shell
|
|
148
|
+
sigma convert -t athena -O aws_table_region=eu-west-2 -p athena_security_lake_table_name rules/cloud/aws/cloudtrail/
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Select Column Names
|
|
152
|
+
|
|
153
|
+
The backend supports the [fields](https://sigmahq.io/sigma-specification/specification/sigma-rules-specification.html#fields) attribute in Sigma rules.
|
|
154
|
+
If a Sigma rule specifies a list of fields, the generated Athena SQL query will SELECT only those specified fields instead of using `SELECT *`.
|
|
155
|
+
|
|
156
|
+
This is useful for optimising queries by retrieving only necessary data.
|
|
157
|
+
|
|
158
|
+
For example, if your Sigma rule includes:
|
|
159
|
+
```yaml
|
|
160
|
+
fields:
|
|
161
|
+
- uid
|
|
162
|
+
- time_dt
|
|
163
|
+
- process.command_line as command_line
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
The generated query will start with:
|
|
167
|
+
```sql
|
|
168
|
+
SELECT uid, time_dt, process.command_line as command_line FROM ...
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
If no `fields` are specified in the rule, the query defaults to `SELECT *`.
|
|
172
|
+
|
|
173
|
+
This feature is automatically applied when converting rules with the backend.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Supported Correlation Rules
|
|
178
|
+
|
|
179
|
+
The Athena backend currently supports **event\_count** correlation rules. Other types (`value_count`, `temporal`, `temporal_ordered`) are not implemented and will raise `NotImplementedError`.
|
|
180
|
+
|
|
181
|
+
### event\_count
|
|
182
|
+
|
|
183
|
+
- **Type**: `event_count`
|
|
184
|
+
- **Parameters**:
|
|
185
|
+
- `rules`: List of Sigma rules to correlate
|
|
186
|
+
- `group-by`: Fields to partition by
|
|
187
|
+
- `timespan`: Window duration (e.g. `15m`, `1h`)
|
|
188
|
+
- `condition`: Comparison operator and threshold (e.g. `gte: 10`)
|
|
189
|
+
|
|
190
|
+
Generates a sliding time window-function query that counts matching events within the specified timeframe.
|
|
191
|
+
|
|
192
|
+
#### Example
|
|
193
|
+
|
|
194
|
+
```yaml
|
|
195
|
+
title: Windows Failed Logon
|
|
196
|
+
id: dc9f1a2e-7d3b-4f1c-b8f4-1e23eadf4567
|
|
197
|
+
status: stable
|
|
198
|
+
logsource:
|
|
199
|
+
product: windows
|
|
200
|
+
service: security
|
|
201
|
+
detection:
|
|
202
|
+
selection:
|
|
203
|
+
EventID: 4625
|
|
204
|
+
condition: selection
|
|
205
|
+
---
|
|
206
|
+
title: Possible Brute-Force Attack via Repeated Logon Failures
|
|
207
|
+
id: e8b2c3d4-5f6a-7b8c-9d0e-f1a2b3c4d5e6
|
|
208
|
+
status: stable
|
|
209
|
+
description: Detects more than 5 failed Windows logon attempts from the same source IP within 10 minutes.
|
|
210
|
+
correlation:
|
|
211
|
+
type: event_count
|
|
212
|
+
rules:
|
|
213
|
+
- dc9f1a2e-7d3b-4f1c-b8f4-1e23eadf4567
|
|
214
|
+
group-by:
|
|
215
|
+
- SourceIp
|
|
216
|
+
timespan: 10m
|
|
217
|
+
condition:
|
|
218
|
+
gte: 5
|
|
219
|
+
```
|
|
220
|
+
Gives:
|
|
221
|
+
```sql
|
|
222
|
+
WITH combined_events AS (
|
|
223
|
+
SELECT *
|
|
224
|
+
FROM <TABLE>
|
|
225
|
+
WHERE EventID = 4625
|
|
226
|
+
),
|
|
227
|
+
event_counts AS (
|
|
228
|
+
SELECT *,
|
|
229
|
+
COUNT(*) OVER (
|
|
230
|
+
PARTITION BY SourceIp
|
|
231
|
+
ORDER BY time
|
|
232
|
+
RANGE BETWEEN INTERVAL '600' SECOND PRECEDING AND CURRENT ROW
|
|
233
|
+
) AS correlation_event_count
|
|
234
|
+
FROM combined_events
|
|
235
|
+
)
|
|
236
|
+
SELECT *
|
|
237
|
+
FROM event_counts
|
|
238
|
+
WHERE correlation_event_count >= 5;
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Specifying the DateTime column to use for the time window
|
|
242
|
+
|
|
243
|
+
By default, the `time` column is used for the rule's sliding time window. This can be changed by setting the
|
|
244
|
+
`time_field` backend-option.
|
|
245
|
+
|
|
246
|
+
For example:
|
|
247
|
+
```python
|
|
248
|
+
athena_backend = athenaBackend(time_field="time_dt")
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## Testing
|
|
254
|
+
|
|
255
|
+
Run the test suite:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
pytest
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Maintainers
|
|
264
|
+
|
|
265
|
+
- [Neil Smith](https://github.com/nsmithuk/)
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## License
|
|
270
|
+
|
|
271
|
+
Licensed under the [MIT License](LICENSE).
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pySigma-backend-athena"
|
|
3
|
+
dynamic = [ "version", "classifiers" ]
|
|
4
|
+
description = "pySigma athena backend"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11,<4.0"
|
|
7
|
+
license = { text = "MIT" }
|
|
8
|
+
keywords = ["sigma", "pySigma", "athena", "aws"]
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "Neil Smith", email = "neil@nsmith.net" },
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
[project.urls]
|
|
15
|
+
Homepage = "https://github.com/nsmithuk/pySigma-backend-athena"
|
|
16
|
+
Documentation = "https://github.com/nsmithuk/pySigma-backend-athena#readme"
|
|
17
|
+
Issues = "https://github.com/nsmithuk/pySigma-backend-athena/issues"
|
|
18
|
+
Source = "https://github.com/nsmithuk/pySigma-backend-athena"
|
|
19
|
+
|
|
20
|
+
[tool.poetry]
|
|
21
|
+
version = "0.2.0"
|
|
22
|
+
repository = "https://github.com/nsmithuk/pySigma-backend-athena"
|
|
23
|
+
readme = "README.md"
|
|
24
|
+
classifiers = [
|
|
25
|
+
"Development Status :: 4 - Beta",
|
|
26
|
+
"Programming Language :: Python",
|
|
27
|
+
"Programming Language :: Python :: 3.10",
|
|
28
|
+
"Programming Language :: Python :: 3.11",
|
|
29
|
+
"Programming Language :: Python :: 3.12",
|
|
30
|
+
"Programming Language :: Python :: 3.13",
|
|
31
|
+
"Programming Language :: Python :: 3.14",
|
|
32
|
+
"Programming Language :: Python :: Implementation :: PyPy",
|
|
33
|
+
]
|
|
34
|
+
packages = [
|
|
35
|
+
{ include = "sigma" }
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[tool.poetry.dependencies]
|
|
39
|
+
python = "^3.11"
|
|
40
|
+
pysigma = "^2.2.0"
|
|
41
|
+
|
|
42
|
+
[tool.poetry.group.dev.dependencies]
|
|
43
|
+
defusedxml = "^0.7"
|
|
44
|
+
pytest = "^9.2.0"
|
|
45
|
+
pytest-cov = "^7.1.0"
|
|
46
|
+
coverage = "^7.18.0"
|
|
47
|
+
black = "^26.10.1"
|
|
48
|
+
isort = "^9.0.2"
|
|
49
|
+
|
|
50
|
+
[tool.isort]
|
|
51
|
+
profile = "black"
|
|
52
|
+
|
|
53
|
+
[build-system]
|
|
54
|
+
requires = ["poetry-core>=1.8.1"]
|
|
55
|
+
build-backend = "poetry.core.masonry.api"
|