Skip to content
Snippets Groups Projects
Commit b907a9fb authored by shadow's avatar shadow
Browse files

moved CVEProject description grabber to separate file and added internal cache to it

parent 178a7121
No related branches found
No related tags found
No related merge requests found
from .description_provider import VulnDescriptionProvider, CveProjectProvider
from .description_provider import VulnDescriptionProvider
from .cveproject import CveProjectProvider
from requests import Session, HTTPError
from descriptions import VulnDescriptionProvider
__all__ = ['CveProjectProvider']
class CveProjectProvider(VulnDescriptionProvider):
"""
Provides vulnerability descriptions using requests to CVEProject
"""
uri_template = 'https://raw.githubusercontent.com/CVEProject/cvelist/master/{}/{}/{}.json'
def __init__(self, session: Session):
self.sess = session
self.cache = {}
def get_description(self, vuln: str, vuln_type: str) -> str:
if vuln in self.cache:
return self.cache[vuln]
try:
if vuln_type == 'cve':
year = vuln[4:8]
section = vuln[9:-3] + 'xxx'
url = self.uri_template.format(year, section, vuln)
response = self.sess.get(url)
response.raise_for_status()
cve_json = response.json()
description = cve_json['description']['description_data'][0]['value']
self.cache[vuln] = description
return description
except HTTPError as he:
return 'Description fetching error: ' + str(he)
return ''
......@@ -11,28 +11,3 @@ class VulnDescriptionProvider(metaclass=abc.ABCMeta):
@abc.abstractmethod
def get_description(self, vuln: str, vuln_type: str) -> str:
pass
class CveProjectProvider(VulnDescriptionProvider):
"""
Provides vulnerability descriptions using requests to CVEProject
"""
uri_template = 'https://raw.githubusercontent.com/CVEProject/cvelist/master/{}/{}/{}.json'
def __init__(self, session: Session):
self.sess = session
def get_description(self, vuln: str, vuln_type: str) -> str:
try:
if vuln_type == 'cve':
year = vuln[4:8]
section = vuln[9:-3] + 'xxx'
url = self.uri_template.format(year, section, vuln)
response = self.sess.get(url)
response.raise_for_status()
cve_json = response.json()
return cve_json['description']['description_data'][0]['value']
except HTTPError as he:
return 'Description fetching error: ' + str(he)
return ''
......@@ -9,11 +9,6 @@ from parsers import FlanXmlParser
from report_builders import ReportBuilder, LatexReportBuilder
def read_file(path: str):
with open(path) as f:
return f.read()
def create_report(parser: FlanXmlParser, builder: ReportBuilder, nmap_command: str, start_date: str, output_writer: IO,
ip_reader: IO):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment