-
Notifications
You must be signed in to change notification settings - Fork 9
Add Correlation Support #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f9f3f49
update related tests
nasbench ae8a2d2
rename folder
nasbench 340390b
apply black formatting
nasbench 0202dd1
Update pyproject.toml
nasbench 5993509
Update sigma/validators/sigmahq/filename.py
nasbench f3ea5cb
Update tests/test_correlation.py
nasbench bf58e15
Update test_correlation.py
nasbench File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| from dataclasses import dataclass | ||
| from typing import ClassVar, List | ||
|
|
||
| from sigma.correlations import SigmaCorrelationRule, SigmaCorrelationType | ||
| from sigma.rule import SigmaRuleBase | ||
| from sigma.validators.base import ( | ||
| SigmaRuleValidator, | ||
| SigmaValidationIssue, | ||
| SigmaValidationIssueSeverity, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class SigmahqCorrelationRulesMinimumIssue(SigmaValidationIssue): | ||
| description: ClassVar[str] = ( | ||
| "Correlation rule must reference at least 2 rules for temporal types" | ||
| ) | ||
| severity: ClassVar[SigmaValidationIssueSeverity] = SigmaValidationIssueSeverity.HIGH | ||
|
|
||
|
|
||
| class SigmahqCorrelationRulesMinimumValidator(SigmaRuleValidator): | ||
| """Checks if temporal correlation rules have at least 2 rules.""" | ||
|
|
||
| def validate(self, rule: SigmaRuleBase) -> List[SigmaValidationIssue]: | ||
| if isinstance(rule, SigmaCorrelationRule): | ||
| if rule.type in [SigmaCorrelationType.TEMPORAL, SigmaCorrelationType.TEMPORAL_ORDERED]: | ||
| if len(rule.rules) < 2: | ||
| return [SigmahqCorrelationRulesMinimumIssue([rule])] | ||
| return [] | ||
|
|
||
|
|
||
| @dataclass | ||
| class SigmahqCorrelationGroupByExistenceIssue(SigmaValidationIssue): | ||
| description: ClassVar[str] = ( | ||
| "Correlation rule is missing the group-by field in correlation section" | ||
| ) | ||
| severity: ClassVar[SigmaValidationIssueSeverity] = SigmaValidationIssueSeverity.HIGH | ||
|
|
||
|
|
||
| class SigmahqCorrelationGroupByExistenceValidator(SigmaRuleValidator): | ||
| """Checks if a correlation rule has a group-by field for types that require it.""" | ||
|
|
||
| def validate(self, rule: SigmaRuleBase) -> List[SigmaValidationIssue]: | ||
| if isinstance(rule, SigmaCorrelationRule): | ||
| if rule.type in [ | ||
| SigmaCorrelationType.EVENT_COUNT, | ||
| SigmaCorrelationType.VALUE_COUNT, | ||
| SigmaCorrelationType.TEMPORAL, | ||
| SigmaCorrelationType.TEMPORAL_ORDERED, | ||
| ]: | ||
| if rule.group_by is None or len(rule.group_by) == 0: | ||
| return [SigmahqCorrelationGroupByExistenceIssue([rule])] | ||
| return [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
tests/files/rules-correlations/correlation_combined_format.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| title: Test Detection Rule in Combined File | ||
| id: aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa | ||
| status: test | ||
| description: This is a test detection rule in a combined format file | ||
| author: Test Author | ||
| date: 2024-01-01 | ||
| level: medium | ||
| logsource: | ||
| category: process_creation | ||
| product: windows | ||
| detection: | ||
| selection: | ||
| Image|endswith: '\test.exe' | ||
| condition: selection | ||
| falsepositives: | ||
| - Unknown | ||
| --- | ||
| title: Test Correlation Rule in Combined File | ||
| id: bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb | ||
| status: test | ||
| description: This is a test correlation rule in a combined format file | ||
| author: Test Author | ||
| date: 2024-01-01 | ||
| level: high | ||
| correlation: | ||
| type: event_count | ||
| rules: | ||
| - aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa | ||
| group-by: | ||
| - Computer | ||
| timespan: 5m | ||
| condition: | ||
| gte: 10 |
16 changes: 16 additions & 0 deletions
16
tests/files/rules-correlations/correlation_valid_filename.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| title: Test Correlation Rule With Correct Filename | ||
| id: 12345678-1234-1234-1234-123456789012 | ||
| status: test | ||
| description: This is a test correlation rule with a correctly named file | ||
| author: Test Author | ||
| date: 2024-01-01 | ||
| level: high | ||
| correlation: | ||
| type: event_count | ||
| rules: | ||
| - 87654321-4321-4321-4321-210987654321 | ||
| group-by: | ||
| - Computer | ||
| timespan: 5m | ||
| condition: | ||
| gte: 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| title: Test Correlation Rule With Incorrect Filename | ||
| id: 98765432-9876-9876-9876-987654321098 | ||
| status: test | ||
| description: This is a test correlation rule with an incorrectly named file | ||
| author: Test Author | ||
| date: 2024-01-01 | ||
| level: high | ||
| correlation: | ||
| type: event_count | ||
| rules: | ||
| - 87654321-4321-4321-4321-210987654321 | ||
| group-by: | ||
| - Computer | ||
| timespan: 5m | ||
| condition: | ||
| gte: 10 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.