Пример #1
0
 def CommandDump(self, CommandIntro, OutputIntro, ResourceList, PluginInfo, PreviousOutput):
     output_list = []
     PluginOutputDir = self.InitPluginOutputDir(PluginInfo)
     ResourceList = sorted(ResourceList, key=lambda x: x[0] == "Extract URLs")
     for Name, Command in ResourceList:
         dump_file_name = "%s.txt" % os.path.splitext(Name)[0]  # Add txt extension to avoid wrong mimetypes
         plugin_output = dict(PLUGIN_OUTPUT)
         ModifiedCommand, FrameworkAbort, PluginAbort, TimeStr, RawOutput, PluginOutputDir = self.RunCommand(Command,
             PluginInfo, PluginOutputDir)
         plugin_output["type"] = "CommandDump"
         plugin_output["output"] = {
             "Name": self.GetCommandOutputFileNameAndExtension(Name)[0],
             "CommandIntro": CommandIntro,
             "ModifiedCommand": ModifiedCommand,
             "RelativeFilePath": self.plugin_handler.dump_output_file(dump_file_name, RawOutput, PluginInfo,
                                                                      relative_path=True),
             "OutputIntro": OutputIntro,
             "TimeStr": TimeStr
         }
         plugin_output = [plugin_output]
         # This command returns URLs for processing
         if Name == self.config.get_val('EXTRACT_URLS_RESERVED_RESOURCE_NAME'):
             #  The plugin_output output dict will be remade if the resource is of this type
             plugin_output = self.LogURLsFromStr(RawOutput)
         # TODO: Look below to handle streaming report
         if PluginAbort:  # Pass partial output to external handler:
             raise PluginAbortException(PreviousOutput + plugin_output)
         if FrameworkAbort:
             raise FrameworkAbortException(PreviousOutput + plugin_output)
         output_list += plugin_output
     return output_list
Пример #2
0
    def user_abort(self, level, partial_output=''):
        """This function handles the next steps when a user presses Ctrl-C

        :param level: The level which was aborted
        :type level: `str`
        :param partial_output: Partial output generated by the command or plugin
        :type partial_output: `str`
        :return: Message to present to the user
        :rtype: `str`
        """
        # Levels so far can be Command or Plugin
        logging.info(
            "\nThe %s was aborted by the user: Please check the report and plugin output files"
            % level)
        message = (
            "\nThe %s was aborted by the user: Please check the report and plugin output files"
            % level)
        if level == 'Command':
            option = 'p'
            if option == 'e':
                # Try to save partial plugin results.
                raise FrameworkAbortException(partial_output)
            elif option == 'p':  # Move on to next plugin.
                # Jump to next handler and pass partial output to avoid losing results.
                raise PluginAbortException(partial_output)
        return message
Пример #3
0
    def get_val(self, key):
        """Transparently gets config info from target or General.

        :param key: Key
        :type key: `str`
        :return: The value for the key
        """
        try:
            key = self.pad_key(key)
            return self.get_key_val(key)
        except KeyError:
            message = "The configuration item: %s does not exist!" % key
            # Raise plugin-level exception to move on to next plugin.
            raise PluginAbortException(message)