Skip to content
Snippets Groups Projects

Implement advanced vulnerability classification

Merged Gioacchino Vino requested to merge pandas_classifier into main
1 file
+ 19
30
Compare changes
  • Side-by-side
  • Inline
+ 19
30
@@ -2,16 +2,18 @@ from gvm.connections import TLSConnection
from gvm.protocols.gmpv208 import Gmp, AliveTest
from gvm.transforms import EtreeTransform
from gvm.xml import pretty_print
import pandas as pd
from time import time, sleep
import logging
import base64
import json
from typing import Optional, Dict, List, Tuple, Set
from typing import Dict, List, Tuple
import yaml
from functools import reduce
import os
import git
import pandas as pd
# Configure Pandas to plot all columns
pd.set_option('display.max_columns', None)
# GVM Xpath Constants
GVM_XPATH_ID = '@id'
@@ -30,6 +32,10 @@ GVM_XPATH_REPORT_TEXT = 'report/text()'
GVM_STATUS_OK = "200"
GVM_STATUS_CREATE_OK = "201"
# LOGGING MSG
OBJ_ALREADY_CREATED = "Already created. Collected from server"
FIRST_OBJ_CONSIDERED = "The first one will be considered"
# Custom Exceptions
class GvmException(Exception):
pass
@@ -53,23 +59,6 @@ class ReportFormats:
txt = "a3810a62-1f62-11e1-9219-406186ea4fc5"
xml = "a994b278-1f62-11e1-96ac-406186ea4fc5"
class ResultReport():
oid: str
severity: float
threat: str
port: str
def __init__(self, o, s, t, p):
self.oid = str(o)
self.severity = float(s)
self.threat = str(t)
self.port = str(p)
def __str__(self):
msg = f"{self.oid}, {self.severity}, "
msg += f"{self.threat}, {self.port}"
return msg
class PortList:
"""
This class helps the managing of the GVM port_list object
@@ -97,12 +86,12 @@ class PortList:
self.create()
else:
logging.debug("Already created. Collected from server")
logging.debug(OBJ_ALREADY_CREATED)
if len(res) > 1:
# If one result has been collected, consider the first one
msg = f"The port_list name {name} retrieved {len(res)} results"
logging.warning(msg)
logging.warning("The first one will be considered")
logging.warning(FIRST_OBJ_CONSIDERED)
# If one result has been collected, consider it
self.name = res[0]['name']
@@ -138,7 +127,7 @@ class PortList:
msg = f"The port_list name {self.name}"
msg += f" retrieved {len(res)} results"
logging.warning(msg)
logging.warning("The first one will be considered")
logging.warning(FIRST_OBJ_CONSIDERED)
self.name = res[0]['name']
self.id = res[0]['id']
self.in_use = res[0]['in_use']
@@ -203,12 +192,12 @@ class Target:
self.create()
else:
logging.debug("Already created. Collected from server")
logging.debug(OBJ_ALREADY_CREATED)
if len(res) > 1:
# If one result has been collected, consider the first one
msg = f"The target name {name} retrieved {len(res)} results"
logging.warning(msg)
logging.warning("The first one will be considered")
logging.warning(FIRST_OBJ_CONSIDERED)
# If one result has been collected, consider it
self.name = res[0]['name']
@@ -252,7 +241,7 @@ class Target:
# Multiple objs retrieved, consider the first one
msg = f"The target id {t_id} retrieved {len(res)} results"
logging.warning(msg)
logging.warning("The first one will be considered")
logging.warning(FIRST_OBJ_CONSIDERED)
self.name = res[0]['name']
self.id = res[0]['id']
@@ -322,12 +311,12 @@ class Task:
# If no result retrieved, create it
self.create()
else:
logging.debug("Already created. Collected from server")
logging.debug(OBJ_ALREADY_CREATED)
if len(res) > 1:
# If one result has been collected, consider the first one
msg = f"The port_list name {name} retrieved {len(res)} results"
logging.warning(msg)
logging.warning("The first one will be considered")
logging.warning(FIRST_OBJ_CONSIDERED)
self.name = res[0]['name']
self.id = res[0]['id']
@@ -380,7 +369,7 @@ class Task:
# Multiple objs retrieved, consider the first one
msg = f"The task id {t_id} retrieved {len(res)} results"
logging.warning(msg)
logging.warning("The first one will be considered")
logging.warning(FIRST_OBJ_CONSIDERED)
self.name = res[0]['name']
self.id = res[0]['id']
@@ -572,7 +561,7 @@ class ReportManager():
logging.info("Report Manager Iniziatation started...")
self.os_name = os_name
self.is_os = is_os
self.imported_oids: Dict[str, List[ResultReport]] = dict()
self.imported_oids: Dict[str,Dict[str,Tuple]] = dict()
self.import_os_sec_repo()
self.import_security_oids()
logging.info("Report Manager Iniziatation completed")
Loading