|
1 | 1 | from defusedxml import ElementTree
|
2 | 2 |
|
3 |
| -from dojo.models import Finding |
| 3 | +from dojo.models import Endpoint, Finding |
4 | 4 |
|
5 | 5 |
|
6 | 6 | class FortifyXMLParser:
|
7 | 7 | def parse_xml(self, filename, test):
|
8 | 8 | fortify_scan = ElementTree.parse(filename)
|
9 | 9 | root = fortify_scan.getroot()
|
| 10 | + if root.tag == "Scan": |
| 11 | + return self.xml_structure_24_2(root, test) |
| 12 | + if root.tag == "ReportDefinition": |
| 13 | + return self.xml_structure_before_24_2(root, test) |
| 14 | + raise ValueError |
| 15 | + |
| 16 | + def xml_structure_24_2(self, root, test): |
| 17 | + items = [] |
| 18 | + for issues in root.findall("Issues"): |
| 19 | + for issue in issues.iter("Issue"): |
| 20 | + check_type_id = issue.find("CheckTypeID").text |
| 21 | + engine_type = issue.find("EngineType").text |
| 22 | + url = issue.find("URL").text |
| 23 | + scheme = issue.find("Scheme").text |
| 24 | + host = issue.find("Host").text |
| 25 | + port = issue.find("Port").text |
| 26 | + vulnerable_session = issue.find("VulnerableSession").text |
| 27 | + vulnerability_id = issue.find("VulnerabilityID").text |
| 28 | + severity = issue.find("Severity").text |
| 29 | + name = issue.find("Name").text |
| 30 | + raw_response = issue.find("RawResponse").text |
| 31 | + description = "" |
| 32 | + description += "**CheckTypeID:** " + check_type_id + "\n" |
| 33 | + description += "**URL:** " + url + "\n" |
| 34 | + description += "**EngineType:** " + engine_type + "\n" |
| 35 | + description += "**Scheme:** " + scheme + "\n" |
| 36 | + description += "**VulnerabilityID:** " + vulnerability_id + "\n" |
| 37 | + description += "**VulnerableSession:** " + vulnerable_session + "\n" |
| 38 | + finding = Finding( |
| 39 | + title=name, |
| 40 | + severity=self.severity_translator(severity=int(severity)), |
| 41 | + static_finding=True, |
| 42 | + test=test, |
| 43 | + description=description, |
| 44 | + ) |
| 45 | + if raw_response is not None: |
| 46 | + finding.unsaved_req_resp = [] |
| 47 | + finding.unsaved_req_resp.append({"req": "", "resp": str(raw_response)}) |
| 48 | + if host is not None: |
| 49 | + finding.unsaved_endpoints = [Endpoint(host=host, port=port)] |
| 50 | + items.append(finding) |
| 51 | + return items |
| 52 | + |
| 53 | + def severity_translator(self, severity): |
| 54 | + if severity == 0: |
| 55 | + return "Info" |
| 56 | + if severity == 1: |
| 57 | + return "Low" |
| 58 | + if severity == 2: |
| 59 | + return "Medium" |
| 60 | + if severity == 3: |
| 61 | + return "High" |
| 62 | + if severity == 4: |
| 63 | + return "Critical" |
| 64 | + return "Info" |
| 65 | + |
| 66 | + def xml_structure_before_24_2(self, root, test): |
10 | 67 | # Get Category Information:
|
11 | 68 | # Abstract, Explanation, Recommendation, Tips
|
12 | 69 | cat_meta = {}
|
|
0 commit comments