Skip to content

Commit 48e31d3

Browse files
authored
Merge pull request #191 from splunk/variable_severity
improve output of risk severity field.
2 parents f85ccbd + 307d8f1 commit 48e31d3

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

contentctl/objects/detection_tags.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@
2323
from contentctl.objects.mitre_attack_enrichment import MitreAttackEnrichment
2424
from contentctl.objects.constants import ATTACK_TACTICS_KILLCHAIN_MAPPING
2525
from contentctl.objects.observable import Observable
26+
from contentctl.objects.enums import Cis18Value, AssetType, SecurityDomain, RiskSeverity, KillChainPhase, NistCategory, SecurityContentProductName
2627
from contentctl.objects.enums import (
2728
Cis18Value,
2829
AssetType,
2930
SecurityDomain,
3031
RiskSeverity,
3132
KillChainPhase,
3233
NistCategory,
33-
RiskLevel,
3434
SecurityContentProductName
3535
)
36+
3637
from contentctl.objects.atomic import AtomicTest
3738
from contentctl.objects.annotated_types import MITRE_ATTACK_ID_TYPE, CVE_TYPE
3839

@@ -50,6 +51,23 @@ class DetectionTags(BaseModel):
5051
@property
5152
def risk_score(self) -> int:
5253
return round((self.confidence * self.impact)/100)
54+
55+
@computed_field
56+
@property
57+
def severity(self)->RiskSeverity:
58+
if 0 <= self.risk_score <= 20:
59+
return RiskSeverity.INFO
60+
elif 20 < self.risk_score <= 40:
61+
return RiskSeverity.LOW
62+
elif 40 < self.risk_score <= 60:
63+
return RiskSeverity.MEDIUM
64+
elif 60 < self.risk_score <= 80:
65+
return RiskSeverity.HIGH
66+
elif 80 < self.risk_score <= 100:
67+
return RiskSeverity.CRITICAL
68+
else:
69+
raise Exception(f"Error getting severity - risk_score must be between 0-100, but was actually {self.risk_score}")
70+
5371

5472
mitre_attack_id: List[MITRE_ATTACK_ID_TYPE] = []
5573
nist: list[NistCategory] = []
@@ -59,17 +77,6 @@ def risk_score(self) -> int:
5977
required_fields: list[str] = Field(min_length=1)
6078
throttling: Optional[Throttling] = None
6179
security_domain: SecurityDomain = Field(...)
62-
63-
@computed_field
64-
@property
65-
def risk_severity(self) -> RiskSeverity:
66-
if self.risk_score >= 80:
67-
return RiskSeverity('high')
68-
elif (self.risk_score >= 50 and self.risk_score <= 79):
69-
return RiskSeverity('medium')
70-
else:
71-
return RiskSeverity('low')
72-
7380
cve: List[CVE_TYPE] = []
7481
atomic_guid: List[AtomicTest] = []
7582
drilldown_search: Optional[str] = None
@@ -78,10 +85,6 @@ def risk_severity(self) -> RiskSeverity:
7885
mitre_attack_enrichments: List[MitreAttackEnrichment] = Field([], validate_default=True)
7986
confidence_id: Optional[PositiveInt] = Field(None, ge=1, le=3)
8087
impact_id: Optional[PositiveInt] = Field(None, ge=1, le=5)
81-
# context_ids: list = None
82-
risk_level_id: Optional[NonNegativeInt] = Field(None, le=4)
83-
risk_level: Optional[RiskLevel] = None
84-
# observable_str: str = None
8588
evidence_str: Optional[str] = None
8689

8790
@computed_field
@@ -157,7 +160,7 @@ def serialize_model(self):
157160
"message": self.message,
158161
"risk_score": self.risk_score,
159162
"security_domain": self.security_domain,
160-
"risk_severity": self.risk_severity,
163+
"risk_severity": self.severity,
161164
"mitre_attack_id": self.mitre_attack_id,
162165
"mitre_attack_enrichments": self.mitre_attack_enrichments
163166
}

contentctl/objects/enums.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,14 +409,16 @@ class NistCategory(str, enum.Enum):
409409
RC_IM = "RC.IM"
410410
RC_CO = "RC.CO"
411411

412-
class RiskLevel(str,enum.Enum):
412+
class RiskSeverity(str,enum.Enum):
413+
# Levels taken from the following documentation link
414+
# https://docs.splunk.com/Documentation/ES/7.3.2/User/RiskScoring
415+
# 20 - Info (0-20 for us)
416+
# 40 - Low (21-40 for us)
417+
# 60 - Medium (41-60 for us)
418+
# 80 - High (61-80 for us)
419+
# 100 - Critical (81 - 100 for us)
413420
INFO = "Info"
414421
LOW = "Low"
415422
MEDIUM = "Medium"
416423
HIGH = "High"
417424
CRITICAL = "Critical"
418-
419-
class RiskSeverity(str,enum.Enum):
420-
LOW = "low"
421-
MEDIUM = "medium"
422-
HIGH = "high"

contentctl/output/templates/savedsearches_detections.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ action.notable.param.nes_fields = {{ detection.nes_fields }}
7171
action.notable.param.rule_description = {{ detection.deployment.alert_action.notable.rule_description | custom_jinja2_enrichment_filter(detection) | escapeNewlines()}}
7272
action.notable.param.rule_title = {% if detection.type | lower == "correlation" %}RBA: {{ detection.deployment.alert_action.notable.rule_title | custom_jinja2_enrichment_filter(detection) }}{% else %}{{ detection.deployment.alert_action.notable.rule_title | custom_jinja2_enrichment_filter(detection) }}{% endif +%}
7373
action.notable.param.security_domain = {{ detection.tags.security_domain.value }}
74-
action.notable.param.severity = high
74+
action.notable.param.severity = {{ detection.tags.severity.value }}
7575
{% endif %}
7676
{% if detection.deployment.alert_action.email %}
7777
action.email.subject.alert = {{ detection.deployment.alert_action.email.subject | custom_jinja2_enrichment_filter(detection) | escapeNewlines() }}

0 commit comments

Comments
 (0)