|
| 1 | +from .parser_helper import get_defectdojo_findings |
| 2 | +from dojo.models import Finding |
| 3 | +import re |
| 4 | + |
| 5 | +__author__ = "Vijay Bheemineni" |
| 6 | +__license__ = "MIT" |
| 7 | +__version__ = "1.0.0" |
| 8 | +__status__ = "Development" |
| 9 | + |
| 10 | + |
| 11 | +class AcunetixScannerParser(object): |
| 12 | + """ |
| 13 | + This class parse Acunetix XML file using helper methods from 'parser_helper.py'. |
| 14 | + """ |
| 15 | + |
| 16 | + def __init__(self, xml_output, test): |
| 17 | + acunetix_defectdojo_findings = get_defectdojo_findings(xml_output) |
| 18 | + self.items = [] |
| 19 | + self.set_defectdojo_findings(acunetix_defectdojo_findings, test) |
| 20 | + |
| 21 | + def set_defectdojo_findings(self, acunetix_defectdojo_findings, test): |
| 22 | + defectdojo_findings = [] |
| 23 | + |
| 24 | + for acunetix_defectdojo_finding in acunetix_defectdojo_findings: |
| 25 | + |
| 26 | + defectdojo_title = acunetix_defectdojo_finding.title |
| 27 | + defectdojo_date = get_defectdojo_date(acunetix_defectdojo_finding.date) |
| 28 | + defectdojo_cwe_number = get_cwe_number(acunetix_defectdojo_finding.cwe) |
| 29 | + defectdojo_severity = get_severity(acunetix_defectdojo_finding.severity) |
| 30 | + defectdojo_falsep = get_false_positive(acunetix_defectdojo_finding.false_p) |
| 31 | + |
| 32 | + defectdojo_findings_titles = [finding.title for finding in defectdojo_findings] |
| 33 | + |
| 34 | + if defectdojo_title not in defectdojo_findings_titles: |
| 35 | + finding = Finding( |
| 36 | + title=defectdojo_title, |
| 37 | + date=defectdojo_date, |
| 38 | + url=acunetix_defectdojo_finding.url, |
| 39 | + cwe=defectdojo_cwe_number, |
| 40 | + test=test, |
| 41 | + severity=defectdojo_severity, |
| 42 | + description=acunetix_defectdojo_finding.description, |
| 43 | + mitigation=acunetix_defectdojo_finding.mitigation, |
| 44 | + references=acunetix_defectdojo_finding.references, |
| 45 | + impact=acunetix_defectdojo_finding.impact, |
| 46 | + false_p=defectdojo_falsep, |
| 47 | + dynamic_finding=acunetix_defectdojo_finding.dynamic_finding |
| 48 | + ) |
| 49 | + defectdojo_findings.append(finding) |
| 50 | + else: |
| 51 | + print(("Duplicate finding : {defectdojo_title}".format(defectdojo_title=defectdojo_title))) |
| 52 | + |
| 53 | + self.items = defectdojo_findings |
| 54 | + |
| 55 | + |
| 56 | +def get_defectdojo_date(date): |
| 57 | + """ |
| 58 | + Returns date as required by DefectDojo. |
| 59 | + :param date: |
| 60 | + :return: yyyy--mm-dd |
| 61 | + """ |
| 62 | + regex = r"([0-9]{2})\/([0-9]{2})\/([0-9]{4})" |
| 63 | + matches = re.finditer(regex, date, re.MULTILINE) |
| 64 | + match = next(enumerate(matches)) |
| 65 | + date = match[1].groups() |
| 66 | + day = date[0] |
| 67 | + mon = date[1] |
| 68 | + year = date[2] |
| 69 | + defectdojo_date = "{year}-{mon}-{day}".format(year=year, mon=mon, day=day) |
| 70 | + print(defectdojo_date) |
| 71 | + return defectdojo_date |
| 72 | + |
| 73 | + |
| 74 | +def get_cwe_number(cwe): |
| 75 | + """ |
| 76 | + Returns cwe number. |
| 77 | + :param cwe: |
| 78 | + :return: cwe number |
| 79 | + """ |
| 80 | + return cwe.split("-")[1] |
| 81 | + |
| 82 | + |
| 83 | +def get_severity(severity): |
| 84 | + """ |
| 85 | + Returns Severity as per DefectDojo standards. |
| 86 | + :param severity: |
| 87 | + :return: |
| 88 | + """ |
| 89 | + if severity == "high": |
| 90 | + return "High" |
| 91 | + elif severity == "medium": |
| 92 | + return "Medium" |
| 93 | + elif severity == "low": |
| 94 | + return "Low" |
| 95 | + elif severity == "informational": |
| 96 | + return "Informational" |
| 97 | + else: |
| 98 | + return "Critical" |
| 99 | + |
| 100 | + |
| 101 | +def get_false_positive(false_p): |
| 102 | + """ |
| 103 | + Returns True, False for false positive as per DefectDojo standards. |
| 104 | + :param false_p: |
| 105 | + :return: |
| 106 | + """ |
| 107 | + if false_p: |
| 108 | + return True |
| 109 | + else: |
| 110 | + return False |
0 commit comments