Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cve values to openvas csv parser #9791

Merged
merged 4 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion dojo/tools/openvas/csv_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import csv
import hashlib
import io
import re
from dateutil.parser import parse
from dojo.models import Finding, Endpoint

Expand Down Expand Up @@ -71,6 +72,33 @@ def map_column_value(self, finding, column_value):
finding.unsaved_endpoints[0].port = int(column_value)


class CveColumnMappingStrategy(ColumnMappingStrategy):
def __init__(self):
self.mapped_column = "cves"
super(CveColumnMappingStrategy, self).__init__()

def map_column_value(self, finding, column_value):
if column_value != "":
if "," in column_value:
finding.description += "\n**All CVEs:** " + str(column_value)
for value in column_value.split(","):
finding.unsaved_vulnerability_ids.append(value)
else:
finding.unsaved_vulnerability_ids.append(column_value)


class NVDCVEColumnMappingStrategy(ColumnMappingStrategy):
def __init__(self):
self.mapped_column = "nvt oid"
super(NVDCVEColumnMappingStrategy, self).__init__()

def map_column_value(self, finding, column_value):
cve_pattern = r'CVE-\d{4}-\d{4,7}'
cves = re.findall(cve_pattern, column_value)
for cve in cves:
finding.unsaved_vulnerability_ids.append(cve)


class ProtocolColumnMappingStrategy(ColumnMappingStrategy):
def __init__(self):
self.mapped_column = "port protocol"
Expand Down Expand Up @@ -210,6 +238,8 @@ def create_chain(self):
duplicate_strategy = DuplicateColumnMappingStrategy()
port_strategy = PortColumnMappingStrategy()
protocol_strategy = ProtocolColumnMappingStrategy()
cve_column_strategy = CveColumnMappingStrategy()
nvd_cve_column_strategy = NVDCVEColumnMappingStrategy()
port_strategy.successor = protocol_strategy
duplicate_strategy.successor = port_strategy
false_positive_strategy.successor = duplicate_strategy
Expand All @@ -224,7 +254,9 @@ def create_chain(self):
hostname_column_strategy.successor = ip_column_strategy
cwe_column_strategy.successor = hostname_column_strategy
title_column_strategy.successor = cwe_column_strategy
date_column_strategy.successor = title_column_strategy
cve_column_strategy.successor = title_column_strategy
nvd_cve_column_strategy.successor = cve_column_strategy
date_column_strategy.successor = nvd_cve_column_strategy
return date_column_strategy

def read_column_names(self, row):
Expand All @@ -246,6 +278,7 @@ def get_findings(self, filename, test):
row_number = 0
for row in reader:
finding = Finding(test=test)
finding.unsaved_vulnerability_ids = list()
finding.unsaved_endpoints = [Endpoint()]
if row_number == 0:
column_names = self.read_column_names(row)
Expand Down
Loading
Loading