From ca74209fb426fc5d21e5c13a2bdb994895f45cfc Mon Sep 17 00:00:00 2001 From: TheGroundZero <2406013+TheGroundZero@users.noreply.github.com> Date: Mon, 8 Apr 2019 16:53:13 +0200 Subject: [PATCH] Correct URL, some code optimalisations --- __init__.py | 2 +- docs/index.rst | 2 +- openvasreporting/__init__.py | 2 +- openvasreporting/__main__.py | 2 +- openvasreporting/libs/__init__.py | 2 +- openvasreporting/libs/config.py | 2 +- openvasreporting/libs/export.py | 2 +- openvasreporting/libs/parsed_data.py | 68 ++++++++++++---------------- openvasreporting/libs/parser.py | 2 +- openvasreporting/openvasreporting.py | 44 +++++++++++++----- openvasreporting/src/__init__.py | 2 +- setup.py | 4 +- 12 files changed, 74 insertions(+), 60 deletions(-) diff --git a/__init__.py b/__init__.py index b9c0ff4..aed408c 100644 --- a/__init__.py +++ b/__init__.py @@ -2,7 +2,7 @@ # # # Project name: OpenVAS to Report: A tool to convert OpenVAS XML reports into Excel files. -# Project URL: https://github.com/TheGroundZero/openvas_to_report +# Project URL: https://github.com/TheGroundZero/openvasreporting # # Copyright # This project is based on OpenVAS2Report (https://github.com/cr0hn/openvas_to_report) (c) 2015, cr0hn<-AT->cr0hn.com diff --git a/docs/index.rst b/docs/index.rst index 91d0e22..56158dc 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -72,7 +72,7 @@ I also plan on adding more functionality as I feel the need for it, or receive r If you feel like I'd need to implement a new feature, rewrite some code, fix a bug, ... hit me up on `Twitter `_ -or file an issue on `GitHub `_. +or file an issue on `GitHub `_. TODO list --------- diff --git a/openvasreporting/__init__.py b/openvasreporting/__init__.py index 45f90fb..f4b6f3b 100644 --- a/openvasreporting/__init__.py +++ b/openvasreporting/__init__.py @@ -2,7 +2,7 @@ # # # Project name: OpenVAS to Report: A tool to convert OpenVAS XML reports into Excel files. -# Project URL: https://github.com/TheGroundZero/openvas_to_report +# Project URL: https://github.com/TheGroundZero/openvasreporting # # Copyright # This project is based on OpenVAS2Report (https://github.com/cr0hn/openvas_to_report) (c) 2015, cr0hn<-AT->cr0hn.com diff --git a/openvasreporting/__main__.py b/openvasreporting/__main__.py index 1b91bf1..88ba655 100644 --- a/openvasreporting/__main__.py +++ b/openvasreporting/__main__.py @@ -2,7 +2,7 @@ # # # Project name: OpenVAS Reporting: A tool to convert OpenVAS XML reports into Excel files. -# Project URL: https://github.com/TheGroundZero/openvas_to_report +# Project URL: https://github.com/TheGroundZero/openvasreporting from openvasreporting.openvasreporting import main __author__ = 'TheGroundZero (https://github.com/TheGroundZero)' diff --git a/openvasreporting/libs/__init__.py b/openvasreporting/libs/__init__.py index d24bc14..083054c 100644 --- a/openvasreporting/libs/__init__.py +++ b/openvasreporting/libs/__init__.py @@ -2,4 +2,4 @@ # # # Project name: OpenVAS Reporting: A tool to convert OpenVAS XML reports into Excel files. -# Project URL: https://github.com/TheGroundZero/openvas_to_report +# Project URL: https://github.com/TheGroundZero/openvasreporting diff --git a/openvasreporting/libs/config.py b/openvasreporting/libs/config.py index 72fa9e6..e1fb2f4 100644 --- a/openvasreporting/libs/config.py +++ b/openvasreporting/libs/config.py @@ -2,7 +2,7 @@ # # # Project name: OpenVAS Reporting: A tool to convert OpenVAS XML reports into Excel files. -# Project URL: https://github.com/TheGroundZero/openvas_to_report +# Project URL: https://github.com/TheGroundZero/openvasreporting """This file contains data structures""" diff --git a/openvasreporting/libs/export.py b/openvasreporting/libs/export.py index b6f5c02..dab1d97 100644 --- a/openvasreporting/libs/export.py +++ b/openvasreporting/libs/export.py @@ -2,7 +2,7 @@ # # # Project name: OpenVAS Reporting: A tool to convert OpenVAS XML reports into Excel files. -# Project URL: https://github.com/TheGroundZero/openvas_to_report +# Project URL: https://github.com/TheGroundZero/openvasreporting import re from collections import Counter diff --git a/openvasreporting/libs/parsed_data.py b/openvasreporting/libs/parsed_data.py index 214dbe1..1ba375d 100644 --- a/openvasreporting/libs/parsed_data.py +++ b/openvasreporting/libs/parsed_data.py @@ -2,7 +2,7 @@ # # # Project name: OpenVAS Reporting: A tool to convert OpenVAS XML reports into Excel files. -# Project URL: https://github.com/TheGroundZero/openvas_to_report +# Project URL: https://github.com/TheGroundZero/openvasreporting """This file contains data structures""" @@ -80,15 +80,11 @@ def string2port(info): return Port(number, protocol) def __eq__(self, other): - if not isinstance(other, Port): - return False - - if other.number != self.number: - return False - if other.protocol != self.protocol: - return False - - return True + return ( + isinstance(other, Port) and + other.number == self.number and + other.protocol == self.protocol + ) class Host(object): @@ -113,15 +109,11 @@ def __init__(self, ip, host_name=""): self.host_name = host_name def __eq__(self, other): - if not isinstance(other, Host): - return False - - if other.ip != self.ip: - return False - if other.host_name != self.host_name: - return False - - return True + return ( + isinstance(other, Host) and + other.ip == self.ip and + other.host_name == self.host_name + ) class Vulnerability(object): @@ -238,28 +230,28 @@ def __eq__(self, other): if not isinstance(other, Vulnerability): raise TypeError("Expected Vulnerability, got '{}' instead".format(type(other))) - if other.cves != self.cves: - return False - if other.threat != self.threat: - return False - if other.name != self.name: - return False - if other.cvss != self.cvss: - return False - if other.description != self.description: - return False - if other.vuln_id != self.vuln_id: - return False - if other.level != self.level: - return False - if other.references != self.references: + if ( + other.vuln_id != self.vuln_id or + other.name != self.name or + other.cves != self.cves or + other.cvss != self.cvss or + other.level != self.level or + other.description != self.description or + other.detect != self.detect or + other.insight != self.insight or + other.impact != self.impact or + other.affected != self.affected or + other.solution != self.solution or + other.solution_type != self.solution_type or + other.references != self.references or + other.threat != self.threat or + other.family != self.family + ): return False for host, port in self.hosts: for o_host, o_port in other.hosts: - if o_host == host and o_port == port: - break - else: - return False + if o_host != host or o_port != port: + return False return True diff --git a/openvasreporting/libs/parser.py b/openvasreporting/libs/parser.py index 8c39d27..a7416e7 100644 --- a/openvasreporting/libs/parser.py +++ b/openvasreporting/libs/parser.py @@ -2,7 +2,7 @@ # # # Project name: OpenVAS Reporting: A tool to convert OpenVAS XML reports into Excel files. -# Project URL: https://github.com/TheGroundZero/openvas_to_report +# Project URL: https://github.com/TheGroundZero/openvasreporting import re import sys import logging diff --git a/openvasreporting/openvasreporting.py b/openvasreporting/openvasreporting.py index ad61f7a..dca8932 100644 --- a/openvasreporting/openvasreporting.py +++ b/openvasreporting/openvasreporting.py @@ -2,7 +2,7 @@ # # # Project name: OpenVAS Reporting: A tool to convert OpenVAS XML reports into Excel files. -# Project URL: https://github.com/TheGroundZero/openvas_to_report +# Project URL: https://github.com/TheGroundZero/openvasreporting import argparse @@ -57,17 +57,9 @@ def create_config(input_files, output_file="openvas_report", min_lvl="none", fil :rtype: Config """ - min_lvl = min_lvl.lower()[0] + min_lvl = check_level(min_lvl.lower()[0]) - if min_lvl in Config.levels().keys(): - min_lvl = Config.levels()[min_lvl] - else: - raise ValueError("Invalid value for level parameter, \ - must be one of: c[ritical], h[igh], m[edium], l[low], n[one]") - - if filetype not in exporters().keys(): - raise ValueError("Filetype not supported, got {}, expecting one of {}".format(filetype, - exporters().keys())) + check_filetype(filetype) if template is not None: return Config(input_files, output_file, min_lvl, filetype, template) @@ -94,3 +86,33 @@ def convert(config): openvas_info = openvas_parser(config.input_files, config.min_level) exporters()[config.filetype](openvas_info, config.template, config.output_file) + + +def check_level(min_lvl): + """ + Check if min_lvl is a correct level + + :param min_lvl: min_lvl + :return: min_lvl + + :raises: ValueError + """ + if min_lvl in Config.levels().keys(): + return Config.levels()[min_lvl] + else: + raise ValueError("Invalid value for level parameter, \ + must be one of: c[ritical], h[igh], m[edium], l[low], n[one]") + + +def check_filetype(filetype): + """ + Check if filetype is a correct filetype + + :param filetype: filetype + :return: + + :raises: ValueError + """ + if filetype not in exporters().keys(): + raise ValueError("Filetype not supported, got {}, expecting one of {}".format(filetype, + exporters().keys())) diff --git a/openvasreporting/src/__init__.py b/openvasreporting/src/__init__.py index d24bc14..083054c 100644 --- a/openvasreporting/src/__init__.py +++ b/openvasreporting/src/__init__.py @@ -2,4 +2,4 @@ # # # Project name: OpenVAS Reporting: A tool to convert OpenVAS XML reports into Excel files. -# Project URL: https://github.com/TheGroundZero/openvas_to_report +# Project URL: https://github.com/TheGroundZero/openvasreporting diff --git a/setup.py b/setup.py index bd52385..d06daf5 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( name='OpenVAS Reporting', description='A tool to convert OpenVAS XML into reports.', - version='1.4.2', + version='1.4.3', long_description=long_description, long_description_content_type='text/markdown', author='TheGroundZero (@DezeStijn)', @@ -24,7 +24,7 @@ project_urls={ 'Source Code': 'https://github.com/TheGroundZero/openvasreporting', 'Documentation': 'https://openvas-reporting.stijncrevits.be', - 'Issues': 'https://github.com/TheGroundZero/openvas_to_report/issues/', + 'Issues': 'https://github.com/TheGroundZero/openvasreporting/issues/', }, license='GPL-3.0-or-later', keywords='OpenVAS OpenVAS-reports Excel xlsxwriter xlsx reporting reports report',