11import json
2- from typing import Iterator
3-
42import requests
3+ from datetime import datetime
54from pymisp import MISPAttribute , MISPEvent , MISPObject
5+ from typing import Iterator
66
77
88class VulnerabilityMapping :
@@ -98,6 +98,11 @@ def _parse_variot_description(self, query_results):
9898
9999
100100class VulnerabilityLookupMapping (VulnerabilityMapping ):
101+ __certfr_mapping = {
102+ "reference" : "id" ,
103+ "title" : "summary" ,
104+ "summary" : "description"
105+ }
101106 __cnvd_mapping = {
102107 "number" : "id" ,
103108 "title" : "summary" ,
@@ -145,6 +150,7 @@ class VulnerabilityLookupMapping(VulnerabilityMapping):
145150 "discovery_date" : "published"
146151 }
147152 __source_mapping = {
153+ "certfr" : "_parse_certfr_description" ,
148154 "cnvd" : "_parse_cnvd_description" ,
149155 "cve" : "_parse_cve_description" ,
150156 'fkie_cve' : '_parse_fkie_description' ,
@@ -179,6 +185,10 @@ class VulnerabilityLookupMapping(VulnerabilityMapping):
179185 "published" : "published"
180186 }
181187
188+ @classmethod
189+ def certfr_mapping (cls ) -> dict :
190+ return cls .__certfr_mapping
191+
182192 @classmethod
183193 def cnvd_mapping (cls ) -> dict :
184194 return cls .__cnvd_mapping
@@ -282,6 +292,31 @@ def _parse_aliases(self, *aliases: tuple) -> Iterator[str]:
282292 for alias in aliases :
283293 yield self ._parse_alias (alias )
284294
295+ def _parse_certfr_description (self , lookup_result : dict ) -> str :
296+ misp_object = self ._create_vulnerability_object (
297+ lookup_result ['reference' ]
298+ )
299+ for field , relation in self .mapping .certfr_mapping ().items ():
300+ misp_object .add_attribute (relation , lookup_result [field ])
301+ timestamps = {
302+ datetime .strptime (revision ['revision_date' ], '%Y-%m-%dT%H:%M:%S.%f' )
303+ for revision in lookup_result .get ('revisions' , [])
304+ }
305+ if timestamps :
306+ misp_object .add_attribute ('published' , min (timestamps ))
307+ if len (timestamps ) > 1 :
308+ misp_object .add_attribute ('modified' , max (timestamps ))
309+ for link in lookup_result .get ('links' , []):
310+ misp_object .add_attribute (
311+ 'references' , link ['url' ], comment = link ['title' ]
312+ )
313+ vulnerability_object = self .misp_event .add_object (misp_object )
314+ for cve in lookup_result .get ('cves' , []):
315+ vulnerability_object .add_reference (
316+ self ._parse_alias (cve ['name' ]), 'related-to'
317+ )
318+ return vulnerability_object .uuid
319+
285320 def _parse_cnvd_description (self , lookup_result : dict ) -> str :
286321 misp_object = self ._create_vulnerability_object (lookup_result ['number' ])
287322 for field , relation in self .mapping .cnvd_mapping ().items ():
@@ -292,6 +327,7 @@ def _parse_cnvd_description(self, lookup_result: dict) -> str:
292327 vulnerability_object .add_reference (
293328 self ._parse_alias (cve ), 'related-to'
294329 )
330+ return vulnerability_object .uuid
295331
296332 def _parse_csaf_branch (self , branch : list ) -> Iterator [str ]:
297333 for sub_branch in branch :
0 commit comments