1+ import contextlib
12from xml .dom import NamespaceErr
23
34from defusedxml import ElementTree as ET
45
5- from dojo .models import Finding
6+ from dojo .models import Endpoint , Finding
67
78
89class OpenVASXMLParser :
@@ -17,26 +18,41 @@ def get_findings(self, filename, test):
1718 results = report .find ("results" )
1819 for result in results :
1920 script_id = None
20- for finding in result :
21- if finding .tag == "name" :
22- title = finding .text
23- description = [f"**Name**: { finding .text } " ]
24- if finding .tag == "host" :
25- title = title + "_" + finding .text
26- description .append (f"**Host**: { finding .text } " )
27- if finding .tag == "port" :
28- title = title + "_" + finding .text
29- description .append (f"**Port**: { finding .text } " )
30- if finding .tag == "nvt" :
31- description .append (f"**NVT**: { finding .text } " )
32- script_id = finding .get ("oid" ) or finding .text
33- if finding .tag == "severity" :
34- severity = self .convert_cvss_score (finding .text )
35- description .append (f"**Severity**: { finding .text } " )
36- if finding .tag == "qod" :
37- description .append (f"**QOD**: { finding .text } " )
38- if finding .tag == "description" :
39- description .append (f"**Description**: { finding .text } " )
21+ unsaved_endpoint = Endpoint ()
22+ for field in result :
23+ if field .tag == "name" :
24+ title = field .text
25+ description = [f"**Name**: { field .text } " ]
26+ if field .tag == "hostname" :
27+ title = title + "_" + field .text
28+ description .append (f"**Hostname**: { field .text } " )
29+ if field .text :
30+ unsaved_endpoint .host = field .text .strip () # strip due to https://github.com/greenbone/gvmd/issues/2378
31+ if field .tag == "host" :
32+ title = title + "_" + field .text
33+ description .append (f"**Host**: { field .text } " )
34+ if not unsaved_endpoint .host and field .text :
35+ unsaved_endpoint .host = field .text .strip () # strip due to https://github.com/greenbone/gvmd/issues/2378
36+ if field .tag == "port" :
37+ title = title + "_" + field .text
38+ description .append (f"**Port**: { field .text } " )
39+ if field .text :
40+ port_str , protocol = field .text .split ("/" )
41+ with contextlib .suppress (ValueError ):
42+ unsaved_endpoint .port = int (port_str )
43+ unsaved_endpoint .protocol = protocol
44+ if field .tag == "nvt" :
45+ description .append (f"**NVT**: { field .text } " )
46+ script_id = field .get ("oid" ) or field .text
47+ if field .tag == "severity" :
48+ description .append (f"**Severity**: { field .text } " )
49+ if field .tag == "threat" :
50+ description .append (f"**Threat**: { field .text } " )
51+ severity = field .text if field .text in {"Info" , "Low" , "Medium" , "High" , "Critical" } else "Info"
52+ if field .tag == "qod" :
53+ description .append (f"**QOD**: { field .text } " )
54+ if field .tag == "description" :
55+ description .append (f"**Description**: { field .text } " )
4056
4157 finding = Finding (
4258 title = str (title ),
@@ -47,6 +63,7 @@ def get_findings(self, filename, test):
4763 static_finding = False ,
4864 vuln_id_from_tool = script_id ,
4965 )
66+ finding .unsaved_endpoints = [unsaved_endpoint ]
5067 findings .append (finding )
5168 return findings
5269
0 commit comments