How to use the pypsrp.messages.MessageType function in pypsrp

To help you get started, we’ve selected a few pypsrp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jborean93 / pypsrp / pypsrp / messages.py View on Github external
:param mi:
        :param mp:
        """
        super(RunspacePoolHostCall, self).__init__()
        self._extended_properties = (
            ('ci', ObjectMeta("I64", name="ci")),
            ('mi', ObjectMeta("Obj", name="mi", object=HostMethodIdentifier)),
            ('mp', ListMeta(name="mp"))
        )
        self.ci = ci
        self.mi = mi
        self.mp = mp


class RunspacePoolHostResponse(ComplexObject):
    MESSAGE_TYPE = MessageType.RUNSPACEPOOL_HOST_RESPONSE

    def __init__(self, ci=None, mi=None, mr=None, me=None):
        """
        [MS-PSRP] 2.2.2.16 RUNSPACEPOOL_HOST_RESPONSE Message
        https://msdn.microsoft.com/en-us/library/dd358453.aspx

        :param ci:
        :param mi:
        :param mr:
        :param me:
        """
        super(RunspacePoolHostResponse, self).__init__()
        self._extended_properties = (
            ('ci', ObjectMeta("I64", name="ci")),
            ('mi', ObjectMeta("Obj", name="mi", object=HostMethodIdentifier)),
            ('mr', ObjectMeta(name="mr")),
github jborean93 / pypsrp / pypsrp / messages.py View on Github external
('progress_type', ObjectMeta("Obj", name="Type",
                                         object=ProgressRecordType)),
            ('seconds_remaining', ObjectMeta("I32", name="SecondsRemaining")),
        )
        self.activity = activity
        self.activity_id = activity_id
        self.description = description
        self.current_operation = current_operation
        self.parent_activity_id = parent_activity_id
        self.percent_complete = percent_complete
        self.progress_type = progress_type
        self.seconds_remaining = seconds_remaining


class InformationRecord(ComplexObject):
    MESSAGE_TYPE = MessageType.INFORMATION_RECORD

    def __init__(self, message_data=None, source=None, time_generated=None,
                 tags=None, user=None, computer=None, pid=None,
                 native_thread_id=None, managed_thread_id=None,
                 write_information_stream=None):
        """
        [MS-PSRP] 2.2.2.26 INFORMATION_RECORD Message
        https://msdn.microsoft.com/en-us/library/mt224023.aspx

        Only in protocol_version 2.3 and above

        :param kwargs:
        """
        super(InformationRecord, self).__init__()
        self._types = [
            "System.Management.Automation.InformationRecord",
github jborean93 / pypsrp / pypsrp / messages.py View on Github external
log.debug("Unpacking PSRP message of type %d: %s"
                  % (message_type, message_data))

        message_obj = {
            MessageType.SESSION_CAPABILITY: SessionCapability,
            MessageType.INIT_RUNSPACEPOOL: InitRunspacePool,
            MessageType.PUBLIC_KEY: PublicKey,
            MessageType.ENCRYPTED_SESSION_KEY: EncryptedSessionKey,
            MessageType.PUBLIC_KEY_REQUEST: PublicKeyRequest,
            MessageType.SET_MAX_RUNSPACES: SetMaxRunspaces,
            MessageType.SET_MIN_RUNSPACES: SetMinRunspaces,
            MessageType.RUNSPACE_AVAILABILITY: RunspaceAvailability,
            MessageType.RUNSPACEPOOL_STATE: RunspacePoolStateMessage,
            MessageType.CREATE_PIPELINE: CreatePipeline,
            MessageType.GET_AVAILABLE_RUNSPACES: GetAvailableRunspaces,
            MessageType.USER_EVENT: UserEvent,
            MessageType.APPLICATION_PRIVATE_DATA: ApplicationPrivateData,
            MessageType.GET_COMMAND_METADATA: GetCommandMetadata,
            MessageType.RUNSPACEPOOL_HOST_CALL: RunspacePoolHostCall,
            MessageType.RUNSPACEPOOL_HOST_RESPONSE: RunspacePoolHostResponse,
            MessageType.PIPELINE_INPUT: PipelineInput,
            MessageType.END_OF_PIPELINE_INPUT: EndOfPipelineInput,
            MessageType.PIPELINE_OUTPUT: PipelineOutput,
            MessageType.ERROR_RECORD: ErrorRecordMessage,
            MessageType.PIPELINE_STATE: PipelineState,
            MessageType.DEBUG_RECORD: DebugRecord,
            MessageType.VERBOSE_RECORD: VerboseRecord,
            MessageType.WARNING_RECORD: WarningRecord,
            MessageType.PROGRESS_RECORD: ProgressRecord,
            MessageType.INFORMATION_RECORD: InformationRecord,
            MessageType.PIPELINE_HOST_CALL: PipelineHostCall,
github jborean93 / pypsrp / pypsrp / messages.py View on Github external
:param min_runspaces:
        :param max_runspaces:
        """
        super(ConnectRunspacePool, self).__init__()
        self._extended_properties = (
            ('min_runspaces', ObjectMeta("I32", name="MinRunspaces",
                                         optional=True)),
            ('max_runspaces', ObjectMeta("I32", name="MaxRunspaces",
                                         optional=True)),
        )
        self.min_runspaces = min_runspaces
        self.max_runspaces = max_runspaces


class RunspacePoolInitData(ComplexObject):
    MESSAGE_TYPE = MessageType.RUNSPACEPOOL_INIT_DATA

    def __init__(self, min_runspaces=None, max_runspaces=None):
        """
        [MS-PSRP] 2.2.2.30 RUNSPACEPOOL_INIT_DATA Message
        https://msdn.microsoft.com/en-us/library/hh537788.aspx

        :param min_runspaces:
        :param max_runspaces:
        """
        super(RunspacePoolInitData, self).__init__()
        self._extended_properties = (
            ('min_runspaces', ObjectMeta("I32", name="MinRunspaces")),
            ('max_runspaces', ObjectMeta("I32", name="MaxRunspaces")),
        )
        self.min_runspaces = min_runspaces
        self.max_runspaces = max_runspaces
github jborean93 / pypsrp / pypsrp / powershell.py View on Github external
:param timeout: Override the default WSMan timeout when polling the
        pipeline.
        """
        try:
            responses = self.runspace_pool._receive(self.id,
                                                    timeout=timeout)
        except WSManFaultError as err:
            # operation timeout needs to be ignored and silently tried
            # again
            if err.code == 2150858793:
                responses = []
            else:
                raise err

        for response in responses:
            if response[0] == MessageType.PIPELINE_OUTPUT:
                self.output.append(response[1].data.data)
github jborean93 / pypsrp / pypsrp / messages.py View on Github external
https://msdn.microsoft.com/en-us/library/hh537788.aspx

        :param min_runspaces:
        :param max_runspaces:
        """
        super(RunspacePoolInitData, self).__init__()
        self._extended_properties = (
            ('min_runspaces', ObjectMeta("I32", name="MinRunspaces")),
            ('max_runspaces', ObjectMeta("I32", name="MaxRunspaces")),
        )
        self.min_runspaces = min_runspaces
        self.max_runspaces = max_runspaces


class ResetRunspaceState(ComplexObject):
    MESSAGE_TYPE = MessageType.RESET_RUNSPACE_STATE

    def __init__(self, ci=None):
        """
        [MS-PSRP] 2.2.2.31 RESET_RUNSPACE_STATE Message
        https://msdn.microsoft.com/en-us/library/mt224027.aspx

        :param ci: The call identifier
        """
        super(ResetRunspaceState, self).__init__()
        self._extended_properties = (
            ('ci', ObjectMeta("I64", name="ci")),
        )
        self.ci = ci
github jborean93 / pypsrp / pypsrp / messages.py View on Github external
def pack(self):
        if self.message_type == MessageType.PUBLIC_KEY_REQUEST:
            message_data = ET.Element("S")
        elif self.message_type == MessageType.END_OF_PIPELINE_INPUT:
            message_data = b""
        elif self.message_type == MessageType.PIPELINE_INPUT:
            message_data = self._serializer.serialize(self.data.data)
        elif self.message_type == MessageType.CONNECT_RUNSPACEPOOL and \
                (self.data.min_runspaces is None and
                 self.data.max_runspaces is None):
            message_data = ET.Element("S")
        else:
            message_data = self._serializer.serialize(self.data)

        if not isinstance(message_data, binary_type):
            message_data = \
                ET.tostring(message_data, encoding='utf-8', method='xml')
        log.debug("Packing PSRP message: %s" % to_string(message_data))

        data = struct.pack("
github jborean93 / pypsrp / pypsrp / powershell.py View on Github external
MessageType.RUNSPACE_AVAILABILITY:
                self._process_runspacepool_availability,
            MessageType.RUNSPACEPOOL_STATE: self._process_runspacepool_state,
            MessageType.USER_EVENT: self._process_user_event,
            MessageType.APPLICATION_PRIVATE_DATA:
                self._process_application_private_data,
            MessageType.RUNSPACEPOOL_HOST_CALL:
                self._process_runspacepool_host_call,
        }

        if pipeline is not None:
            pipeline_response_functions = {
                # The Pipeline Output isn't processes and just returned back to
                # the receive caller
                MessageType.PIPELINE_OUTPUT: None,
                MessageType.ERROR_RECORD: pipeline._process_error_record,
                MessageType.PIPELINE_STATE: pipeline._process_pipeline_state,
                MessageType.DEBUG_RECORD: pipeline._process_debug_record,
                MessageType.VERBOSE_RECORD: pipeline._process_verbose_record,
                MessageType.WARNING_RECORD: pipeline._process_warning_record,
                MessageType.PROGRESS_RECORD: pipeline._process_progress_record,
                MessageType.INFORMATION_RECORD:
                    pipeline._process_information_record,
                MessageType.PIPELINE_HOST_CALL:
                    pipeline._process_pipeline_host_call,
            }
            response_functions.update(pipeline_response_functions)

        return_values = []
        for message in messages:
            response_function = response_functions[message.message_type]
            if response_function is not None:
github jborean93 / pypsrp / pypsrp / messages.py View on Github external
class ErrorRecordMessage(ErrorRecord):
    MESSAGE_TYPE = MessageType.ERROR_RECORD

    def __init__(self, **kwargs):
        """
        [MS-PSRP] 2.2.2.20 ERROR_RECORD Message
        https://msdn.microsoft.com/en-us/library/dd342423.aspx

        :param kwargs:
        """
        super(ErrorRecordMessage, self).__init__(**kwargs)


class PipelineState(ComplexObject):
    MESSAGE_TYPE = MessageType.PIPELINE_STATE

    def __init__(self, state=None, error_record=None):
        """
        [MS-PSRP] 2.2.2.21 PIPELINE_STATE Message
        https://msdn.microsoft.com/en-us/library/dd304923.aspx

        :param state: The state of the pipeline
        :param error_record:
        """
        super(PipelineState, self).__init__()
        self._extended_properties = (
            ('state', ObjectMeta("I32", name="PipelineState")),
            ('error_record', ObjectMeta("Obj", name="ExceptionAsErrorRecord",
                                        optional=True)),
        )
        self.state = state
github jborean93 / pypsrp / pypsrp / messages.py View on Github external
https://msdn.microsoft.com/en-us/library/dd304870.aspx

        :param max_runspaces: The maximum number of runspaces
        :param ci: The ci identifier for the CI table
        """
        super(SetMaxRunspaces, self).__init__()
        self._extended_properties = (
            ('max_runspaces', ObjectMeta("I32", name="MaxRunspaces")),
            ('ci', ObjectMeta("I64", name="CI")),
        )
        self.max_runspaces = max_runspaces
        self.ci = ci


class SetMinRunspaces(ComplexObject):
    MESSAGE_TYPE = MessageType.SET_MIN_RUNSPACES

    def __init__(self, min_runspaces=None, ci=None):
        """
        [MS-PSRP] 2.2.2.7 SET_MIN_RUNSPACES Message
        https://msdn.microsoft.com/en-us/library/dd340570.aspx

        :param max_runspaces: The minimum number of runspaces
        :param ci: The ci identifier for the CI table
        """
        super(SetMinRunspaces, self).__init__()
        self._extended_properties = (
            ('min_runspaces', ObjectMeta("I32", name="MinRunspaces")),
            ('ci', ObjectMeta("I64", name="CI")),
        )
        self.min_runspaces = min_runspaces
        self.ci = ci