Class: WinRM::PSRP::Message

Inherits:
Object
  • Object
show all
Includes:
UUID
Defined in:
lib/winrm/psrp/message.rb

Overview

Constant Summary collapse

CLIENT_DESTINATION =

Value of message destination when sent to a client

1
SERVER_DESTINATION =

Value of message destination when sent to a server

2
MESSAGE_TYPES =

All known PSRP message types

{
  session_capability:         0x00010002,
  init_runspacepool:          0x00010004,
  public_key:                 0x00010005,
  encrypted_session_key:      0x00010006,
  public_key_request:         0x00010007,
  connect_runspacepool:       0x00010008,
  runspace_init_data:         0x0002100b,
  reset_runspace_state:       0x0002100c,
  set_max_runspaces:          0x00021002,
  set_min_runspaces:          0x00021003,
  runspace_availability:      0x00021004,
  runspacepool_state:         0x00021005,
  create_pipeline:            0x00021006,
  get_available_runspaces:    0x00021007,
  user_event:                 0x00021008,
  application_private_data:   0x00021009,
  get_command_metadata:       0x0002100a,
  runspacepool_host_call:     0x00021100,
  runspacepool_host_response: 0x00021101,
  pipeline_input:             0x00041002,
  end_of_pipeline_input:      0x00041003,
  pipeline_output:            0x00041004,
  error_record:               0x00041005,
  pipeline_state:             0x00041006,
  debug_record:               0x00041007,
  verbose_record:             0x00041008,
  warning_record:             0x00041009,
  progress_record:            0x00041010,
  information_record:         0x00041011,
  pipeline_host_call:         0x00041100,
  pipeline_host_response:     0x00041101
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UUID

#uuid_to_windows_guid_bytes

Constructor Details

#initialize(runspace_pool_id, type, data, pipeline_id = nil, destination = SERVER_DESTINATION) ⇒ Message

Creates a new PSRP message instance specified in hex, e.g. 0x00010002.

Parameters:

  • runspace_pool_id (String)

    The UUID of the remote shell/runspace pool.

  • pipeline_id (String) (defaults to: nil)

    The UUID to correlate the command/pipeline response

  • type (Integer)

    The PSRP MessageType. This is most commonly

  • data (String)

    The PSRP payload as serialized XML

  • destination (Integer) (defaults to: SERVER_DESTINATION)

    The destination for this message - client or server



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/winrm/psrp/message.rb', line 77

def initialize(
  runspace_pool_id,
  type,
  data,
  pipeline_id = nil,
  destination = SERVER_DESTINATION
)
  raise 'invalid message type' unless MESSAGE_TYPES.values.include?(type)

  @data = data
  @destination = destination
  @type = type
  @pipeline_id = pipeline_id
  @runspace_pool_id = runspace_pool_id
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



93
94
95
# File 'lib/winrm/psrp/message.rb', line 93

def data
  @data
end

#destinationObject (readonly)

Returns the value of attribute destination.



93
94
95
# File 'lib/winrm/psrp/message.rb', line 93

def destination
  @destination
end

#pipeline_idObject (readonly)

Returns the value of attribute pipeline_id.



93
94
95
# File 'lib/winrm/psrp/message.rb', line 93

def pipeline_id
  @pipeline_id
end

#runspace_pool_idObject (readonly)

Returns the value of attribute runspace_pool_id.



93
94
95
# File 'lib/winrm/psrp/message.rb', line 93

def runspace_pool_id
  @runspace_pool_id
end

#typeObject (readonly)

Returns the value of attribute type.



93
94
95
# File 'lib/winrm/psrp/message.rb', line 93

def type
  @type
end

Instance Method Details

#bytesArray<Byte>

Returns the raw PSRP message bytes ready for transfer to Windows inside a WinRM message.

Returns:

  • (Array<Byte>)

    Unencoded raw byte array of the PSRP message.



98
99
100
101
102
103
104
105
106
107
# File 'lib/winrm/psrp/message.rb', line 98

def bytes
  [
    int16le(destination),
    int16le(type),
    uuid_to_windows_guid_bytes(runspace_pool_id),
    uuid_to_windows_guid_bytes(pipeline_id),
    byte_order_mark,
    data_bytes
  ].flatten
end

#parsed_dataMessageData::Base

Parses the raw data to a MessageData class

Returns:



111
112
113
# File 'lib/winrm/psrp/message.rb', line 111

def parsed_data
  @parsed_data ||= MessageData.parse(self)
end