Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 51 lines (43 sloc) 1.8 KB
import json
import dateutil
import dateutil.parser
import os
import urllib2
import gzip
from StringIO import StringIO
# Grab and consume the latest CVE feed from NIST
nvdrecent = urllib2.Request('https://nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-recent.json.gz')
nvdrecent.add_header('Accept-encoding', 'gzip')
response = urllib2.urlopen(nvdrecent)
buf = StringIO(response.read())
f = gzip.GzipFile(fileobj=buf)
data = json.load(f)
# Pull the list of items together and grab the fields we need
list(data)
cves = data['CVE_Items']
cvenum = int(data['CVE_data_numberOfCVEs'])
date_posted = dateutil.parser.parse(data['CVE_data_timestamp'])
# Format the date the way we want it
date_posted = date_posted.strftime("%B %d %Y")
# Sort the list
sortedcves = sorted(cves, key=lambda k: dateutil.parser.parse(k.get('publishedDate', '')), reverse=True)
# Snag the latest CVES from our list
lastfivecves = sortedcves[0:6]
# Set up the array
output = []
# Iterate through the CVEs to get the data we want
for cve in lastfivecves[0:5]:
zdate = cve.get('publishedDate')
cvedate = dateutil.parser.parse((cve.get('publishedDate')))
cvedate = cvedate.strftime("%B %d %Y")
description = cve.get('cve')['description']['description_data'][0]['value']
CVE_id = cve.get('cve')['CVE_data_meta']['ID']
description = description + " This is " + CVE_id + " published on " + cvedate
redirectionurl = "https://cve.mitre.org/cgi-bin/cvename.cgi?name=" + CVE_id
# Place all of our output data into a variable
export_dict = {"uid": CVE_id,"updateDate": zdate, "titleText": CVE_id, "mainText": description, "redirectionUrl": redirectionurl}
# Write variable data into our array
output.append(export_dict)
# Write everthing out to our json file
with open('cve.json','w') as json_file:
json.dump(output, json_file, indent=4)
You can’t perform that action at this time.