Last active
November 2, 2021 09:30
-
-
Save jgamblin/dfafbb94323fa1be39bc5552ecc36d04 to your computer and use it in GitHub Desktop.
NVD CVEs to Indivual JSON files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import gzip | |
import os | |
import codecs | |
import time | |
from datetime import timedelta | |
start = time.time() | |
count = 0 | |
baseURL = "https://nvd.nist.gov/feeds/json/cve/1.0/" | |
year = 2002 | |
while year <= 2019: | |
yearstr = str(year) | |
os.mkdir(yearstr) | |
os.chdir(yearstr) | |
feed = ('nvdcve-1.0-'+yearstr+'.json.gz') | |
url = baseURL + feed | |
r = requests.get(url) | |
open(feed, 'wb').write(r.content) | |
with gzip.open(feed, 'rt', encoding="utf8") as fd: | |
data = json.load(fd) | |
for item in data['CVE_Items']: | |
if 'cve' in item: | |
if 'CVE_data_meta' in item['cve']: | |
if 'ID' in item['cve']['CVE_data_meta']: | |
count = count + 1 | |
filename = (item['cve']['CVE_data_meta']['ID'] + '.json') | |
try: | |
with open(filename, 'wb') as f: | |
json.dump(item, codecs.getwriter('utf-8')(f), | |
ensure_ascii=False) | |
f.close() | |
except TypeError: | |
continue | |
os.chdir('..') | |
year = year + 1 | |
elapsed = (time.time() - start) | |
print("CVEs Turned Into JSON Files:") | |
print(count) | |
print("Done In:") | |
print(str(timedelta(seconds=elapsed))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment