Beispiel #1
0
 def __run_plugin__ (self, filename, verbose, raw):
   try:
     plugin = Plugin (filename, self.__ossim_config, self.__severity_list, verbose, raw)
   except (PluginError, PluginConfigParserError) as e:
     if verbose > 0:
       print ''
       Output.warning (e.msg)
     else:
       self.__summary.append ({'plugin': e.plugin, 'warning': e.msg})
   except Exception as e:
     print ''
     Output.error ('Unknown error parsing plugin "%s": %s' % (filename, str(e)))
   else:
     if (plugin.get_enable()) and (plugin.get_checks_len() > 0) and (plugin.check_category (self.__category_list)):
       self.__summary.append (plugin.run ())
     else:
       del plugin
Beispiel #2
0
 def __run_plugin__(self, filename, verbose, raw):
     try:
         plugin = Plugin(filename, self.__ossim_config,
                         self.__severity_list, verbose, raw)
     except (PluginError, PluginConfigParserError) as e:
         if verbose > 0:
             print ''
             Output.warning(e.msg)
         else:
             self.__summary.append({'plugin': e.plugin, 'warning': e.msg})
     except Exception as e:
         print ''
         Output.error('Unknown error parsing plugin "%s": %s' %
                      (filename, str(e)))
     else:
         if (plugin.get_enable()) and (plugin.get_checks_len() > 0) and (
                 plugin.check_category(self.__category_list)):
             self.__summary.append(plugin.run())
         else:
             del plugin
Beispiel #3
0
    def __run_plugin__(self, filename, verbose, raw):
        # Parse the plugin configuration file.
        # Check if file exists
        if not path.isfile(filename):
            msg = 'Plugin file does not exist: %s' % filename
            self.__generate_blocked_output(config_file=None,
                                           plugin=filename,
                                           plugin_data={},
                                           sections=[],
                                           error_msg=msg)
            return

        # Check for file extension.
        if not filename.endswith('.plg'):
            msg = 'File extension is not .plg'
            self.__generate_blocked_output(config_file=None,
                                           plugin=filename,
                                           plugin_data={},
                                           sections=[],
                                           error_msg=msg)
            return

        # Check for db connections and some other basic param config
        cfg_msg = ''
        for key in self.__successful_config.keys():
            if not self.__successful_config[key]['result']:
                cfg_msg = ';'.join([cfg_msg, self.__successful_config[key]['error']])
        if cfg_msg != '':
            self.__generate_blocked_output(config_file=None,
                                           plugin=filename,
                                           plugin_data={},
                                           sections=[],
                                           error_msg=cfg_msg)

        config_file = None
        try:
            config_file = self.__load_plugin_file(filename)
        except PluginError as e:
            self.__generate_blocked_output(config_file=None,
                                           plugin=e.plugin,
                                           plugin_data={},
                                           sections=[],
                                           error_msg=e.msg)

            return

        # Fill the Plugin Object
        if config_file:
            try:
                plugin = Plugin(filename,
                                config_file,
                                self.__alienvault_config,
                                self.__severity_list,
                                self.__appliance_type_list,
                                self.__ignore_dummy_platform,
                                verbose,
                                raw)

                if (plugin.get_checks_len() > 0) and (plugin.check_category(self.__category_list)):
                    result = plugin.run()
                    self.__in_strike_zone &= result.get('strike_zone', True)
                    self.__summary[plugin.get_name()] = result
                else:
                    del plugin

            except (PluginError, PluginConfigParserError, CheckError) as e:

                if verbose > 0:
                    Output.warning(e.msg)

                sections = []
                try:
                    sections = config_file.sections()
                except Exception:
                    pass

                self.__generate_blocked_output(config_file=config_file,
                                               plugin=e.plugin,
                                               plugin_data=e.kwargs,
                                               sections=sections,
                                               error_msg=e.msg)

            except KeyError, msg:
                Output.error('Unknown error running plugin "%s": %s' % (filename, str(msg)))
Beispiel #4
0
    def __run_plugin__(self, filename, verbose, raw):
        # Parse the plugin configuration file.
        # Check if file exists
        if not path.isfile(filename):
            msg = 'Plugin file does not exist: %s' % filename
            self.__generate_blocked_output(config_file=None,
                                           plugin=filename,
                                           plugin_data={},
                                           sections=[],
                                           error_msg=msg)
            return

        # Check for file extension.
        if not filename.endswith('.plg'):
            msg = 'File extension is not .plg'
            self.__generate_blocked_output(config_file=None,
                                           plugin=filename,
                                           plugin_data={},
                                           sections=[],
                                           error_msg=msg)
            return

        # Check for db connections and some other basic param config
        cfg_msg = ''
        for key in self.__successful_config.keys():
            if not self.__successful_config[key]['result']:
                cfg_msg = ';'.join(
                    [cfg_msg, self.__successful_config[key]['error']])
        if cfg_msg != '':
            self.__generate_blocked_output(config_file=None,
                                           plugin=filename,
                                           plugin_data={},
                                           sections=[],
                                           error_msg=cfg_msg)

        config_file = None
        try:
            config_file = self.__load_plugin_file(filename)
        except PluginError as e:
            self.__generate_blocked_output(config_file=None,
                                           plugin=e.plugin,
                                           plugin_data={},
                                           sections=[],
                                           error_msg=e.msg)

            return

        # Fill the Plugin Object
        if config_file:
            try:
                plugin = Plugin(filename, config_file,
                                self.__alienvault_config, self.__severity_list,
                                self.__appliance_type_list,
                                self.__ignore_dummy_platform, verbose, raw)

                if (plugin.get_checks_len() > 0) and (plugin.check_category(
                        self.__category_list)):
                    result = plugin.run()
                    self.__in_strike_zone &= result.get('strike_zone', True)
                    self.__summary[plugin.get_name()] = result
                else:
                    del plugin

            except (PluginError, PluginConfigParserError, CheckError) as e:

                if verbose > 0:
                    Output.warning(e.msg)

                sections = []
                try:
                    sections = config_file.sections()
                except Exception:
                    pass

                self.__generate_blocked_output(config_file=config_file,
                                               plugin=e.plugin,
                                               plugin_data=e.kwargs,
                                               sections=sections,
                                               error_msg=e.msg)

            except KeyError, msg:
                Output.error('Unknown error running plugin "%s": %s' %
                             (filename, str(msg)))