-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from SigmaHQ/analyze_logsource
Feat: Analyze logsources
- Loading branch information
Showing
5 changed files
with
188 additions
and
79 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,55 @@ | ||
import copy | ||
from typing import Dict, List | ||
from sigma.rule import SigmaRule, SigmaLevel | ||
from sigma.collection import SigmaCollection | ||
|
||
|
||
rule_level_mapping = { | ||
None: "None", | ||
SigmaLevel.INFORMATIONAL: "Informational", | ||
SigmaLevel.LOW: "Low", | ||
SigmaLevel.MEDIUM: "Medium", | ||
SigmaLevel.HIGH: "High", | ||
SigmaLevel.CRITICAL: "Critical", | ||
} | ||
|
||
template_stat_detail = { | ||
"Overall": 0, | ||
"Critical": 0, | ||
"High": 0, | ||
"Medium": 0, | ||
"Low": 0, | ||
"Informational": 0, | ||
"None": 0, | ||
} | ||
|
||
|
||
def format_row(row: str, column_widths: List) -> str: | ||
"""Format rows for table.""" | ||
return " | ".join( | ||
f"{str(item).ljust(width)}" for item, width in zip(row, column_widths) | ||
) | ||
|
||
|
||
def get_rulelevel_mapping(rule: SigmaRule) -> int: | ||
"""Calculate rule score according to rule_level_scores.""" | ||
return rule_level_mapping[rule.level] | ||
|
||
|
||
def create_logsourcestats(rules: SigmaCollection) -> Dict[str, int]: | ||
""" | ||
Iterate through all the rules and count SigmaLevel grouped by | ||
Logsource Category Name. | ||
""" | ||
stats = {} | ||
|
||
for rule in rules: | ||
if hasattr(rule, "logsource"): | ||
# Create stats key for logsource category. | ||
if not rule.logsource.category in stats: | ||
stats[rule.logsource.category] = copy.deepcopy(template_stat_detail) | ||
|
||
stats[rule.logsource.category]["Overall"] += 1 | ||
stats[rule.logsource.category][get_rulelevel_mapping(rule)] += 1 | ||
|
||
return stats |
This file contains 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
Oops, something went wrong.