forked from empti/vulscan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnist_nvd_download.py
60 lines (51 loc) · 2.55 KB
/
nist_nvd_download.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# download the cve json files
# TODO: also save service + version data
from __future__ import print_function
import urllib
import gzip
import json
import pandas as pd
OUTPUT_NAME = 'nvd_latest.csv'
# https://nvd.nist.gov/vuln/data-feeds
cve_file_urls = [
'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2020.json.gz',
'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2019.json.gz',
'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2018.json.gz',
'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2017.json.gz',
'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2016.json.gz',
# 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2015.json.gz',
# 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2014.json.gz',
# 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2013.json.gz',
# 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2012.json.gz',
# 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2011.json.gz',
# 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2010.json.gz',
# 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2009.json.gz',
# 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2008.json.gz',
# 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2007.json.gz',
# 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2006.json.gz',
# 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2005.json.gz',
# 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2004.json.gz',
# 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2003.json.gz',
# 'https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-2002.json.gz',
]
cve_summary = []
for cve_file in cve_file_urls:
print(f'gathering CVEs from {cve_file}...')
with urllib.request.urlopen(cve_file) as fp:
gzipped = fp.read()
cve_blob = json.loads(gzip.decompress(gzipped).decode())
cves = cve_blob['CVE_Items']
for c in cves:
id = c['cve']['CVE_data_meta']['ID']
if c['impact'].get('baseMetricV3'):
cvss = c['impact']['baseMetricV3']['cvssV3']['baseScore']
elif c['impact'].get('baseMetricV2'):
cvss = c['impact']['baseMetricV2']['cvssV2']['baseScore']
else:
cvss = ''
description = c['cve']['description']['description_data'][0]['value']
description = description.replace(';','.') # scrub semicolons from descriptions
cve_summary.append({'id':id, 'description':description, 'cvss':cvss})
df = pd.DataFrame(cve_summary)
df.to_csv(OUTPUT_NAME,sep=';', index=False)
print(f'results saved to {OUTPUT_NAME}')