@@ -98,6 +98,14 @@ def _parse_variot_description(self, query_results):
9898
9999
100100class VulnerabilityLookupMapping (VulnerabilityMapping ):
101+ __cnvd_mapping = {
102+ "number" : "id" ,
103+ "title" : "summary" ,
104+ "description" : "description" ,
105+ "referenceLink" : "references" ,
106+ "submitTime" : "published" ,
107+ "openTime" : "modified"
108+ }
101109 __csaf_mapping = {
102110 "id" : "id" ,
103111 "initial_release_date" : "published" ,
@@ -137,6 +145,7 @@ class VulnerabilityLookupMapping(VulnerabilityMapping):
137145 "discovery_date" : "published"
138146 }
139147 __source_mapping = {
148+ "cnvd" : "_parse_cnvd_description" ,
140149 "cve" : "_parse_cve_description" ,
141150 'fkie_cve' : '_parse_fkie_description' ,
142151 "ghsa" : "_parse_standard_description" ,
@@ -170,6 +179,10 @@ class VulnerabilityLookupMapping(VulnerabilityMapping):
170179 "published" : "published"
171180 }
172181
182+ @classmethod
183+ def cnvd_mapping (cls ) -> dict :
184+ return cls .__cnvd_mapping
185+
173186 @classmethod
174187 def csaf_mapping (cls ) -> dict :
175188 return cls .__csaf_mapping
@@ -249,18 +262,36 @@ def _create_vulnerability_object(self, vuln_id: str) -> MISPObject:
249262 )
250263 return misp_object
251264
265+ def _parse_alias (self , alias : str ) -> str :
266+ query = requests .get (f"{ self .api_url } /api/vulnerability/{ alias } " )
267+ if query .status_code != 200 :
268+ self .errors .append (
269+ f"Unable to query related vulnerability id { alias } "
270+ )
271+ return
272+ vulnerability = query .json ()
273+ if not vulnerability :
274+ self .errors .append (
275+ f"No results for related vulnerability id{ alias } "
276+ )
277+ return
278+ feature = self .mapping .source_mapping (alias .split ("-" )[0 ].lower ())
279+ return getattr (self , feature )(vulnerability )
280+
252281 def _parse_aliases (self , * aliases : tuple ) -> Iterator [str ]:
253282 for alias in aliases :
254- query = requests .get (f"{ self .api_url } /api/vulnerability/{ alias } " )
255- if query .status_code != 200 :
256- self .errors .append (f"Unable to query related vulnerability id { alias } " )
257- continue
258- vulnerability = query .json ()
259- if not vulnerability :
260- self .errors .append (f"No results for related vulnerability id{ alias } " )
261- continue
262- feature = self .mapping .source_mapping (alias .split ("-" )[0 ].lower ())
263- yield getattr (self , feature )(vulnerability )
283+ yield self ._parse_alias (alias )
284+
285+ def _parse_cnvd_description (self , lookup_result : dict ) -> str :
286+ misp_object = self ._create_vulnerability_object (lookup_result ['number' ])
287+ for field , relation in self .mapping .cnvd_mapping ().items ():
288+ misp_object .add_attribute (relation , lookup_result [field ])
289+ vulnerability_object = self .misp_event .add_object (misp_object )
290+ cve = lookup_result .get ('cves' , {}).get ('cve' , {}).get ('cveNumber' )
291+ if cve is not None :
292+ vulnerability_object .add_reference (
293+ self ._parse_alias (cve ), 'related-to'
294+ )
264295
265296 def _parse_csaf_branch (self , branch : list ) -> Iterator [str ]:
266297 for sub_branch in branch :
@@ -434,7 +465,7 @@ def _parse_jvn_description(self, lookup_result: dict) -> str:
434465 else :
435466 misp_object .add_reference (
436467 self .misp_event .add_attribute (type = "weakness" , value = reference ["@id" ]).uuid ,
437- "weakened-by" ,
468+ "weakened-by"
438469 )
439470 continue
440471 if source == "JVN" :
0 commit comments