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

Improve vt element regarding dates, empty elements and tags #31

Merged
merged 5 commits into from
Nov 13, 2018
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
15 changes: 12 additions & 3 deletions ospd_openvas/nvticache.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,17 @@ def get_nvt_metadata(oid):

custom = dict()
for child, res in zip(subelem, resp):
if child not in ['cve', 'bid', 'xref', ]:
if child not in ['cve', 'bid', 'xref', 'tag',] and res:
custom[child] = res
elif child == 'tag':
tags = res.split('|')
for tag in tags:
try:
_tag, _value = tag.split('=', 1)
except ValueError:
logger.error('Tag %s in %s has no value.' % (_tag, oid))
continue
custom[_tag] = _value

return custom

Expand Down Expand Up @@ -194,7 +203,7 @@ def get_nvt_severity(ctx, tag=None, oid=None):
else:
return '10'

if tag and 'cvess_base' in tag:
return tag['cvess_base']
if tag and 'cvss_base' in tag:
return tag['cvss_base']

return ''
35 changes: 28 additions & 7 deletions ospd_openvas/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,23 @@ def load_vts(self):
str_out = True
for oid in oids:
vt_id = oid[1]
filename = oid[0].split(':')
ret = self.add_vt(vt_id,
name=filename[1],
vt_params=nvti.get_nvt_params(vt_id),
vt_refs=nvti.get_nvt_refs(vt_id),
custom=nvti.get_nvt_metadata(vt_id))

_vt_params = nvti.get_nvt_params(vt_id)
_vt_refs = nvti.get_nvt_refs(vt_id)
_filename = oid[0].split(':')
_custom = nvti.get_nvt_metadata(vt_id)
_vt_creation_time = _custom.pop('creation_date')
_vt_modification_time = _custom.pop('last_modification')

ret = self.add_vt(
vt_id,
name=_filename[1],
vt_params=_vt_params,
vt_refs=_vt_refs,
custom=_custom,
vt_creation_time=_vt_creation_time,
vt_modification_time=_vt_modification_time
)
if ret == -1:
logger.info("Dupplicated VT with OID: {0}".format(vt_id))
if ret == -2:
Expand Down Expand Up @@ -341,6 +352,16 @@ def get_refs_vt_as_xml_str(vt_refs):
refs += (tostring(ref).decode('utf-8'))
return refs

@staticmethod
def get_creation_time_vt_as_xml_str(creation_time):
""" Return creation time as string."""
return creation_time

@staticmethod
def get_modification_time_vt_as_xml_str(modification_time):
""" Return modification time as string."""
return modification_time

def check(self):
""" Checks that openvassd command line tool is found and
is executable. """
Expand Down Expand Up @@ -392,7 +413,7 @@ def get_openvas_result(self, scan_id):
msg = res.split('|||')
host_aux = openvas_db.item_get_single('internal/ip')
roid = msg[3]
tag = nvti.get_nvt_tag(ctx, roid)
tag = self.vts[roid].get('custom')
rqod = nvti.get_nvt_qod(ctx, tag)
rseverity = nvti.get_nvt_severity(ctx, tag)
rname = nvti.get_nvt_name(ctx, roid)
Expand Down