Exemple #1
0
    def recv_msg(self, message):

        # When an audit is finished, check if there are more running audits.
        # If there aren't any, stop the Orchestrator.
        if (message.message_type == MessageType.MSG_TYPE_CONTROL
                and message.message_code == MessageCode.MSG_CONTROL_STOP_AUDIT
                and get_audit_count() == 1):
            Config._context.send_msg(  # XXX FIXME hide this from plugins!
                message_type=MessageType.MSG_TYPE_CONTROL,
                message_code=MessageCode.MSG_CONTROL_STOP,
                message_info=True,  # True for finished, False for user cancel
                priority=MessagePriority.MSG_PRIORITY_LOW)
Exemple #2
0
    def recv_msg(self, message):

        # When an audit is finished, check if there are more running audits.
        # If there aren't any, stop the Orchestrator.
        if (
            message.message_type == MessageType.MSG_TYPE_CONTROL and
            message.message_code == MessageCode.MSG_CONTROL_STOP_AUDIT and
            get_audit_count() == 1
        ):
            Config._context.send_msg(  # XXX FIXME hide this from plugins!
                message_type = MessageType.MSG_TYPE_CONTROL,
                message_code = MessageCode.MSG_CONTROL_STOP,
                message_info = True,  # True for finished, False for user cancel
                    priority = MessagePriority.MSG_PRIORITY_LOW
            )
Exemple #3
0
 def audit_is_dead(self, audit_name):
     try:
         del self.already_seen_info[audit_name]
     except KeyError:
         pass  # may happen when only generating reports
     try:
         del self.current_plugins[audit_name]
     except KeyError:
         pass
     if get_audit_count() <= 1:  # this is the last one
         Config._context.send_msg(  # XXX FIXME hide this from plugins!
             message_type=MessageType.MSG_TYPE_CONTROL,
             message_code=MessageCode.MSG_CONTROL_STOP,
             message_info=True,  # True for finished, False for user cancel
             priority=MessagePriority.MSG_PRIORITY_LOW,
         )
Exemple #4
0
 def audit_is_dead(self, audit_name):
     try:
         del self.already_seen_info[audit_name]
     except KeyError:
         pass # may happen when only generating reports
     try:
         del self.current_plugins[audit_name]
     except KeyError:
         pass
     if get_audit_count() <= 1:  # this is the last one
         Config._context.send_msg(  # XXX FIXME hide this from plugins!
             message_type = MessageType.MSG_TYPE_CONTROL,
             message_code = MessageCode.MSG_CONTROL_STOP,
             message_info = True,  # True for finished, False for user cancel
                 priority = MessagePriority.MSG_PRIORITY_LOW,
         )
Exemple #5
0
    def recv_msg(self, message):
        if not isinstance(message, Message):
            raise TypeError("Expected Message, got %r instead" % type(message))

        print "-" * 79
        print "Message:"
        print "  Timestamp: %s" % time.ctime(message.timestamp)
        print "  Audit:     %s" % message.audit_name
        print "  Plugin:    %s" % message.plugin_id
        print "  Type:      %s" % MessageType.get_name_from_value(
            message.message_type)
        print "  Code:      %s" % MessageCode.get_name_from_value_and_type(
            message.message_code, message.message_type)
        print "  Priority:  %s" % MessagePriority.get_name_from_value(
            message.priority)
        print "  Payload:   %r" % (message.message_info, )
        print

        if message.message_type == MessageType.MSG_TYPE_CONTROL:

            if message.message_code == MessageCode.MSG_CONTROL_STOP_AUDIT:
                if get_audit_count() == 1:
                    Config._context.send_msg(
                        message_type=MessageType.MSG_TYPE_CONTROL,
                        message_code=MessageCode.MSG_CONTROL_STOP,
                        message_info=True,
                        priority=MessagePriority.MSG_PRIORITY_LOW)

            elif message.message_code == MessageCode.MSG_CONTROL_LOG:
                (text, level, is_error) = message.message_info
                if is_error:
                    print colorize(text, "magenta")
                else:
                    print colorize(text, "cyan")

            elif message.message_code == MessageCode.MSG_CONTROL_ERROR:
                (description, traceback) = message.message_info
                print colorize(description, "magenta")
                print colorize(traceback, "magenta")

            elif message.message_code == MessageCode.MSG_CONTROL_WARNING:
                for w in message.message_info:
                    formatted = warnings.formatwarning(w.message, w.category,
                                                       w.filename, w.lineno,
                                                       w.line)
                    print colorize(formatted, "yellow")
Exemple #6
0
    def recv_msg(self, message):
        if not isinstance(message, Message):
            raise TypeError("Expected Message, got %r instead" % type(message))

        print "-" * 79
        print "Message:"
        print "  Timestamp: %s" % time.ctime(message.timestamp)
        print "  Audit:     %s" % message.audit_name
        print "  Plugin:    %s" % message.plugin_id
        print "  Type:      %s" % MessageType.get_name_from_value(message.message_type)
        print "  Code:      %s" % MessageCode.get_name_from_value_and_type(message.message_code, message.message_type)
        print "  Priority:  %s" % MessagePriority.get_name_from_value(message.priority)
        print "  Payload:   %r" % (message.message_info,)
        print

        if message.message_type == MessageType.MSG_TYPE_CONTROL:

            if message.message_code == MessageCode.MSG_CONTROL_STOP_AUDIT:
                if get_audit_count() == 1:
                    Config._context.send_msg(
                        message_type = MessageType.MSG_TYPE_CONTROL,
                        message_code = MessageCode.MSG_CONTROL_STOP,
                        message_info = True,
                            priority = MessagePriority.MSG_PRIORITY_LOW
                    )

            elif message.message_code == MessageCode.MSG_CONTROL_LOG:
                (text, level, is_error) = message.message_info
                if is_error:
                    print colorize(text, "magenta")
                else:
                    print colorize(text, "cyan")

            elif message.message_code == MessageCode.MSG_CONTROL_ERROR:
                (description, traceback) = message.message_info
                print colorize(description, "magenta")
                print colorize(traceback, "magenta")

            elif message.message_code == MessageCode.MSG_CONTROL_WARNING:
                for w in message.message_info:
                    formatted = warnings.formatwarning(w.message, w.category, w.filename, w.lineno, w.line)
                    print colorize(formatted, "yellow")
Exemple #7
0
    def recv_msg(self, message):

        # Process status messages.
        if message.message_type == MessageType.MSG_TYPE_STATUS:

            # A plugin has started.
            if message.message_code == MessageCode.MSG_STATUS_PLUGIN_BEGIN:

                # Create a simple ID for the plugin execution.
                id_dict = self.current_plugins[Config.audit_name][message.plugin_id]
                simple_id = len(id_dict)
                id_dict[message.ack_identity] = simple_id

                # Show a message to the user.
                m_plugin_name = self.get_plugin_name(message.plugin_id, message.ack_identity)
                m_plugin_name = colorize(m_plugin_name, "informational")
                m_text        = "[*] %s: Started." % m_plugin_name
                Console.display(m_text)

            # A plugin has ended.
            elif message.message_code == MessageCode.MSG_STATUS_PLUGIN_END:

                # Show a message to the user.
                m_plugin_name = self.get_plugin_name(message.plugin_id, message.ack_identity)
                m_plugin_name = colorize(m_plugin_name, "informational")
                m_text        = "[*] %s: Finished." % m_plugin_name
                Console.display(m_text)

                # Free the simple ID for the plugin execution.
                del self.current_plugins[Config.audit_name][message.plugin_id][message.ack_identity]

            # A plugin has advanced.
            elif message.message_code == MessageCode.MSG_STATUS_PLUGIN_STEP:

                # Don't show this event in quiet mode.
                if Console.level >= Console.VERBOSE:

                    # Get the plugin name.
                    m_plugin_name = self.get_plugin_name(message.plugin_id, message.ack_identity)
                    m_plugin_name = colorize(m_plugin_name, "informational")

                    # Get the progress percentage.
                    m_progress = message.message_info
                    if m_progress is not None:
                        m_progress_h   = int(m_progress)
                        m_progress_l   = int((m_progress - float(m_progress_h)) * 100)
                        m_progress_txt = colorize("%i.%.2i%%" % (m_progress_h, m_progress_l), "middle")
                        m_progress_txt = m_progress_txt + " percent done..."
                    else:
                        m_progress_txt = "Working..."

                    # Show it to the user.
                    m_text = "[*] %s: %s" % (m_plugin_name, m_progress_txt)
                    Console.display(m_text)

        # Process control messages.
        elif message.message_type == MessageType.MSG_TYPE_CONTROL:

            # When an audit is finished, check if there are more running audits.
            # If there aren't any, stop the Orchestrator.
            if message.message_code == MessageCode.MSG_CONTROL_STOP_AUDIT:
                try:
                    del self.already_seen_info[Config.audit_name]
                except KeyError:
                    pass # may happen when generating reports only
                if get_audit_count() == 1:  # this is the last one
                    Config._context.send_msg(  # XXX FIXME hide this from plugins!
                        message_type = MessageType.MSG_TYPE_CONTROL,
                        message_code = MessageCode.MSG_CONTROL_STOP,
                        message_info = True,  # True for finished, False for user cancel
                            priority = MessagePriority.MSG_PRIORITY_LOW
                    )

            # Show log messages. The verbosity is sent by Logger.
            elif message.message_code == MessageCode.MSG_CONTROL_LOG:
                (text, level, is_error) = message.message_info
                if Console.level >= level:
                    try:
                        m_plugin_name = self.get_plugin_name(message.plugin_id, message.ack_identity)
                    except Exception:
                        m_plugin_name = "GoLismero"
                    m_plugin_name = colorize(m_plugin_name, 'informational')
                    text = colorize(text, 'middle')
                    if is_error:
                        text = "[!] %s: %s" % (m_plugin_name, text)
                        Console.display_error(text)
                    else:
                        text = "[*] %s: %s" % (m_plugin_name, text)
                        Console.display(text)

            # Show plugin errors.
            # Only the description in standard level,
            # full traceback in more verbose level.
            if message.message_code == MessageCode.MSG_CONTROL_ERROR:
                (description, traceback) = message.message_info
                try:
                    m_plugin_name = self.get_plugin_name(message.plugin_id, message.ack_identity)
                except Exception:
                    m_plugin_name = "GoLismero"
                text        = "[!] Plugin '%s' error: %s " % (m_plugin_name, str(description))
                text        = colorize(text, 'critical')
                traceback   = colorize(traceback, 'critical')
                Console.display_error(text)
                Console.display_error_more_verbose(traceback)

            # Show plugin warnings.
            # Only the description in verbose level,
            # full traceback in more verbose level.
            elif message.message_code == MessageCode.MSG_CONTROL_WARNING:
                for w in message.message_info:
                    if Console.level >= Console.MORE_VERBOSE:
                        formatted = warnings.formatwarning(w.message, w.category, w.filename, w.lineno, w.line)
                    elif Console.level >= Console.VERBOSE:
                        formatted = w.message
                    else:
                        formatted = None
                    if formatted:
                        m_plugin_name = self.get_plugin_name(message.plugin_id, message.ack_identity)
                        text = "[!] Plugin '%s' warning: %s " % (m_plugin_name, str(formatted))
                        text = colorize(text, 'low')
                        Console.display_error(text)
Exemple #8
0
    def recv_msg(self, message):

        # Process status messages
        if message.message_type == MessageType.MSG_TYPE_STATUS:

            if message.message_code == MessageCode.MSG_STATUS_PLUGIN_BEGIN:
                m_plugin_name = self.get_plugin_name(message.plugin_name)
                m_plugin_name = colorize(m_plugin_name, "info")
                m_text        = "[*] %s: Started." % m_plugin_name

                Console.display(m_text)

            elif message.message_code == MessageCode.MSG_STATUS_PLUGIN_END:
                m_plugin_name = self.get_plugin_name(message.plugin_name)
                m_plugin_name = colorize(m_plugin_name, "info")
                m_text        = "[*] %s: Finished." % m_plugin_name

                Console.display(m_text)

            elif message.message_code == MessageCode.MSG_STATUS_PLUGIN_STEP:

                if Console.level >= Console.VERBOSE:
                    m_id, m_progress = message.message_info

                    m_plugin_name = self.get_plugin_name(message.plugin_name)
                    m_plugin_name = colorize(m_plugin_name, "info")

                    if m_progress is not None:
                        m_progress_h   = int(m_progress)
                        m_progress_l   = int((m_progress - float(m_progress_h)) * 100)
                        m_progress_txt = colorize("%i.%.2i%%" % (m_progress_h, m_progress_l), "middle")
                        m_progress_txt = m_progress_txt + " percent done..."
                    else:
                        m_progress_txt = "Working..."

                    m_text = "[*] %s: %s" % (m_plugin_name, m_progress_txt)

                    Console.display(m_text)

        # Process control messages
        elif message.message_type == MessageType.MSG_TYPE_CONTROL:

            # When an audit is finished, check if there are more running audits.
            # If there aren't any, stop the Orchestrator.
            if message.message_code == MessageCode.MSG_CONTROL_STOP_AUDIT:
                if get_audit_count() == 1:  # this is the last one
                    Config._context.send_msg(  # XXX FIXME hide this from plugins!
                        message_type = MessageType.MSG_TYPE_CONTROL,
                        message_code = MessageCode.MSG_CONTROL_STOP,
                        message_info = True,  # True for finished, False for user cancel
                            priority = MessagePriority.MSG_PRIORITY_LOW
                    )

            # Show log messages
            # (The verbosity is sent by Logger)
            elif message.message_code == MessageCode.MSG_CONTROL_LOG:
                (text, level, is_error) = message.message_info
                if Console.level >= level:
                    try:
                        m_plugin_name = self.get_plugin_name(message.plugin_name)
                    except Exception:
                        m_plugin_name = "GoLismero"
                    m_plugin_name = colorize(m_plugin_name, 'info')
                    text = colorize(text, 'middle')
                    if is_error:
                        text = "[!] %s: %s" % (m_plugin_name, text)
                        Console.display_error(text)
                    else:
                        text = "[*] %s: %s" % (m_plugin_name, text)
                        Console.display(text)

            # Show plugin errors
            # (Only the description in standard level,
            # full traceback in more verbose level)
            if message.message_code == MessageCode.MSG_CONTROL_ERROR:
                (description, traceback) = message.message_info
                try:
                    m_plugin_name = self.get_plugin_name(message.plugin_name)
                except Exception:
                    m_plugin_name = "GoLismero"
                text        = "[!] Plugin '%s' error: %s " % (m_plugin_name, str(description))
                text        = colorize(text, 'critical')
                traceback   = colorize(traceback, 'critical')
                Console.display_error(text)
                Console.display_error_more_verbose(traceback)

            # Show plugin warnings
            # (Only the description in verbose level,
            # full traceback in more verbose level)
            elif message.message_code == MessageCode.MSG_CONTROL_WARNING:
                for w in message.message_info:
                    if Console.level >= Console.MORE_VERBOSE:
                        formatted = warnings.formatwarning(w.message, w.category, w.filename, w.lineno, w.line)
                    elif Console.level >= Console.VERBOSE:
                        formatted = w.message
                    else:
                        formatted = None
                    if formatted:
                        m_plugin_name = self.get_plugin_name(message.plugin_name)
                        text = "[!] Plugin '%s' warning: %s " % (m_plugin_name, str(formatted))
                        text = colorize(text, 'low')
                        Console.display_error(text)
Exemple #9
0
    def recv_msg(self, message):

        # Process status messages
        if message.message_type == MessageType.MSG_TYPE_STATUS:

            if message.message_code == MessageCode.MSG_STATUS_PLUGIN_BEGIN:
                m_plugin_name = self.get_plugin_name(message.plugin_name)
                m_plugin_name = colorize(m_plugin_name, "info")
                m_text = "[*] %s: Started." % m_plugin_name

                Console.display(m_text)

            elif message.message_code == MessageCode.MSG_STATUS_PLUGIN_END:
                m_plugin_name = self.get_plugin_name(message.plugin_name)
                m_plugin_name = colorize(m_plugin_name, "info")
                m_text = "[*] %s: Finished." % m_plugin_name

                Console.display(m_text)

            elif message.message_code == MessageCode.MSG_STATUS_PLUGIN_STEP:

                if Console.level >= Console.VERBOSE:
                    m_id, m_progress = message.message_info

                    m_plugin_name = self.get_plugin_name(message.plugin_name)
                    m_plugin_name = colorize(m_plugin_name, "info")

                    if m_progress is not None:
                        m_progress_h = int(m_progress)
                        m_progress_l = int(
                            (m_progress - float(m_progress_h)) * 100)
                        m_progress_txt = colorize(
                            "%i.%.2i%%" % (m_progress_h, m_progress_l),
                            "middle")
                        m_progress_txt = m_progress_txt + " percent done..."
                    else:
                        m_progress_txt = "Working..."

                    m_text = "[*] %s: %s" % (m_plugin_name, m_progress_txt)

                    Console.display(m_text)

        # Process control messages
        elif message.message_type == MessageType.MSG_TYPE_CONTROL:

            # When an audit is finished, check if there are more running audits.
            # If there aren't any, stop the Orchestrator.
            if message.message_code == MessageCode.MSG_CONTROL_STOP_AUDIT:
                if get_audit_count() == 1:  # this is the last one
                    Config._context.send_msg(  # XXX FIXME hide this from plugins!
                        message_type=MessageType.MSG_TYPE_CONTROL,
                        message_code=MessageCode.MSG_CONTROL_STOP,
                        message_info=
                        True,  # True for finished, False for user cancel
                        priority=MessagePriority.MSG_PRIORITY_LOW)

            # Show log messages
            # (The verbosity is sent by Logger)
            elif message.message_code == MessageCode.MSG_CONTROL_LOG:
                (text, level, is_error) = message.message_info
                if Console.level >= level:
                    try:
                        m_plugin_name = self.get_plugin_name(
                            message.plugin_name)
                    except Exception:
                        m_plugin_name = "GoLismero"
                    m_plugin_name = colorize(m_plugin_name, 'info')
                    text = colorize(text, 'middle')
                    if is_error:
                        text = "[!] %s: %s" % (m_plugin_name, text)
                        Console.display_error(text)
                    else:
                        text = "[*] %s: %s" % (m_plugin_name, text)
                        Console.display(text)

            # Show plugin errors
            # (Only the description in standard level,
            # full traceback in more verbose level)
            if message.message_code == MessageCode.MSG_CONTROL_ERROR:
                (description, traceback) = message.message_info
                try:
                    m_plugin_name = self.get_plugin_name(message.plugin_name)
                except Exception:
                    m_plugin_name = "GoLismero"
                text = "[!] Plugin '%s' error: %s " % (m_plugin_name,
                                                       str(description))
                text = colorize(text, 'critical')
                traceback = colorize(traceback, 'critical')
                Console.display_error(text)
                Console.display_error_more_verbose(traceback)

            # Show plugin warnings
            # (Only the description in verbose level,
            # full traceback in more verbose level)
            elif message.message_code == MessageCode.MSG_CONTROL_WARNING:
                for w in message.message_info:
                    if Console.level >= Console.MORE_VERBOSE:
                        formatted = warnings.formatwarning(
                            w.message, w.category, w.filename, w.lineno,
                            w.line)
                    elif Console.level >= Console.VERBOSE:
                        formatted = w.message
                    else:
                        formatted = None
                    if formatted:
                        m_plugin_name = self.get_plugin_name(
                            message.plugin_name)
                        text = "[!] Plugin '%s' warning: %s " % (
                            m_plugin_name, str(formatted))
                        text = colorize(text, 'low')
                        Console.display_error(text)