23
23
from contentctl .objects .mitre_attack_enrichment import MitreAttackEnrichment
24
24
from contentctl .objects .constants import ATTACK_TACTICS_KILLCHAIN_MAPPING
25
25
from contentctl .objects .observable import Observable
26
+ from contentctl .objects .enums import Cis18Value , AssetType , SecurityDomain , RiskSeverity , KillChainPhase , NistCategory , SecurityContentProductName
26
27
from contentctl .objects .enums import (
27
28
Cis18Value ,
28
29
AssetType ,
29
30
SecurityDomain ,
30
31
RiskSeverity ,
31
32
KillChainPhase ,
32
33
NistCategory ,
33
- RiskLevel ,
34
34
SecurityContentProductName
35
35
)
36
+
36
37
from contentctl .objects .atomic import AtomicTest
37
38
from contentctl .objects .annotated_types import MITRE_ATTACK_ID_TYPE , CVE_TYPE
38
39
@@ -50,6 +51,23 @@ class DetectionTags(BaseModel):
50
51
@property
51
52
def risk_score (self ) -> int :
52
53
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
+
53
71
54
72
mitre_attack_id : List [MITRE_ATTACK_ID_TYPE ] = []
55
73
nist : list [NistCategory ] = []
@@ -59,17 +77,6 @@ def risk_score(self) -> int:
59
77
required_fields : list [str ] = Field (min_length = 1 )
60
78
throttling : Optional [Throttling ] = None
61
79
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
-
73
80
cve : List [CVE_TYPE ] = []
74
81
atomic_guid : List [AtomicTest ] = []
75
82
drilldown_search : Optional [str ] = None
@@ -78,10 +85,6 @@ def risk_severity(self) -> RiskSeverity:
78
85
mitre_attack_enrichments : List [MitreAttackEnrichment ] = Field ([], validate_default = True )
79
86
confidence_id : Optional [PositiveInt ] = Field (None , ge = 1 , le = 3 )
80
87
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
85
88
evidence_str : Optional [str ] = None
86
89
87
90
@computed_field
@@ -157,7 +160,7 @@ def serialize_model(self):
157
160
"message" : self .message ,
158
161
"risk_score" : self .risk_score ,
159
162
"security_domain" : self .security_domain ,
160
- "risk_severity" : self .risk_severity ,
163
+ "risk_severity" : self .severity ,
161
164
"mitre_attack_id" : self .mitre_attack_id ,
162
165
"mitre_attack_enrichments" : self .mitre_attack_enrichments
163
166
}
0 commit comments