Skip to content

Commit

Permalink
v1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGroundZero committed Sep 13, 2018
1 parent 8165909 commit dd660a6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 43 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Changelog
=========

1.2.2 - Fix bug where port info was not correctly extracted.

1.2.1 - Fix bug where affected hosts were added on wrong row in Excel export.

1.2.0 - Functional export to Word document (.docx). Includes some formatting. TODO: graphs
Expand Down
12 changes: 4 additions & 8 deletions openvasreporting/libs/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ def export_to_excel(vuln_info, output_file="openvas_report"):
ws_vuln.write('D9', "Host name", format_table_titles)
ws_vuln.write('E9', "Port number", format_table_titles)
ws_vuln.write('F9', "Port protocol", format_table_titles)
ws_vuln.write('G9', "Port description", format_table_titles)

# Affected hosts
for j, (host, port) in enumerate(vuln.hosts, 10):
Expand All @@ -267,9 +266,8 @@ def export_to_excel(vuln_info, output_file="openvas_report"):
ws_vuln.write("D{}".format(j), host.host_name if host.host_name else "-")

if port:
ws_vuln.write("E{}".format(j), port.number)
ws_vuln.write("E{}".format(j), "-" if port.number == 0 else port.number)
ws_vuln.write("F{}".format(j), port.protocol)
ws_vuln.write("G{}".format(j), port.description)
else:
ws_vuln.write("E{}".format(j), "No port info")

Expand Down Expand Up @@ -487,23 +485,21 @@ def add_style(new_style_name, base_style_name, font_size, font_color, font_bold,
# --------------------
document.add_paragraph('Vulnerable hosts', style='Report Heading 3')

table_hosts = document.add_table(cols=5, rows=(len(vuln.hosts) + 1))
table_hosts = document.add_table(cols=4, rows=(len(vuln.hosts) + 1))
hdr_cells = table_hosts.rows[0].cells
hdr_cells[0].paragraphs[0].add_run('IP').bold = True
hdr_cells[1].paragraphs[0].add_run('Host name').bold = True
hdr_cells[2].paragraphs[0].add_run('Port number').bold = True
hdr_cells[3].paragraphs[0].add_run('Port protocol').bold = True
hdr_cells[4].paragraphs[0].add_run('Port description').bold = True

for j, (host, port) in enumerate(vuln.hosts, 1):

cells = table_hosts.rows[j].cells
cells[0].text = host.ip
cells[1].text = host.host_name if host.host_name else "-"
if port:
cells[2].text = port.number
if port and port is not None:
cells[2].text = "-" if port.number == 0 else str(port.number)
cells[3].text = port.protocol
cells[4].text = port.description
else:
cells[2].text = "No port info"

Expand Down
42 changes: 18 additions & 24 deletions openvasreporting/libs/parsed_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
class Port(object):
"""Port information"""

def __init__(self, number, protocol="tcp", description=""):
def __init__(self, number, protocol="tcp"):
"""
:param number: port number
:type number: int
:param protocol: port protocol (tcp, udp, ...)
:type protocol: basestring
:param description: port description
:type description: basestring
:raises: TypeError, ValueError
"""
if not isinstance(number, int):
Expand All @@ -34,12 +31,8 @@ def __init__(self, number, protocol="tcp", description=""):
if not isinstance(protocol, str):
raise TypeError("Expected basestring, got '{}' instead".format(type(protocol)))

if not isinstance(description, str):
raise TypeError("Expected basestring, got '{}' instead".format(type(description)))

self.number = number
self.protocol = protocol
self.description = description

@staticmethod
def string2port(info):
Expand All @@ -49,14 +42,18 @@ def string2port(info):
..note:
Raises value error if information can't be processed.
# >>> p=Port.string2port("callbook (2000/tcp)")
# >>> p=Port.string2port("2000/tcp")
# >>> print p.number
2000
# >>> print p.desc
"callbook"
# >>> print p.proto
"tcp"
# >>> p=Port.string2port("general/icmp")
# >>> print p.number
0
# >>> print p.proto
"icmp"
:param info: raw string with port information
:type info: basestring
Expand All @@ -68,21 +65,20 @@ def string2port(info):
if not isinstance(info, str):
raise TypeError("Expected basestring, got '{}' instead".format(type(info)))

regex = re.search("([\w\W]+)(\()([\d]+)(/)([\w]+)", info)

if regex:
if len(regex.groups()) != 5:
raise ValueError("Can't parse input string")

description = regex.group(1).strip()
number = int(regex.group(3))
protocol = regex.group(5)

return Port(number, protocol, description)
regex_nr = re.search("([\d]+)(/)([\w]+)", info)
regex_general = re.search("(general)(/)([\w]+)", info)

if regex_nr and len(regex_nr.groups()) == 3:
number = int(regex_nr.group(1))
protocol = regex_nr.group(3)
elif regex_general and len(regex_general.groups()) == 3:
number = 0
protocol = regex_general.group(3)
else:
raise ValueError("Can't parse input string")

return Port(number, protocol)

def __eq__(self, other):
if not isinstance(other, Port):
return False
Expand All @@ -91,8 +87,6 @@ def __eq__(self, other):
return False
if other.protocol != self.protocol:
return False
if other.description != self.description:
return False

return True

Expand Down
20 changes: 10 additions & 10 deletions openvasreporting/libs/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def openvas_parser(input_files, min_lvl=Config.levels()["n"]):

for vuln in root.findall(".//results/result"):

nvt_tmp = vuln.find(".//nvt")
nvt_tmp = vuln.find("./nvt")

# VULN_NAME
vuln_name = nvt_tmp.find(".//name").text
vuln_name = nvt_tmp.find("./name").text

logging.debug("--------------------------------------------------------------------------------")
logging.debug("- {}".format(vuln_name)) # DEBUG
Expand All @@ -83,7 +83,7 @@ def openvas_parser(input_files, min_lvl=Config.levels()["n"]):
# --------------------
#
# VULN_CVSS
vuln_cvss = vuln.find(".//severity").text
vuln_cvss = vuln.find("./severity").text
if vuln_cvss is None:
vuln_cvss = 0.0
vuln_cvss = float(vuln_cvss)
Expand Down Expand Up @@ -133,20 +133,20 @@ def openvas_parser(input_files, min_lvl=Config.levels()["n"]):
# --------------------
#
# VULN_HOST
vuln_host = vuln.find(".//host").text
vuln_port = vuln.find(".//port").text
vuln_host = vuln.find("./host").text
vuln_port = vuln.find("./port").text
logging.debug("* vuln_host:\t{} port:\t{}".format(vuln_host, vuln_port)) # DEBUG

# --------------------
#
# VULN_DESCRIPTION
vuln_description = vuln.find(".//description").text
vuln_description = vuln.find("./description").text
logging.debug("* vuln_desc:\t{}".format(vuln_description)) # DEBUG

# --------------------
#
# VULN_THREAT
vuln_threat = vuln.find(".//threat").text
vuln_threat = vuln.find("./threat").text
if vuln_threat is None:
vuln_threat = Config.levels()["n"]
else:
Expand All @@ -157,14 +157,14 @@ def openvas_parser(input_files, min_lvl=Config.levels()["n"]):
# --------------------
#
# VULN_FAMILY
vuln_family = nvt_tmp.find(".//family").text
vuln_family = nvt_tmp.find("./family").text

logging.debug("* vuln_family:\t{}".format(vuln_family)) # DEBUG

# --------------------
#
# VULN_CVES
vuln_cves = nvt_tmp.find(".//cve").text
vuln_cves = nvt_tmp.find("./cve").text
if vuln_cves:
if vuln_cves.lower() == "nocve":
vuln_cves = []
Expand All @@ -176,7 +176,7 @@ def openvas_parser(input_files, min_lvl=Config.levels()["n"]):
# --------------------
#
# VULN_REFERENCES
vuln_references = nvt_tmp.find(".//xref").text
vuln_references = nvt_tmp.find("./xref").text
if vuln_references:
if vuln_references.lower() == "noxref":
vuln_references = []
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
setup(
name='OpenVAS Reporting',
description='A tool to convert OpenVAS XML into reports.',
version='1.2.1',
version='1.2.2',
long_description=long_description,
long_description_content_type='text/markdown',
author='TheGroundZero (@DezeStijn)',
Expand Down

0 comments on commit dd660a6

Please sign in to comment.