Skip to content

Commit 3f24987

Browse files
authored
Merge pull request #191 from UncoderIO/gis-8503
Gis 8503
2 parents 2c82341 + 51cdf69 commit 3f24987

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from app.translator.platforms.splunk.parsers.splunk import SplunkQueryParser # noqa: F401
2-
from app.translator.platforms.splunk.parsers.splunk_alert import SplunkAlertParser # noqa: F401
2+
from app.translator.platforms.splunk.parsers.splunk_alert import SplunkAlertParser, SplunkAlertYMLParser # noqa: F401
33
from app.translator.platforms.splunk.renders.splunk import SplunkQueryRender # noqa: F401
44
from app.translator.platforms.splunk.renders.splunk_alert import SplunkAlertRender # noqa: F401
55
from app.translator.platforms.splunk.renders.splunk_cti import SplunkCTI # noqa: F401

uncoder-core/app/translator/platforms/splunk/const.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,14 @@
4242
**PLATFORM_DETAILS,
4343
}
4444

45+
SPLUNK_ALERT_YML_DETAILS = {
46+
"platform_id": "splunk-spl-rule-yml",
47+
"name": "Splunk Alert YML",
48+
"platform_name": "Alert (SPL) YML",
49+
"first_choice": 0,
50+
**PLATFORM_DETAILS,
51+
}
52+
4553
splunk_query_details = PlatformDetails(**SPLUNK_QUERY_DETAILS)
4654
splunk_alert_details = PlatformDetails(**SPLUNK_ALERT_DETAILS)
55+
splunk_alert_yml_details = PlatformDetails(**SPLUNK_ALERT_YML_DETAILS)

uncoder-core/app/translator/platforms/splunk/parsers/splunk_alert.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020

2121
from app.translator.core.custom_types.meta_info import SeverityType
2222
from app.translator.core.mitre import MitreConfig
23+
from app.translator.core.mixins.rule import YamlRuleMixin
2324
from app.translator.core.models.platform_details import PlatformDetails
2425
from app.translator.core.models.query_container import MetaInfoContainer, MitreInfoContainer, RawQueryContainer
2526
from app.translator.managers import parser_manager
26-
from app.translator.platforms.splunk.const import splunk_alert_details
27+
from app.translator.platforms.splunk.const import splunk_alert_details, splunk_alert_yml_details
2728
from app.translator.platforms.splunk.mapping import SplunkMappings, splunk_alert_mappings
2829
from app.translator.platforms.splunk.parsers.splunk import SplunkQueryParser
2930

@@ -73,3 +74,45 @@ def parse_raw_query(self, text: str, language: str) -> RawQueryContainer:
7374
mitre_attack=mitre_attack_container,
7475
),
7576
)
77+
78+
79+
@parser_manager.register
80+
class SplunkAlertYMLParser(SplunkQueryParser, YamlRuleMixin):
81+
details: PlatformDetails = splunk_alert_yml_details
82+
mappings: SplunkMappings = splunk_alert_mappings
83+
mitre_config: MitreConfig = MitreConfig()
84+
85+
def parse_raw_query(self, text: str, language: str) -> RawQueryContainer:
86+
rule = self.load_rule(text)
87+
mitre_attack_container = self.mitre_config.get_mitre_info(
88+
techniques=rule.get("tags", {}).get("mitre_attack_id", [])
89+
)
90+
description = rule.get("description", "")
91+
if rule.get("how_to_implement", ""):
92+
description = f'{description} {rule.get("how_to_implement", "")}'
93+
tags = rule.get("tags", {}).get("analytic_story", [])
94+
if rule.get("type"):
95+
tags.append(rule.get("type"))
96+
false_positives = None
97+
if rule.get("known_false_positives"):
98+
false_positives = (
99+
rule["known_false_positives"]
100+
if isinstance(rule["known_false_positives"], list)
101+
else [rule["known_false_positives"]]
102+
)
103+
return RawQueryContainer(
104+
query=rule.get("search"),
105+
language=language,
106+
meta_info=MetaInfoContainer(
107+
id_=rule.get("id"),
108+
title=rule.get("name"),
109+
date=rule.get("date"),
110+
author=rule.get("author").split(", "),
111+
status=rule.get("status"),
112+
description=description,
113+
false_positives=false_positives,
114+
references=rule.get("references"),
115+
mitre_attack=mitre_attack_container,
116+
tags=tags,
117+
),
118+
)

0 commit comments

Comments
 (0)