forked from p15670423/monkey
Some bugfixes and added explanations about why no mitigations exist
This commit is contained in:
parent
2b0820f74a
commit
950e160627
|
@ -24,6 +24,14 @@ class AttackMitigations(Document):
|
||||||
if mitigation_external_ref_id.startswith('M'):
|
if mitigation_external_ref_id.startswith('M'):
|
||||||
self.mitigations.append(Mitigation.get_from_stix2_data(mitigation))
|
self.mitigations.append(Mitigation.get_from_stix2_data(mitigation))
|
||||||
|
|
||||||
|
def add_no_mitigations_info(self, mitigation: CourseOfAction):
|
||||||
|
mitigation_external_ref_id = MitreApiInterface.get_stix2_external_reference_id(mitigation)
|
||||||
|
if mitigation_external_ref_id.startswith('T') and len(self.mitigations) == 0:
|
||||||
|
mitigation_mongo_object = Mitigation.get_from_stix2_data(mitigation)
|
||||||
|
mitigation_mongo_object['description'] = mitigation_mongo_object['description'].splitlines()[0]
|
||||||
|
mitigation_mongo_object['url'] = ''
|
||||||
|
self.mitigations.append(mitigation_mongo_object)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def mitigations_from_attack_pattern(attack_pattern: AttackPattern):
|
def mitigations_from_attack_pattern(attack_pattern: AttackPattern):
|
||||||
return AttackMitigations(technique_id=MitreApiInterface.get_stix2_external_reference_id(attack_pattern),
|
return AttackMitigations(technique_id=MitreApiInterface.get_stix2_external_reference_id(attack_pattern),
|
||||||
|
|
|
@ -17,6 +17,8 @@ def try_store_mitigations_on_mongo():
|
||||||
except errors.OperationFailure:
|
except errors.OperationFailure:
|
||||||
try:
|
try:
|
||||||
mongo.db.create_collection(mitigation_collection_name)
|
mongo.db.create_collection(mitigation_collection_name)
|
||||||
|
except errors.CollectionInvalid:
|
||||||
|
pass
|
||||||
finally:
|
finally:
|
||||||
store_mitigations_on_mongo()
|
store_mitigations_on_mongo()
|
||||||
|
|
||||||
|
@ -27,5 +29,8 @@ def store_mitigations_on_mongo():
|
||||||
mitigation_technique_relationships = MitreApiInterface.get_technique_and_mitigation_relationships()
|
mitigation_technique_relationships = MitreApiInterface.get_technique_and_mitigation_relationships()
|
||||||
for relationship in mitigation_technique_relationships:
|
for relationship in mitigation_technique_relationships:
|
||||||
mongo_mitigations[relationship['target_ref']].add_mitigation(stix2_mitigations[relationship['source_ref']])
|
mongo_mitigations[relationship['target_ref']].add_mitigation(stix2_mitigations[relationship['source_ref']])
|
||||||
|
for relationship in mitigation_technique_relationships:
|
||||||
|
mongo_mitigations[relationship['target_ref']].\
|
||||||
|
add_no_mitigations_info(stix2_mitigations[relationship['source_ref']])
|
||||||
for key, mongo_object in mongo_mitigations.items():
|
for key, mongo_object in mongo_mitigations.items():
|
||||||
mongo_object.save()
|
mongo_object.save()
|
||||||
|
|
|
@ -28,9 +28,8 @@ class MitigationsComponent extends React.Component {
|
||||||
const emptyLineRegex = /^\s*[\r\n]/gm;
|
const emptyLineRegex = /^\s*[\r\n]/gm;
|
||||||
description = description.replace(citationRegex, '');
|
description = description.replace(citationRegex, '');
|
||||||
description = description.replace(emptyLineRegex, '');
|
description = description.replace(emptyLineRegex, '');
|
||||||
let descriptions = description.split('\n');
|
description = marked(description);
|
||||||
descriptions = descriptions.map(function(paragraph){ return marked(paragraph); });
|
return description;
|
||||||
return descriptions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static getMitigations() {
|
static getMitigations() {
|
||||||
|
@ -42,7 +41,7 @@ class MitigationsComponent extends React.Component {
|
||||||
accessor: x => this.getMitigationName(x.name, x.url),
|
accessor: x => this.getMitigationName(x.name, x.url),
|
||||||
width: 200},
|
width: 200},
|
||||||
{ id: 'description',
|
{ id: 'description',
|
||||||
accessor: x => (<div dangerouslySetInnerHTML={{__html: x.description}} />),
|
accessor: x => (<div dangerouslySetInnerHTML={{__html: this.parseDescription(x.description)}} />),
|
||||||
style: {'whiteSpace': 'unset'}}
|
style: {'whiteSpace': 'unset'}}
|
||||||
]
|
]
|
||||||
}])
|
}])
|
||||||
|
|
Loading…
Reference in New Issue