-
Notifications
You must be signed in to change notification settings - Fork 0
/
cve-flash.py
executable file
·64 lines (54 loc) · 2.14 KB
/
cve-flash.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
61
62
63
64
#!/usr/bin/env python3
import json
import os
import urllib
from urllib import request
import gzip
import io
import dateutil
from dateutil import parser
# Grab and consume the latest CVE feed from NIST
headers ={'User-agent': 'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11'}
nvdrecent = urllib.request.Request('https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-recent.json.gz', headers = headers)
response = urllib.request.urlopen(nvdrecent)
buf = io.BytesIO(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")
goodcves = []
# Sort the list
sortedcves = sorted(cves, key=lambda k: dateutil.parser.parse(k.get('publishedDate', '')), reverse=True)
# Remove rejected items
goodcves = []
for cve in sortedcves:
description = cve.get('cve')['description']['description_data'][0]['value']
if 'REJECT' in description:
pass
else:
goodcves.append(cve)
# Snag the latest CVES from our list
lastfivecves = goodcves[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 everything out to our json file.
with open('cve.json','w') as json_file:
json.dump(output, json_file, indent=4)