fix: [vulnerability_lookup] Avoiding KeyError exceptions on some fields

pull/670/head
Christian Studer 2024-07-02 11:09:26 +02:00
parent 42fb1bcf14
commit 7d7dc1e633
No known key found for this signature in database
GPG Key ID: 6BBED1B63A6D639F
1 changed files with 4 additions and 5 deletions

View File

@ -152,7 +152,7 @@ class VulnerabilityLookupParser(VulnerabilityParser):
for field, relation in self.mapping.csaf_mapping().items():
misp_object.add_attribute(relation, tracking[field])
misp_object.add_attribute('summary', description['title'])
for reference in description['references']:
for reference in description.get('references', []):
misp_object.add_attribute('references', reference['url'])
misp_object.add_attribute('credit', description['publisher']['name'])
misp_object.add_reference(self.misp_attribute.uuid, 'describes')
@ -183,7 +183,7 @@ class VulnerabilityLookupParser(VulnerabilityParser):
def _parse_cve_description(self, lookup_result: dict) -> str:
misp_object = MISPObject('vulnerability')
cveMetaData = lookup_result['cveMetaData']
cveMetaData = lookup_result['cveMetadata']
for field, relation in self.mapping.cve_mapping().items():
misp_object.add_attribute(relation, cveMetaData[field])
for reference in lookup_result['containers']['cna']['references']:
@ -267,9 +267,8 @@ class VulnerabilityLookupParser(VulnerabilityParser):
misp_object = MISPObject('vulnerability')
for field, relation in self.mapping.standard_mapping().items():
misp_object.add_attribute(relation, lookup_result[field])
misp_object.add_attribute(
'cvss-string', lookup_result['severity']['score']
)
for cvss in lookup_result.get('severity', []):
misp_object.add_attribute('cvss-string', cvss['score'])
for reference in lookup_result['references']:
misp_object.add_attribute('references', reference['url'])
misp_object.add_reference(self.misp_attribute.uuid, 'related-to')