Skip to content
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
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
language: python
python:
- '2.6'
- '2.7'
- '3.3'
- '3.4'
- '3.5'
- '3.6'
services:
- elasticsearch
- mongodb
install:
- pip install pep8 --use-mirrors
- pip install pyflakes --use-mirrors
- pip install pep8
- pip install pyflakes
- pip install coveralls
- pip install jsonpickle
- pip install pymongo elasticsearch
- pip freeze
- python setup.py install
before_script:
- pep8 . --exclude test,docs,examples,build --ignore=W503,E123
- pyflakes libnessus/*.py
- sleep 10
script: nosetests --with-coverage --cover-package=libnessus
Expand Down
4 changes: 4 additions & 0 deletions libnessus/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class MissingAttribute(Exception):
"""Error when Nessus report items are missing essential properties"""
def __init__(self, *args, **kwargs):
Exception.__init__(self, "Report object is missing essential attributes", *args, **kwargs)
32 changes: 16 additions & 16 deletions libnessus/objects/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ class NessusReport(object):
in a easy way the content, and present some metadata
"""
def __init__(self, name, hosts):
'''
"""
Description: Constructor of NessusReport
:param name: name of the report
:type name: str
:param hosts: list of NessusReportHost
:type hosts: list
:return: NessusReport
:rtype: NessusReport
'''
"""
self.name = name
self.__hosts = hosts
self.__start = self.__compute_started(self.__hosts)
self.__end = self.__compute_ended(self.__hosts)

def __repr__(self):
'''
"""
Description: compute a string of the obj
:return: description de la valeur de retour
:rtype: str
'''
"""
return "{name} {total} {elapsed}".format(name=self.name,
total=self.hosts_total,
elapsed=self.elapsed)
Expand All @@ -43,13 +43,13 @@ def hosts(self):
return self.__hosts

def save(self, backend):
'''
"""
Description: allow to persist to a backend
:param backend: libnessus.plugins.PluginBackend object.
:type arg1: PluginBackend
:return: The primary key of the stored object is returned.
:rtype: str
'''
"""
try:
_id = backend.insert(self)
return _id
Expand All @@ -58,24 +58,24 @@ def save(self, backend):
raise

def iscomparable(self, other):
'''
"""
description: check if two obj are comparable
by checking the class name
:param other: nessusreport
:type other: nessusreport
:raises: typeerror if not comparable
'''
"""
if not isinstance(other, self.__class__):
raise TypeError(("non sense incompatibe object : ", self, other))

def __eq__(self, other):
'''
"""
Description: compare obj as equal
:param other: another report
:type other: NessusReport
:return: boolean
:rtype: boolean
'''
"""
try:
self.iscomparable(other)
rdict = self.diff(other)
Expand All @@ -89,13 +89,13 @@ def __eq__(self, other):
raise etyperr

def __ne__(self, other):
'''
"""
Description: compare obj as !=
:param other: another report
:type other: NessusReport
:return: boolean
:rtype: boolean
'''
"""
try:
self.iscomparable(other)
rdict = self.diff(other)
Expand All @@ -105,12 +105,12 @@ def __ne__(self, other):
raise etyperr

def __get_dict(self):
'''
"""
Description: get a dict representation of the object
Needed to transform the obj in a dict representation to use dictdiffer
:return: dict representation of the object
:rtype: dict
'''
"""
rdict = {}
rdict['name'] = self.name
hostitem = dict(
Expand All @@ -121,13 +121,13 @@ def __get_dict(self):
return rdict

def diff(self, other):
'''
"""
Description: diff object and provide the differences
:param other: obj to compare to
:type other: NessusReport
:return: a dict of all the differences
:rtype: dict
'''
"""
diff = DictDiffer(self.__get_dict(), other.__get_dict())
rdict = {}
rdict["removed"] = diff.removed()
Expand Down
43 changes: 22 additions & 21 deletions libnessus/objects/reporthost.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#!/usr/bin/env python
'''
"""
File: reporthost.py
Author: Me
Description:
'''
"""

from libnessus.objects.dictdiffer import DictDiffer
from libnessus.objects import reportlogger
from libnessus import exceptions as NessusExceptions

log = reportlogger.ReportLogger

class NessusReportHost(object):
'''
"""
Description: Represent an object NessusReportHost in a nessus xml
'''
"""
def __init__(self, host_properties={}, report_items=[]):
_minimal_attr = set(['HOST_START', 'HOST_END', 'host-ip', 'name'])
self._hostprop_attr = set(host_properties.keys())
Expand All @@ -20,19 +23,17 @@ def __init__(self, host_properties={}, report_items=[]):
if len(_missing_attr) == 0:
self.__host_properties = host_properties
else:
raise Exception("Not all the attributes to create a decent "
log.debug("Host Missing Attributes: ")
log.debug(host_properties)
raise NessusExceptions.MissingAttribute("Not all the attributes to create a decent "
"NessusReportHost are available. "
"Missing: {}".format(" ".join(_missing_attr)))

self.__report_items = report_items

def __repr__(self):
"""return a string representation of the obj nessusHost"""
retstr = "{0} {1} {2} {3}".format(self.name,
self.address,
self.get_host_properties,
self.get_total_vuln)
return retstr
return "{0} {1} {2} {3}".format(self.name, self.address, self.get_host_properties, self.get_total_vuln)

def __hash__(self):
""":return: hash function to be able to add object to dict/set
Expand All @@ -41,26 +42,26 @@ def __hash__(self):
return hash(self.address)

def iscomparable(self, other):
'''
"""
Description: check if two obj are comparable
by checking the class name and adress value are equal
:param other: NessusReportHost
:type other: NessusReportHost
:raises: TypeError if not comparable
'''
"""
if not isinstance(other, self.__class__):
raise TypeError(("Non sense incompatibe object : ", self, other))
if self.address != other.address:
raise TypeError(("Address need to be == : ", self, other))

def __eq__(self, other):
'''
"""
Description: compare all properties and reportitem
:param other: the object to compare
:type other: NessusReportHost
:return: true if equal
:rtype: boolean
'''
"""
try:
self.iscomparable(other)
except TypeError as etyperr:
Expand All @@ -74,13 +75,13 @@ def __eq__(self, other):
return res_pro

def __ne__(self, other):
'''
"""
Description:
:param other: the object to compare
:type other: NessusReportHost
:return: true if equal
:rtype: boolean
'''
"""
try:
self.iscomparable(other)
except TypeError as etyperr:
Expand All @@ -90,13 +91,13 @@ def __ne__(self, other):
return res_pro

def __get_dict(self):
'''
"""
Description: get a dict representation of the object
Needed because the object has 2 main component :
a dict and a table of ReportItem
:return: dict representation of the object
:rtype: dict
'''
"""
rdict = self.get_host_properties.copy()
# add reportitem in the dict in the form
# key = {'NessusReportItem::10544': NessusReportItem,}
Expand All @@ -108,13 +109,13 @@ def __get_dict(self):
return rdict

def diff(self, other):
'''
"""
Description: compute a diff dict obj
:param other: the object to compare
:type other: NessusReportHost
:return:
:rtype: dict
'''
"""
diff = DictDiffer(self.__get_dict(), other.__get_dict())
rdict = {}
rdict["removed"] = diff.removed()
Expand Down Expand Up @@ -152,7 +153,7 @@ def get_host_properties(self):

@property
def get_hostprop_attr(self):
"""Return a set of keys reprsenting all properties' key
"""Return a set of keys representing all properties' key
:return: set
"""
return self._hostprop_attr
Expand Down
29 changes: 20 additions & 9 deletions libnessus/objects/reportitem.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
'''
"""
File: vuln.py
Description:
'''

"""
from libnessus import exceptions
from libnessus.objects.dictdiffer import DictDiffer


Expand All @@ -28,7 +28,7 @@ def __init__(self, vuln_info=None):
if len(_missing_attr) == 0:
self.__vuln_info = vuln_info
else:
raise Exception("Not all the attributes to create a decent "
raise exceptions.MissingAttribute("Not all the attributes to create a decent "
"NessusVuln object are available. "
"Missing: ", _missing_attr)

Expand All @@ -49,13 +49,13 @@ def __hash__(self):
return hash(self.plugin_id)

def iscomparable(self, other):
'''
"""
Description: check if two obj are comparable
by checking the class name and plugin_id value are equal
:param other: NessusReportItem
:type other: NessusReportItem
:raises: TypeError if not comparable
'''
"""
if not isinstance(other, self.__class__):
raise TypeError(("Non sense incompatibe object : ", self, other))
if self.plugin_id != other.plugin_id:
Expand Down Expand Up @@ -95,7 +95,7 @@ def __ne__(self, other):
)

def diff(self, other):
'''
"""
Description: Compare two NessusReportItem
:param other: NessusReportItem
:type other: NessusReportItem
Expand All @@ -104,7 +104,7 @@ def diff(self, other):
get_vuln_info property that have changed
:rtype: dict
:raises: TypeError
'''
"""
try:
self.iscomparable(other)
except TypeError as etyperr:
Expand Down Expand Up @@ -174,6 +174,17 @@ def plugin_name(self):
plugin_name = self.__vuln_info['pluginName']
return plugin_name

@property
def cve(self):
"""
Get CVE or return empty string
:return str
"""
for (k, v) in self.__vuln_info.items():
if k == 'cve':
return str(v)
return ''

@property
def plugin_family(self):
"""
Expand Down Expand Up @@ -255,7 +266,7 @@ def description(self):
@property
def solution(self):
"""
Get the sulution provide by nessus
Get the solution provide by nessus
:return str
"""
return self.__vuln_info['solution']
Loading