winrm 1.8.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -11
- data/.rubocop.yml +26 -22
- data/.travis.yml +11 -12
- data/Gemfile +3 -9
- data/LICENSE +202 -202
- data/README.md +232 -215
- data/Rakefile +34 -36
- data/Vagrantfile +6 -9
- data/WinrmAppveyor.psm1 +31 -31
- data/appveyor.yml +51 -51
- data/bin/rwinrm +97 -97
- data/changelog.md +86 -86
- data/lib/winrm.rb +39 -42
- data/lib/winrm/connection.rb +82 -0
- data/lib/winrm/connection_opts.rb +87 -0
- data/lib/winrm/{exceptions/exceptions.rb → exceptions.rb} +76 -57
- data/lib/winrm/http/response_handler.rb +96 -82
- data/lib/winrm/http/transport.rb +424 -435
- data/lib/winrm/http/transport_factory.rb +68 -0
- data/lib/winrm/output.rb +59 -43
- data/lib/winrm/psrp/create_pipeline.xml.erb +167 -0
- data/lib/winrm/psrp/fragment.rb +70 -0
- data/lib/winrm/psrp/init_runspace_pool.xml.erb +224 -0
- data/lib/winrm/psrp/message.rb +130 -0
- data/lib/winrm/psrp/message_data.rb +41 -0
- data/lib/winrm/psrp/message_data/base.rb +49 -0
- data/lib/winrm/psrp/message_data/error_record.rb +68 -0
- data/lib/winrm/psrp/message_data/pipeline_host_call.rb +32 -0
- data/lib/winrm/psrp/message_data/pipeline_output.rb +49 -0
- data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +32 -0
- data/lib/winrm/psrp/message_data/runspacepool_state.rb +39 -0
- data/lib/winrm/psrp/message_data/session_capability.rb +36 -0
- data/lib/winrm/psrp/message_defragmenter.rb +62 -0
- data/lib/winrm/psrp/message_factory.rb +75 -0
- data/lib/winrm/psrp/message_fragmenter.rb +60 -0
- data/lib/winrm/psrp/powershell_output_decoder.rb +120 -0
- data/lib/winrm/psrp/receive_response_reader.rb +93 -0
- data/lib/winrm/psrp/session_capability.xml.erb +7 -0
- data/lib/winrm/psrp/uuid.rb +40 -0
- data/lib/winrm/shells/base.rb +175 -0
- data/lib/winrm/shells/cmd.rb +65 -0
- data/lib/winrm/shells/power_shell.rb +201 -0
- data/lib/winrm/shells/retryable.rb +45 -0
- data/lib/winrm/shells/shell_factory.rb +50 -0
- data/lib/winrm/version.rb +7 -7
- data/lib/winrm/wsmv/base.rb +59 -0
- data/lib/winrm/wsmv/cleanup_command.rb +61 -0
- data/lib/winrm/wsmv/close_shell.rb +50 -0
- data/lib/winrm/wsmv/command.rb +101 -0
- data/lib/winrm/wsmv/command_output.rb +76 -0
- data/lib/winrm/wsmv/command_output_decoder.rb +55 -0
- data/lib/winrm/wsmv/configuration.rb +46 -0
- data/lib/winrm/wsmv/create_pipeline.rb +66 -0
- data/lib/winrm/wsmv/create_shell.rb +119 -0
- data/lib/winrm/wsmv/header.rb +203 -0
- data/lib/winrm/wsmv/init_runspace_pool.rb +95 -0
- data/lib/winrm/wsmv/iso8601_duration.rb +60 -0
- data/lib/winrm/wsmv/keep_alive.rb +68 -0
- data/lib/winrm/wsmv/receive_response_reader.rb +128 -0
- data/lib/winrm/wsmv/send_data.rb +68 -0
- data/lib/winrm/wsmv/soap.rb +51 -0
- data/lib/winrm/wsmv/wql_query.rb +79 -0
- data/lib/winrm/wsmv/write_stdin.rb +88 -0
- data/preamble +17 -17
- data/{spec → tests/integration}/auth_timeout_spec.rb +18 -16
- data/{spec → tests/integration}/cmd_spec.rb +104 -102
- data/{spec → tests/integration}/config-example.yml +16 -19
- data/{spec → tests/integration}/issue_59_spec.rb +26 -23
- data/tests/integration/powershell_spec.rb +154 -0
- data/{spec → tests/integration}/spec_helper.rb +65 -73
- data/{spec → tests/integration}/transport_spec.rb +99 -139
- data/{spec → tests/integration}/wql_spec.rb +16 -14
- data/{spec → tests}/matchers.rb +60 -74
- data/tests/spec/configuration_spec.rb +93 -0
- data/tests/spec/connection_spec.rb +39 -0
- data/{spec → tests/spec}/exception_spec.rb +50 -50
- data/tests/spec/http/transport_factory_spec.rb +68 -0
- data/tests/spec/http/transport_spec.rb +44 -0
- data/{spec → tests/spec}/output_spec.rb +127 -110
- data/tests/spec/psrp/fragment_spec.rb +62 -0
- data/tests/spec/psrp/message_data/base_spec.rb +13 -0
- data/tests/spec/psrp/message_data/error_record_spec.rb +41 -0
- data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +25 -0
- data/tests/spec/psrp/message_data/pipeline_output_spec.rb +32 -0
- data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +25 -0
- data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +16 -0
- data/tests/spec/psrp/message_data/session_capability_spec.rb +30 -0
- data/tests/spec/psrp/message_data_spec.rb +35 -0
- data/tests/spec/psrp/message_defragmenter_spec.rb +47 -0
- data/tests/spec/psrp/message_fragmenter_spec.rb +105 -0
- data/tests/spec/psrp/powershell_output_decoder_spec.rb +84 -0
- data/tests/spec/psrp/psrp_message_spec.rb +70 -0
- data/tests/spec/psrp/recieve_response_reader_spec.rb +154 -0
- data/tests/spec/psrp/uuid_spec.rb +28 -0
- data/{spec → tests/spec}/response_handler_spec.rb +61 -61
- data/tests/spec/shells/base_spec.rb +202 -0
- data/tests/spec/shells/cmd_spec.rb +75 -0
- data/tests/spec/shells/powershell_spec.rb +175 -0
- data/tests/spec/spec_helper.rb +47 -0
- data/tests/spec/stubs/clixml/error_record.xml.erb +84 -0
- data/{spec → tests/spec}/stubs/responses/get_command_output_response.xml.erb +13 -13
- data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +10 -0
- data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +10 -0
- data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +12 -0
- data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +9 -0
- data/{spec → tests/spec}/stubs/responses/open_shell_v1.xml +19 -19
- data/{spec → tests/spec}/stubs/responses/open_shell_v2.xml +20 -20
- data/{spec → tests/spec}/stubs/responses/soap_fault_v1.xml +36 -36
- data/{spec → tests/spec}/stubs/responses/soap_fault_v2.xml +42 -42
- data/{spec → tests/spec}/stubs/responses/wmi_error_v2.xml +41 -41
- data/tests/spec/wsmv/cleanup_command_spec.rb +22 -0
- data/tests/spec/wsmv/close_shell_spec.rb +17 -0
- data/{spec → tests/spec/wsmv}/command_output_decoder_spec.rb +37 -37
- data/tests/spec/wsmv/command_output_spec.rb +45 -0
- data/tests/spec/wsmv/command_spec.rb +19 -0
- data/tests/spec/wsmv/configuration_spec.rb +17 -0
- data/tests/spec/wsmv/create_pipeline_spec.rb +31 -0
- data/tests/spec/wsmv/create_shell_spec.rb +38 -0
- data/tests/spec/wsmv/init_runspace_pool_spec.rb +36 -0
- data/tests/spec/wsmv/keep_alive_spec.rb +21 -0
- data/tests/spec/wsmv/receive_response_reader_spec.rb +123 -0
- data/tests/spec/wsmv/send_data_spec.rb +30 -0
- data/tests/spec/wsmv/wql_query_spec.rb +13 -0
- data/tests/spec/wsmv/write_stdin_spec.rb +22 -0
- data/winrm.gemspec +42 -40
- metadata +140 -38
- data/.rspec +0 -3
- data/lib/winrm/command_executor.rb +0 -243
- data/lib/winrm/command_output_decoder.rb +0 -53
- data/lib/winrm/helpers/iso8601_duration.rb +0 -58
- data/lib/winrm/helpers/powershell_script.rb +0 -42
- data/lib/winrm/soap_provider.rb +0 -39
- data/lib/winrm/winrm_service.rb +0 -550
- data/spec/command_executor_spec.rb +0 -475
- data/spec/issue_184_spec.rb +0 -67
- data/spec/powershell_spec.rb +0 -97
- data/spec/winrm_options_spec.rb +0 -76
- data/spec/winrm_primitives_spec.rb +0 -51
@@ -0,0 +1,130 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright 2015 Matt Wrock <matt@mattwrock.com>
|
4
|
+
# Copyright 2016 Shawn Neal <sneal@sneal.net>
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the 'License');
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an 'AS IS' BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
require_relative 'uuid'
|
19
|
+
require_relative 'message_data'
|
20
|
+
|
21
|
+
module WinRM
|
22
|
+
# PowerShell Remoting Protcol module
|
23
|
+
module PSRP
|
24
|
+
# PowerShell Remoting Protocol base message.
|
25
|
+
# http://download.microsoft.com/download/9/5/E/95EF66AF-9026-4BB0-A41D-A4F81802D92C/%5BMS-PSRP%5D.pdf
|
26
|
+
class Message
|
27
|
+
include UUID
|
28
|
+
|
29
|
+
# Value of message destination when sent to a client
|
30
|
+
CLIENT_DESTINATION = 1
|
31
|
+
|
32
|
+
# Value of message destination when sent to a server
|
33
|
+
SERVER_DESTINATION = 2
|
34
|
+
|
35
|
+
# All known PSRP message types
|
36
|
+
MESSAGE_TYPES = {
|
37
|
+
session_capability: 0x00010002,
|
38
|
+
init_runspacepool: 0x00010004,
|
39
|
+
public_key: 0x00010005,
|
40
|
+
encrypted_session_key: 0x00010006,
|
41
|
+
public_key_request: 0x00010007,
|
42
|
+
connect_runspacepool: 0x00010008,
|
43
|
+
runspace_init_data: 0x0002100b,
|
44
|
+
reset_runspace_state: 0x0002100c,
|
45
|
+
set_max_runspaces: 0x00021002,
|
46
|
+
set_min_runspaces: 0x00021003,
|
47
|
+
runspace_availability: 0x00021004,
|
48
|
+
runspacepool_state: 0x00021005,
|
49
|
+
create_pipeline: 0x00021006,
|
50
|
+
get_available_runspaces: 0x00021007,
|
51
|
+
user_event: 0x00021008,
|
52
|
+
application_private_data: 0x00021009,
|
53
|
+
get_command_metadata: 0x0002100a,
|
54
|
+
runspacepool_host_call: 0x00021100,
|
55
|
+
runspacepool_host_response: 0x00021101,
|
56
|
+
pipeline_input: 0x00041002,
|
57
|
+
end_of_pipeline_input: 0x00041003,
|
58
|
+
pipeline_output: 0x00041004,
|
59
|
+
error_record: 0x00041005,
|
60
|
+
pipeline_state: 0x00041006,
|
61
|
+
debug_record: 0x00041007,
|
62
|
+
verbose_record: 0x00041008,
|
63
|
+
warning_record: 0x00041009,
|
64
|
+
progress_record: 0x00041010,
|
65
|
+
information_record: 0x00041011,
|
66
|
+
pipeline_host_call: 0x00041100,
|
67
|
+
pipeline_host_response: 0x00041101
|
68
|
+
}.freeze
|
69
|
+
|
70
|
+
# Creates a new PSRP message instance
|
71
|
+
# @param runspace_pool_id [String] The UUID of the remote shell/runspace pool.
|
72
|
+
# @param pipeline_id [String] The UUID to correlate the command/pipeline response
|
73
|
+
# @param type [Fixnum] The PSRP MessageType. This is most commonly
|
74
|
+
# specified in hex, e.g. 0x00010002.
|
75
|
+
# @param data [String] The PSRP payload as serialized XML
|
76
|
+
# @param destination [Fixnum] The destination for this message - client or server
|
77
|
+
def initialize(
|
78
|
+
runspace_pool_id,
|
79
|
+
type,
|
80
|
+
data,
|
81
|
+
pipeline_id = nil,
|
82
|
+
destination = SERVER_DESTINATION
|
83
|
+
)
|
84
|
+
raise 'invalid message type' unless MESSAGE_TYPES.values.include?(type)
|
85
|
+
|
86
|
+
@data = data
|
87
|
+
@destination = destination
|
88
|
+
@type = type
|
89
|
+
@pipeline_id = pipeline_id
|
90
|
+
@runspace_pool_id = runspace_pool_id
|
91
|
+
end
|
92
|
+
|
93
|
+
attr_reader :destination, :type, :runspace_pool_id, :pipeline_id, :data
|
94
|
+
|
95
|
+
# Returns the raw PSRP message bytes ready for transfer to Windows inside a
|
96
|
+
# WinRM message.
|
97
|
+
# @return [Array<Byte>] Unencoded raw byte array of the PSRP message.
|
98
|
+
def bytes
|
99
|
+
[
|
100
|
+
int16le(destination),
|
101
|
+
int16le(type),
|
102
|
+
uuid_to_windows_guid_bytes(runspace_pool_id),
|
103
|
+
uuid_to_windows_guid_bytes(pipeline_id),
|
104
|
+
byte_order_mark,
|
105
|
+
data_bytes
|
106
|
+
].flatten
|
107
|
+
end
|
108
|
+
|
109
|
+
# Parses the raw data to a MessageData class
|
110
|
+
# @return [MessageData::Base] MessageData corresponding to this message type
|
111
|
+
def parsed_data
|
112
|
+
@parsed_data ||= MessageData.parse(self)
|
113
|
+
end
|
114
|
+
|
115
|
+
private
|
116
|
+
|
117
|
+
def byte_order_mark
|
118
|
+
[239, 187, 191]
|
119
|
+
end
|
120
|
+
|
121
|
+
def data_bytes
|
122
|
+
@data_bytes ||= data.force_encoding('utf-8').bytes
|
123
|
+
end
|
124
|
+
|
125
|
+
def int16le(int16)
|
126
|
+
[int16].pack('N').unpack('C4').reverse
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright 2016 Matt Wrock <matt@mattwrock.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the 'License');
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an 'AS IS' BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require_relative 'message_data/base'
|
18
|
+
require_relative 'message_data/error_record'
|
19
|
+
require_relative 'message_data/pipeline_output'
|
20
|
+
require_relative 'message_data/pipeline_host_call'
|
21
|
+
require_relative 'message_data/runspacepool_host_call'
|
22
|
+
require_relative 'message_data/runspacepool_state'
|
23
|
+
require_relative 'message_data/session_capability'
|
24
|
+
|
25
|
+
module WinRM
|
26
|
+
# PowerShell Remoting Protcol module
|
27
|
+
module PSRP
|
28
|
+
# PowerShell Remoting Protocol message data.
|
29
|
+
module MessageData
|
30
|
+
def self.parse(message)
|
31
|
+
type_key = WinRM::PSRP::Message::MESSAGE_TYPES.key(message.type)
|
32
|
+
type = camelize(type_key.to_s).to_sym
|
33
|
+
const_get(type).new(message.data) if MessageData.constants.include?(type)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.camelize(underscore)
|
37
|
+
underscore.split('_').collect(&:capitalize).join
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright 2016 Matt Wrock <matt@mattwrock.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the 'License');
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an 'AS IS' BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'nori'
|
18
|
+
|
19
|
+
module WinRM
|
20
|
+
# PowerShell Remoting Protcol module
|
21
|
+
module PSRP
|
22
|
+
# PowerShell Remoting Protocol message data.
|
23
|
+
module MessageData
|
24
|
+
# base class for message data
|
25
|
+
class Base
|
26
|
+
def initialize(data)
|
27
|
+
@raw = data
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String] raw message data
|
31
|
+
attr_reader :raw
|
32
|
+
|
33
|
+
protected
|
34
|
+
|
35
|
+
def clixml
|
36
|
+
@clixml ||= begin
|
37
|
+
parser = Nori.new(
|
38
|
+
parser: :rexml,
|
39
|
+
advanced_typecasting: false,
|
40
|
+
convert_tags_to: ->(tag) { tag.snakecase.to_sym },
|
41
|
+
strip_namespaces: true
|
42
|
+
)
|
43
|
+
parser.parse(raw)[:obj][:ms]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright 2016 Matt Wrock <matt@mattwrock.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module WinRM
|
18
|
+
module PSRP
|
19
|
+
module MessageData
|
20
|
+
# pipeline host call message type
|
21
|
+
class ErrorRecord < Base
|
22
|
+
def exception
|
23
|
+
@exception ||= property_hash('Exception')
|
24
|
+
end
|
25
|
+
|
26
|
+
def fully_qualified_error_id
|
27
|
+
@fully_qualified_error_id ||= string_prop('FullyQualifiedErrorId')
|
28
|
+
end
|
29
|
+
|
30
|
+
def invocation_info
|
31
|
+
@invocation_info ||= property_hash('InvocationInfo')
|
32
|
+
end
|
33
|
+
|
34
|
+
def error_category_message
|
35
|
+
@error_category_message ||= string_prop('ErrorCategory_Message')
|
36
|
+
end
|
37
|
+
|
38
|
+
def error_details_script_stack_trace
|
39
|
+
@error_details_script_stack_trace ||= string_prop('ErrorDetails_ScriptStackTrace')
|
40
|
+
end
|
41
|
+
|
42
|
+
def doc
|
43
|
+
@doc ||= REXML::Document.new(raw)
|
44
|
+
end
|
45
|
+
|
46
|
+
def string_prop(prop_name)
|
47
|
+
prop = REXML::XPath.first(doc, "//*[@N='#{prop_name}']")
|
48
|
+
prop.text if prop
|
49
|
+
end
|
50
|
+
|
51
|
+
def property_hash(prop_name)
|
52
|
+
prop_nodes = REXML::XPath.first(doc, "//*[@N='#{prop_name}']/Props")
|
53
|
+
prop_nodes.elements.each_with_object({}) do |node, props|
|
54
|
+
name = node.attributes['N']
|
55
|
+
props[underscore(name).to_sym] = node.text if node.text
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def underscore(camel)
|
60
|
+
camel.gsub(/::/, '/')
|
61
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
62
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
63
|
+
.tr('-', '_').downcase
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright 2016 Matt Wrock <matt@mattwrock.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module WinRM
|
18
|
+
module PSRP
|
19
|
+
module MessageData
|
20
|
+
# pipeline host call message type
|
21
|
+
class PipelineHostCall < Base
|
22
|
+
def method_identifier
|
23
|
+
clixml[:obj][0][:to_string]
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_parameters
|
27
|
+
clixml[:obj][1][:lst]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright 2016 Matt Wrock <matt@mattwrock.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'rexml/document'
|
18
|
+
|
19
|
+
module WinRM
|
20
|
+
module PSRP
|
21
|
+
module MessageData
|
22
|
+
# Handles decoding a raw powershell output response
|
23
|
+
class PipelineOutput < Base
|
24
|
+
def output
|
25
|
+
extract_out_string(remove_bom(raw.force_encoding('utf-8')))
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def extract_out_string(text)
|
31
|
+
doc = REXML::Document.new(text)
|
32
|
+
doc.root.get_elements('//S').map do |node|
|
33
|
+
text = ''
|
34
|
+
if node.text
|
35
|
+
text << node.text.gsub(/_x(\h\h\h\h)_/) do
|
36
|
+
Regexp.last_match[1].hex.chr
|
37
|
+
end.chomp
|
38
|
+
end
|
39
|
+
text << "\r\n"
|
40
|
+
end.join
|
41
|
+
end
|
42
|
+
|
43
|
+
def remove_bom(text)
|
44
|
+
text.sub("\xEF\xBB\xBF", '')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright 2016 Matt Wrock <matt@mattwrock.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module WinRM
|
18
|
+
module PSRP
|
19
|
+
module MessageData
|
20
|
+
# runspace pool host call message type
|
21
|
+
class RunspacepoolHostCall < Base
|
22
|
+
def method_identifier
|
23
|
+
clixml[:obj][0][:to_string]
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_parameters
|
27
|
+
clixml[:obj][1][:lst]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright 2016 Matt Wrock <matt@mattwrock.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module WinRM
|
18
|
+
module PSRP
|
19
|
+
module MessageData
|
20
|
+
# runspace pool state message type
|
21
|
+
class RunspacepoolState < Base
|
22
|
+
BEFORE_OPEN = 0
|
23
|
+
OPENING = 1
|
24
|
+
OPENED = 2
|
25
|
+
CLOSED = 3
|
26
|
+
CLOSING = 4
|
27
|
+
BROKEN = 5
|
28
|
+
NEGOTIATION_SENT = 6
|
29
|
+
NEGOTIATION_SUCCEEDED = 7
|
30
|
+
CONNECTING = 8
|
31
|
+
DISCONNECTED = 9
|
32
|
+
|
33
|
+
def runspace_state
|
34
|
+
clixml[:i32].to_i
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|