99import json
1010import logging
1111import os
12+ from typing import Iterable
1213
1314import dateparser
14- from typing import Iterable
1515from fetchcode .vcs .git import fetch_via_git
16- from vulnerabilities .importer import AdvisoryData , Reference
17- from vulnerabilities .importer import Importer
1816
17+ from vulnerabilities .importer import AdvisoryData
18+ from vulnerabilities .importer import Importer
19+ from vulnerabilities .importer import Reference
20+ from vulnerabilities .utils import build_description
21+ from vulnerabilities .utils import dedupe
1922
2023logger = logging .getLogger (__name__ )
2124
@@ -26,208 +29,34 @@ class GSDImporter(Importer):
2629 gsd_url = "git+https://github.com/cloudsecurityalliance/gsd-database"
2730
2831 def advisory_data (self ) -> Iterable [AdvisoryData ]:
29- # for file in fork_and_get_files(self.gsd_url):
30- # print(file)
31- x = '''{
32- "GSD": {
33- "alias": "CVE-2017-4017",
34- "description": "User Name Disclosure in the server in McAfee Network Data Loss Prevention (NDLP) 9.3.x allows remote attackers to view user information via the appliance web interface.",
35- "id": "GSD-2017-4017"
36- },
37- "namespaces": {
38- "cve.org": {
39- "CVE_data_meta": {
40- "ASSIGNER": "secure@intel.com",
41- "ID": "CVE-2017-4017",
42- "STATE": "PUBLIC"
43- },
44- "affects": {
45- "vendor": {
46- "vendor_data": [
47- {
48- "product": {
49- "product_data": [
50- {
51- "product_name": "Network Data Loss Prevention (NDLP)",
52- "version": {
53- "version_data": [
54- {
55- "version_value": "9.3.x"
56- }
57- ]
58- }
59- }
60- ]
61- },
62- "vendor_name": "McAfee"
63- }
64- ]
65- }
66- },
67- "data_format": "MITRE",
68- "data_type": "CVE",
69- "data_version": "4.0",
70- "description": {
71- "description_data": [
72- {
73- "lang": "eng",
74- "value": "User Name Disclosure in the server in McAfee Network Data Loss Prevention (NDLP) 9.3.x allows remote attackers to view user information via the appliance web interface."
75- }
76- ]
77- },
78- "problemtype": {
79- "problemtype_data": [
80- {
81- "description": [
82- {
83- "lang": "eng",
84- "value": "User Name Disclosure"
85- }
86- ]
87- }
88- ]
89- },
90- "references": {
91- "reference_data": [
92- {
93- "name": "https://kc.mcafee.com/corporate/index?page=content&id=SB10198",
94- "refsource": "CONFIRM",
95- "url": "https://kc.mcafee.com/corporate/index?page=content&id=SB10198"
96- },
97- {
98- "name": "1038523",
99- "refsource": "SECTRACK",
100- "url": "http://www.securitytracker.com/id/1038523"
101- }
102- ]
103- }
104- },
105- "nvd.nist.gov": {
106- "configurations": {
107- "CVE_data_version": "4.0",
108- "nodes": [
109- {
110- "children": [],
111- "cpe_match": [
112- {
113- "cpe23Uri": "cpe:2.3:a:mcafee:network_data_loss_prevention:*:*:*:*:*:*:*:*",
114- "cpe_name": [],
115- "versionEndIncluding": "9.3.0",
116- "vulnerable": true
117- }
118- ],
119- "operator": "OR"
120- }
121- ]
122- },
123- "cve": {
124- "CVE_data_meta": {
125- "ASSIGNER": "secure@intel.com",
126- "ID": "CVE-2017-4017"
127- },
128- "data_format": "MITRE",
129- "data_type": "CVE",
130- "data_version": "4.0",
131- "description": {
132- "description_data": [
133- {
134- "lang": "en",
135- "value": "User Name Disclosure in the server in McAfee Network Data Loss Prevention (NDLP) 9.3.x allows remote attackers to view user information via the appliance web interface."
136- }
137- ]
138- },
139- "problemtype": {
140- "problemtype_data": [
141- {
142- "description": [
143- {
144- "lang": "en",
145- "value": "CWE-200"
146- }
147- ]
148- }
149- ]
150- },
151- "references": {
152- "reference_data": [
153- {
154- "name": "https://kc.mcafee.com/corporate/index?page=content&id=SB10198",
155- "refsource": "CONFIRM",
156- "tags": [
157- "Vendor Advisory"
158- ],
159- "url": "https://kc.mcafee.com/corporate/index?page=content&id=SB10198"
160- },
161- {
162- "name": "1038523",
163- "refsource": "SECTRACK",
164- "tags": [],
165- "url": "http://www.securitytracker.com/id/1038523"
166- }
167- ]
168- }
169- },
170- "impact": {
171- "baseMetricV2": {
172- "cvssV2": {
173- "accessComplexity": "LOW",
174- "accessVector": "NETWORK",
175- "authentication": "NONE",
176- "availabilityImpact": "NONE",
177- "baseScore": 5.0,
178- "confidentialityImpact": "PARTIAL",
179- "integrityImpact": "NONE",
180- "vectorString": "AV:N/AC:L/Au:N/C:P/I:N/A:N",
181- "version": "2.0"
182- },
183- "exploitabilityScore": 10.0,
184- "impactScore": 2.9,
185- "obtainAllPrivilege": false,
186- "obtainOtherPrivilege": false,
187- "obtainUserPrivilege": false,
188- "severity": "MEDIUM",
189- "userInteractionRequired": false
190- },
191- "baseMetricV3": {
192- "cvssV3": {
193- "attackComplexity": "LOW",
194- "attackVector": "NETWORK",
195- "availabilityImpact": "NONE",
196- "baseScore": 5.3,
197- "baseSeverity": "MEDIUM",
198- "confidentialityImpact": "LOW",
199- "integrityImpact": "NONE",
200- "privilegesRequired": "NONE",
201- "scope": "UNCHANGED",
202- "userInteraction": "NONE",
203- "vectorString": "CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N",
204- "version": "3.0"
205- },
206- "exploitabilityScore": 3.9,
207- "impactScore": 1.4
208- }
209- },
210- "lastModifiedDate": "2017-07-08T01:29Z",
211- "publishedDate": "2017-05-17T21:29Z"
212- }
213- }
214- }'''
215- raw_data = json .loads (x )
216-
217- # GSD json
218- GSD = raw_data .get ("GSD" ) or {}
219- alias = GSD .get ("alias" ) or ""
220- description = GSD .get ("description" ) or ""
221- idx = GSD .get ("id" ) or ""
222-
223- namespaces = raw_data .get ("namespaces" ) or {}
224- cve_org = namespaces .get ("cve.org" ) or {}
225- nvd_nist_gov = namespaces .get ("nvd.nist.gov" ) or {}
226-
227- yield AdvisoryData ( aliases = aliases ,
228- summary = summary ,
229- references = references ,
230- date_published = get_published_date_nvd_nist_gov (nvd_nist_gov ))
32+ forked_dir = fork_and_get_dir (self .gsd_url )
33+ for file in get_files (forked_dir ):
34+ raw_data = json .loads (file )
35+
36+ namespaces = raw_data .get ("namespaces" ) or {}
37+ cve_org = namespaces .get ("cve.org" ) or {}
38+ nvd_nist_gov = namespaces .get ("nvd.nist.gov" ) or {}
39+
40+ GSD = raw_data .get ("GSD" ) or {}
41+ GSD_alias = GSD .get ("alias" ) or []
42+ details = GSD .get ("description" ) or get_description (cve_org )
43+ GSD_id = GSD .get ("id" ) or ""
44+
45+ aliases_cve_org = get_aliases (cve_org )
46+ aliases_nvd_nist_gov = get_aliases (nvd_nist_gov )
47+ aliases = GSD_alias + GSD_id + aliases_cve_org + aliases_nvd_nist_gov
48+
49+ summary = build_description (summary = get_summary (cve_org ), description = details )
50+ references = get_references (cve_org )
51+
52+ date_published = get_published_date_nvd_nist_gov (nvd_nist_gov )
53+
54+ yield AdvisoryData (
55+ aliases = dedupe (aliases ),
56+ summary = summary ,
57+ references = references ,
58+ date_published = date_published ,
59+ )
23160
23261
23362def get_summary (cve ) -> str :
@@ -244,13 +73,13 @@ def get_cvss_str_v_cve_org(cve) -> str:
24473def get_description (cve ) -> [str ]:
24574 description = cve .get ("description" ) or {}
24675 description_data = description .get ("description_data" ) or []
247- return [desc [' value' ] for desc in description_data if desc [' value' ]]
76+ return [desc [" value" ] for desc in description_data if desc [" value" ]]
24877
24978
250- def get_references (cve , severities ) -> [ str ] :
79+ def get_references (cve ) :
25180 references = cve .get ("references" ) or {}
25281 reference_data = references .get ("reference_data" ) or []
253- return [Reference (url = ref ["url" ]) for ref in reference_data if ref [' url' ]]
82+ return [Reference (url = ref ["url" ]) for ref in reference_data if ref [" url" ]]
25483
25584
25685def get_aliases (cve ) -> [str ]:
@@ -273,44 +102,31 @@ def get_published_date_nvd_nist_gov(nvd_nist_gov):
273102 return publishedDate and dateparser .parse (publishedDate )
274103
275104
276- def get_nvd_nist_gov_details (nvd_nist_gov ):
277- configurations = nvd_nist_gov .get ("configurations" ) or {}
278- lastModifiedDate = nvd_nist_gov .get ("lastModifiedDate" )
279-
280-
281- def get_severities_nvd_nist_gov (nvd_nist_gov ):
282- impact = nvd_nist_gov .get ("impact" ) or {}
283- baseMetricV2 = impact .get ("baseMetricV2" ) or {}
284- cvssV2 =
285- severity = baseMetricV2 .get ("severity" )
286-
287- baseMetricV3 = impact .get ("baseMetricV2" ) or {}
288- cvssV3 =
289-
290-
291-
292- def get_severities_cve_org (cve_org ):
293- impact = cve_org .get ("impact" ) or {}
294-
295-
296-
297105def ForkError ():
298106 pass
299107
300108
301-
302- def fork_and_get_files (url ) -> dict :
109+ def fork_and_get_dir (url ) -> dict :
303110 try :
304111 fork_directory = fetch_via_git (url = url )
112+ return fork_directory .dest_dir
305113 except Exception as e :
306114 logger .error (f"Can't clone url { url } " )
307115 raise ForkError () from e
308116
309- advisory_dirs = os .path .join (fork_directory .dest_dir , "1999" )
310- for root , _ , files in os .walk (advisory_dirs ):
311- for file in files :
312- if not file .endswith (".json" ):
313- logger .warning (f"unsupported file { file } " )
314- else :
117+
118+ def get_files (fork_directory ):
119+ for root_dir in os .listdir (fork_directory ):
120+ if root_dir in [
121+ "nvd_updated_time.txt" ,
122+ "CODE_OF_CONDUCT.md" ,
123+ "LICENSE" ,
124+ "allowlist.json" ,
125+ "README.md" ,
126+ ".github" ,
127+ ]:
128+ continue
129+ for root , _ , files in os .walk (os .path .join (fork_directory , root_dir )):
130+ for file in files :
315131 with open (os .path .join (root , file ), "r" ) as f :
316132 yield f .read ()
0 commit comments