Exemple #1
0
    def __init__(self, pathname, filename='*.spider', **kwargs):
        """Initialize HoppyParser.

        :param str pathname: Path to the report directory.
        :param str filename: Regex matching the report file.

        """
        FileParser.__init__(self, pathname, filename, **kwargs)
Exemple #2
0
    def __init__(self, pathname, filename='*.spider', **kwargs):
        """Initialize HoppyParser.

        :param str pathname: Path to the report directory.
        :param str filename: Regex matching the report file.

        """
        FileParser.__init__(self, pathname, filename, **kwargs)
Exemple #3
0
    def __init__(self, pathname, filename='*.txt', plugin='', light=True, first=True):
        """Initialize MetasploitParser.

        :param str pathname: Path to the report directory.
        :param str filename: Regex matching the report file.
        :param str plugin: Name of the plugin that generated the report.
        :param bool first: Only process first file (``True``) or each file that matched (``False``).

        """
        self.__plugin__ = plugin
        FileParser.__init__(self, pathname, filename, first=first)
Exemple #4
0
    def __init__(self, pathname, filename='*.txt', plugin='', first=True):
        """Initialize MetasploitParser.

        :param str pathname: Path to the report directory.
        :param str filename: Regex matching the report file.
        :param str plugin: Name of the plugin that generated the report.
        :param bool first: Only process first file (``True``) or each file that
            matched (``False``).

        """
        self.__plugin__ = plugin
        FileParser.__init__(self, pathname, filename, first=first)
Exemple #5
0
 def test_parser_file_handle_file_with_content(self, mock_recursive_find):
     try:
         str_type = basestring  # Python 2.x.
     except NameError:
         str_type = str  # Python 3.x.
     with mock.patch.object(builtins, 'open', mock.mock_open(read_data='The cake is a lie!\nThe cake is a lie!')):
         data = FileParser.handle_file('text.txt')
         self.assertIsInstance(data, str_type)
         self.assertTrue(data == 'The cake is a lie!\nThe cake is a lie!')
Exemple #6
0
    def handle_file(cls, metadatafile, reportfile):
        """Process the two report files of the Skipfish report.

        :param str metadatafile: Path to the metadata file.
        :param str reportfile: Path to the report file.
        :raises TypeError: if the files have not the right extension.
        :raises OSError: if an error occurs when reading the files.
        :raises IOError: if an error occurs when reading the files.

        :return: Both metadata and report files' contents.
        :rtype: :class:`tuple`

        """
        if not metadatafile.endswith(cls.__format__) or not reportfile.endswith(cls.__format__):
            raise TypeError("This parser only supports '%s' files" % cls.__format__)
        pathname, filename = os.path.split(metadatafile)
        metadata_stream = FileParser.handle_file(pathname=pathname, filename=filename)
        pathname, filename = os.path.split(reportfile)
        report_stream = FileParser.handle_file(pathname=pathname, filename=filename)
        return (metadata_stream, report_stream)
Exemple #7
0
 def test_parser_file_handle_file_with_content(self, mock_recursive_find):
     try:
         str_type = basestring  # Python 2.x.
     except NameError:
         str_type = str  # Python 3.x.
     with mock.patch.object(
             builtins, 'open',
             mock.mock_open(
                 read_data='The cake is a lie!\nThe cake is a lie!')):
         data = FileParser.handle_file('text.txt')
         self.assertIsInstance(data, str_type)
         self.assertTrue(data == 'The cake is a lie!\nThe cake is a lie!')
Exemple #8
0
 def test_parser_file_init_with_content(self, mock_recursive_find):
     try:
         str_type = basestring  # Python 2.x.
     except NameError:
         str_type = str  # Python 3.x.
     with mock.patch.object(
             builtins, 'open',
             mock.mock_open(
                 read_data='The cake is a lie!\nThe cake is a lie!')):
         my_fileparser = FileParser(pathname='./', filename='text.txt')
         self.assertIsInstance(my_fileparser.stream, str_type)
         self.assertTrue(my_fileparser.stream ==
                         'The cake is a lie!\nThe cake is a lie!')
Exemple #9
0
    def handle_file(cls, metadatafile, reportfile):
        """Process the two report files of the Skipfish report.

        :param str metadatafile: Path to the metadata file.
        :param str reportfile: Path to the report file.
        :raises TypeError: if the files have not the right extension.
        :raises OSError: if an error occurs when reading the files.
        :raises IOError: if an error occurs when reading the files.

        :return: Both metadata and report files' contents.
        :rtype: :class:`tuple`

        """
        if not metadatafile.endswith(
                cls.__format__) or not reportfile.endswith(cls.__format__):
            raise TypeError("This parser only supports '%s' files" %
                            cls.__format__)
        pathname, filename = os.path.split(metadatafile)
        metadata_stream = FileParser.handle_file(pathname=pathname,
                                                 filename=filename)
        pathname, filename = os.path.split(reportfile)
        report_stream = FileParser.handle_file(pathname=pathname,
                                               filename=filename)
        return (metadata_stream, report_stream)
Exemple #10
0
    def parse_report(self):
        """Parse the results of the report.

        :return: List of dicts where each one represents a discovery.
        :rtype: :class:`list`

        """
        self.vulns = [
            {'ranking': self.RANKING_SCALE[vuln.get('severity')]}
            for vuln in self.stream.findall('.//vulnerability')]
        if not self.light:
            try:
                self.vulns.append({
                    'ranking': constants.UNKNOWN,
                    'transactions': self._parse_report_full(FileParser.handle_file(self.pathname, self.__httpfile_format__))})
            except (OSError, IOError):
                # There is no additional file referencing the HTTP requests. We silently pass.
                pass
        return self.vulns
Exemple #11
0
    def parse_report(self):
        """Parse the results of the report.

        :return: List of dicts where each one represents a discovery.
        :rtype: :class:`list`

        """
        self.vulns = [{
            'ranking': self.RANKING_SCALE[vuln.get('severity')]
        } for vuln in self.stream.findall('.//vulnerability')]
        if not self.light:
            try:
                self.vulns.append({
                    'ranking':
                    constants.UNKNOWN,
                    'transactions':
                    self._parse_report_full(
                        FileParser.handle_file(self.pathname,
                                               self.__httpfile_format__))
                })
            except (OSError, IOError):
                # There is no additional file referencing the HTTP requests. We silently pass.
                pass
        return self.vulns
Exemple #12
0
 def test_parser_file_handle_file_no_file(self, mock_recursive_find):
     with self.assertRaises(IOError):
         FileParser.handle_file('/dev/null')
Exemple #13
0
 def test_parser_file_handle_file_no_file(self, mock_recursive_find):
     with self.assertRaises(IOError):
         FileParser.handle_file('/dev/null')
Exemple #14
0
 def test_parser_file_init_no_file(self, mock_recursive_find):
     with self.assertRaises(IOError):
         FileParser(pathname='/dev/', filename='null')