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
data/Vagrantfile
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
8
|
-
config.vm.box = 'mwrock/Windows2012R2'
|
9
|
-
end
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
Vagrant.configure("2") do |config|
|
5
|
+
config.vm.box = "mwrock/WindowsNano"
|
6
|
+
end
|
data/WinrmAppveyor.psm1
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
function New-ClientCertificate {
|
2
|
-
param([String]$username, [String]$basePath = ((Resolve-
|
3
|
-
|
4
|
-
$env:OPENSSL_CONF=[System.IO.Path]::GetTempFileName()
|
5
|
-
|
6
|
-
Set-Content -Path $env:OPENSSL_CONF -Value @"
|
7
|
-
distinguished_name = req_distinguished_name
|
8
|
-
[req_distinguished_name]
|
9
|
-
[v3_req_client]
|
10
|
-
extendedKeyUsage = clientAuth
|
11
|
-
subjectAltName = otherName:1.3.6.1.4.1.311.20.2.3;UTF8:$username@localhost
|
12
|
-
"@
|
13
|
-
|
14
|
-
$user_path = Join-Path $basePath user.pem
|
15
|
-
$key_path = Join-Path $basePath key.pem
|
16
|
-
$pfx_path = Join-Path $basePath user.pfx
|
17
|
-
|
18
|
-
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -out $user_path -outform PEM -keyout $key_path -subj "/CN=$username" -extensions v3_req_client 2>&1
|
19
|
-
|
20
|
-
openssl pkcs12 -export -in $user_path -inkey $key_path -out $pfx_path -passout pass: 2>&1
|
21
|
-
|
22
|
-
del $env:OPENSSL_CONF
|
23
|
-
}
|
24
|
-
|
25
|
-
function New-WinrmUserCertificateMapping {
|
26
|
-
param([String]$issuer)
|
27
|
-
$secure_pass = ConvertTo-SecureString $env:
|
28
|
-
$cred = New-Object System.Management.Automation.PSCredential ($env:winrm_user, $secure_pass)
|
29
|
-
New-Item -Path WSMan:\localhost\ClientCertificate -Subject "$env:winrm_user@localhost" -URI * -Issuer $issuer -Credential $cred -Force
|
30
|
-
}
|
31
|
-
|
1
|
+
function New-ClientCertificate {
|
2
|
+
param([String]$username, [String]$basePath = ((Resolve-Path .).Path))
|
3
|
+
|
4
|
+
$env:OPENSSL_CONF=[System.IO.Path]::GetTempFileName()
|
5
|
+
|
6
|
+
Set-Content -Path $env:OPENSSL_CONF -Value @"
|
7
|
+
distinguished_name = req_distinguished_name
|
8
|
+
[req_distinguished_name]
|
9
|
+
[v3_req_client]
|
10
|
+
extendedKeyUsage = clientAuth
|
11
|
+
subjectAltName = otherName:1.3.6.1.4.1.311.20.2.3;UTF8:$username@localhost
|
12
|
+
"@
|
13
|
+
|
14
|
+
$user_path = Join-Path $basePath user.pem
|
15
|
+
$key_path = Join-Path $basePath key.pem
|
16
|
+
$pfx_path = Join-Path $basePath user.pfx
|
17
|
+
|
18
|
+
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -out $user_path -outform PEM -keyout $key_path -subj "/CN=$username" -extensions v3_req_client 2>&1
|
19
|
+
|
20
|
+
openssl pkcs12 -export -in $user_path -inkey $key_path -out $pfx_path -passout pass: 2>&1
|
21
|
+
|
22
|
+
del $env:OPENSSL_CONF
|
23
|
+
}
|
24
|
+
|
25
|
+
function New-WinrmUserCertificateMapping {
|
26
|
+
param([String]$issuer)
|
27
|
+
$secure_pass = ConvertTo-SecureString $env:winrm_password -AsPlainText -Force
|
28
|
+
$cred = New-Object System.Management.Automation.PSCredential ($env:winrm_user, $secure_pass)
|
29
|
+
New-Item -Path WSMan:\localhost\ClientCertificate -Subject "$env:winrm_user@localhost" -URI * -Issuer $issuer -Credential $cred -Force
|
30
|
+
}
|
31
|
+
|
32
32
|
Export-ModuleMember New-ClientCertificate, New-WinrmUserCertificateMapping
|
data/appveyor.yml
CHANGED
@@ -1,51 +1,51 @@
|
|
1
|
-
version: "master-{build}"
|
2
|
-
|
3
|
-
os: Windows Server 2012 R2
|
4
|
-
platform:
|
5
|
-
- x64
|
6
|
-
|
7
|
-
environment:
|
8
|
-
winrm_user: test_user
|
9
|
-
|
10
|
-
user_cert: c:\projects\winrm\user.pem
|
11
|
-
user_key: c:\projects\winrm\key.pem
|
12
|
-
|
13
|
-
matrix:
|
14
|
-
- ruby_version: "21"
|
15
|
-
winrm_endpoint: http://localhost:5985/wsman
|
16
|
-
|
17
|
-
clone_folder: c:\projects\winrm
|
18
|
-
clone_depth: 1
|
19
|
-
branches:
|
20
|
-
only:
|
21
|
-
- master
|
22
|
-
|
23
|
-
install:
|
24
|
-
- ps: net user /add $env:winrm_user $env:
|
25
|
-
- ps: net localgroup administrators $env:winrm_user /add
|
26
|
-
- ps: $env:PATH="C:\OpenSSL-Win64\bin;$env:PATH"
|
27
|
-
- ps: Import-Module c:\projects\winrm\WinrmAppveyor.psm1
|
28
|
-
- ps: New-ClientCertificate $env:winrm_user c:\projects\winrm
|
29
|
-
- ps: $env:user_cert_thumb = (Import-pfxCertificate -FilePath c:\projects\winrm\user.pfx -CertStoreLocation Cert:\LocalMachine\root).Thumbprint
|
30
|
-
- ps: Import-pfxCertificate -FilePath c:\projects\winrm\user.pfx -CertStoreLocation Cert:\LocalMachine\TrustedPeople
|
31
|
-
- ps: $env:winrm_cert = (New-SelfSignedCertificate -DnsName localhost -CertStoreLocation cert:\localmachine\my).Thumbprint
|
32
|
-
- ps: winrm create winrm/config/Listener?Address=*+Transport=HTTPS "@{Hostname=`"localhost`";CertificateThumbprint=`"$($env:winrm_cert)`"}"
|
33
|
-
- ps: winrm set winrm/config/client/auth '@{Basic="true"}'
|
34
|
-
- ps: winrm set winrm/config/service/auth '@{Basic="true"}'
|
35
|
-
- ps: winrm set winrm/config/service/auth '@{Certificate="true"}'
|
36
|
-
- ps: winrm set winrm/config/service/auth '@{CbtHardeningLevel="Strict"}'
|
37
|
-
- ps: winrm set winrm/config/service '@{AllowUnencrypted="true"}'
|
38
|
-
- ps: New-WinrmUserCertificateMapping $env:user_cert_thumb
|
39
|
-
- ps: $env:PATH="C:\Ruby$env:ruby_version\bin;$env:PATH"
|
40
|
-
- ps: Write-Host $env:PATH
|
41
|
-
- ps: ruby --version
|
42
|
-
- ps: gem --version
|
43
|
-
- ps: gem install bundler --quiet --no-ri --no-rdoc
|
44
|
-
- ps: bundler --version
|
45
|
-
|
46
|
-
build_script:
|
47
|
-
- bundle install || bundle install || bundle install
|
48
|
-
|
49
|
-
test_script:
|
50
|
-
- SET SPEC_OPTS=--format progress
|
51
|
-
- bundle exec rake integration
|
1
|
+
version: "master-{build}"
|
2
|
+
|
3
|
+
os: Windows Server 2012 R2
|
4
|
+
platform:
|
5
|
+
- x64
|
6
|
+
|
7
|
+
environment:
|
8
|
+
winrm_user: test_user
|
9
|
+
winrm_password: Pass@word1
|
10
|
+
user_cert: c:\projects\winrm\user.pem
|
11
|
+
user_key: c:\projects\winrm\key.pem
|
12
|
+
|
13
|
+
matrix:
|
14
|
+
- ruby_version: "21"
|
15
|
+
winrm_endpoint: http://localhost:5985/wsman
|
16
|
+
|
17
|
+
clone_folder: c:\projects\winrm
|
18
|
+
clone_depth: 1
|
19
|
+
branches:
|
20
|
+
only:
|
21
|
+
- master
|
22
|
+
|
23
|
+
install:
|
24
|
+
- ps: net user /add $env:winrm_user $env:winrm_password
|
25
|
+
- ps: net localgroup administrators $env:winrm_user /add
|
26
|
+
- ps: $env:PATH="C:\OpenSSL-Win64\bin;$env:PATH"
|
27
|
+
- ps: Import-Module c:\projects\winrm\WinrmAppveyor.psm1
|
28
|
+
- ps: New-ClientCertificate $env:winrm_user c:\projects\winrm
|
29
|
+
- ps: $env:user_cert_thumb = (Import-pfxCertificate -FilePath c:\projects\winrm\user.pfx -CertStoreLocation Cert:\LocalMachine\root).Thumbprint
|
30
|
+
- ps: Import-pfxCertificate -FilePath c:\projects\winrm\user.pfx -CertStoreLocation Cert:\LocalMachine\TrustedPeople
|
31
|
+
- ps: $env:winrm_cert = (New-SelfSignedCertificate -DnsName localhost -CertStoreLocation cert:\localmachine\my).Thumbprint
|
32
|
+
- ps: winrm create winrm/config/Listener?Address=*+Transport=HTTPS "@{Hostname=`"localhost`";CertificateThumbprint=`"$($env:winrm_cert)`"}"
|
33
|
+
- ps: winrm set winrm/config/client/auth '@{Basic="true"}'
|
34
|
+
- ps: winrm set winrm/config/service/auth '@{Basic="true"}'
|
35
|
+
- ps: winrm set winrm/config/service/auth '@{Certificate="true"}'
|
36
|
+
- ps: winrm set winrm/config/service/auth '@{CbtHardeningLevel="Strict"}'
|
37
|
+
- ps: winrm set winrm/config/service '@{AllowUnencrypted="true"}'
|
38
|
+
- ps: New-WinrmUserCertificateMapping $env:user_cert_thumb
|
39
|
+
- ps: $env:PATH="C:\Ruby$env:ruby_version\bin;$env:PATH"
|
40
|
+
- ps: Write-Host $env:PATH
|
41
|
+
- ps: ruby --version
|
42
|
+
- ps: gem --version
|
43
|
+
- ps: gem install bundler --quiet --no-ri --no-rdoc
|
44
|
+
- ps: bundler --version
|
45
|
+
|
46
|
+
build_script:
|
47
|
+
- bundle install || bundle install || bundle install
|
48
|
+
|
49
|
+
test_script:
|
50
|
+
- SET SPEC_OPTS=--format progress
|
51
|
+
- bundle exec rake integration
|
data/bin/rwinrm
CHANGED
@@ -1,97 +1,97 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
# Copyright 2014 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
|
-
# rubocop:disable all
|
19
|
-
|
20
|
-
$LOAD_PATH.push File.expand_path('../../lib', __FILE__)
|
21
|
-
|
22
|
-
require 'readline'
|
23
|
-
require 'io/console'
|
24
|
-
require 'winrm'
|
25
|
-
|
26
|
-
def help_msg
|
27
|
-
puts 'Usage: rwinrm user@host'
|
28
|
-
puts ''
|
29
|
-
end
|
30
|
-
|
31
|
-
def parse_options
|
32
|
-
options = {}
|
33
|
-
fail 'Missing required options' unless ARGV.length == 1
|
34
|
-
|
35
|
-
m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?/i.match(ARGV[0])
|
36
|
-
fail "#{ARGV[0]} is an invalid host" unless m
|
37
|
-
options[:user] = m[:user]
|
38
|
-
options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"
|
39
|
-
|
40
|
-
# Get the password
|
41
|
-
print 'Password: '
|
42
|
-
options[:pass] = STDIN.noecho(&:gets).chomp
|
43
|
-
puts
|
44
|
-
|
45
|
-
# Set some defaults required by WinRM WS
|
46
|
-
options[:auth_type] = :plaintext
|
47
|
-
options[:basic_auth_only] = true
|
48
|
-
|
49
|
-
options
|
50
|
-
rescue StandardError => e
|
51
|
-
puts e.message
|
52
|
-
help_msg
|
53
|
-
exit 1
|
54
|
-
end
|
55
|
-
|
56
|
-
def repl(options)
|
57
|
-
client = WinRM::WinRMWebService.new(
|
58
|
-
options[:endpoint],
|
59
|
-
options[:auth_type].to_sym,
|
60
|
-
options)
|
61
|
-
|
62
|
-
client.set_timeout(3600)
|
63
|
-
shell_id = client.open_shell
|
64
|
-
command_id = client.run_command(shell_id, 'cmd', "/K prompt [#{ARGV[0]}]$P$G")
|
65
|
-
|
66
|
-
read_thread = Thread.new do
|
67
|
-
client.get_command_output(shell_id, command_id) do |stdout, stderr|
|
68
|
-
STDOUT.write stdout
|
69
|
-
STDERR.write stderr
|
70
|
-
end
|
71
|
-
end
|
72
|
-
read_thread.abort_on_exception = true
|
73
|
-
|
74
|
-
while (buf = Readline.readline('', true))
|
75
|
-
if buf =~ /^exit/
|
76
|
-
read_thread.exit
|
77
|
-
client.cleanup_command(shell_id, command_id)
|
78
|
-
client.close_shell(shell_id)
|
79
|
-
exit 0
|
80
|
-
else
|
81
|
-
client.write_stdin(shell_id, command_id, "#{buf}\r\n")
|
82
|
-
end
|
83
|
-
end
|
84
|
-
rescue Interrupt
|
85
|
-
puts 'exiting'
|
86
|
-
# ctrl-c
|
87
|
-
rescue WinRM::WinRMAuthorizationError
|
88
|
-
puts 'Authentication failed, bad user name or password'
|
89
|
-
exit 1
|
90
|
-
rescue StandardError => e
|
91
|
-
puts e.message
|
92
|
-
exit 1
|
93
|
-
end
|
94
|
-
|
95
|
-
repl(parse_options)
|
96
|
-
|
97
|
-
# rubocop:enable all
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# Copyright 2014 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
|
+
# rubocop:disable all
|
19
|
+
|
20
|
+
$LOAD_PATH.push File.expand_path('../../lib', __FILE__)
|
21
|
+
|
22
|
+
require 'readline'
|
23
|
+
require 'io/console'
|
24
|
+
require 'winrm'
|
25
|
+
|
26
|
+
def help_msg
|
27
|
+
puts 'Usage: rwinrm user@host'
|
28
|
+
puts ''
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_options
|
32
|
+
options = {}
|
33
|
+
fail 'Missing required options' unless ARGV.length == 1
|
34
|
+
|
35
|
+
m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?/i.match(ARGV[0])
|
36
|
+
fail "#{ARGV[0]} is an invalid host" unless m
|
37
|
+
options[:user] = m[:user]
|
38
|
+
options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"
|
39
|
+
|
40
|
+
# Get the password
|
41
|
+
print 'Password: '
|
42
|
+
options[:pass] = STDIN.noecho(&:gets).chomp
|
43
|
+
puts
|
44
|
+
|
45
|
+
# Set some defaults required by WinRM WS
|
46
|
+
options[:auth_type] = :plaintext
|
47
|
+
options[:basic_auth_only] = true
|
48
|
+
|
49
|
+
options
|
50
|
+
rescue StandardError => e
|
51
|
+
puts e.message
|
52
|
+
help_msg
|
53
|
+
exit 1
|
54
|
+
end
|
55
|
+
|
56
|
+
def repl(options)
|
57
|
+
client = WinRM::WinRMWebService.new(
|
58
|
+
options[:endpoint],
|
59
|
+
options[:auth_type].to_sym,
|
60
|
+
options)
|
61
|
+
|
62
|
+
client.set_timeout(3600)
|
63
|
+
shell_id = client.open_shell
|
64
|
+
command_id = client.run_command(shell_id, 'cmd', "/K prompt [#{ARGV[0]}]$P$G")
|
65
|
+
|
66
|
+
read_thread = Thread.new do
|
67
|
+
client.get_command_output(shell_id, command_id) do |stdout, stderr|
|
68
|
+
STDOUT.write stdout
|
69
|
+
STDERR.write stderr
|
70
|
+
end
|
71
|
+
end
|
72
|
+
read_thread.abort_on_exception = true
|
73
|
+
|
74
|
+
while (buf = Readline.readline('', true))
|
75
|
+
if buf =~ /^exit/
|
76
|
+
read_thread.exit
|
77
|
+
client.cleanup_command(shell_id, command_id)
|
78
|
+
client.close_shell(shell_id)
|
79
|
+
exit 0
|
80
|
+
else
|
81
|
+
client.write_stdin(shell_id, command_id, "#{buf}\r\n")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
rescue Interrupt
|
85
|
+
puts 'exiting'
|
86
|
+
# ctrl-c
|
87
|
+
rescue WinRM::WinRMAuthorizationError
|
88
|
+
puts 'Authentication failed, bad user name or password'
|
89
|
+
exit 1
|
90
|
+
rescue StandardError => e
|
91
|
+
puts e.message
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
|
95
|
+
repl(parse_options)
|
96
|
+
|
97
|
+
# rubocop:enable all
|
data/changelog.md
CHANGED
@@ -1,86 +1,86 @@
|
|
1
|
-
# WinRM Gem Changelog
|
2
|
-
|
3
|
-
# 1.8.1
|
4
|
-
- Http receive timeout should always be equal to 10 seconds greater than the winrm operation timeout and not default to one hour
|
5
|
-
|
6
|
-
# 1.8.0
|
7
|
-
- Add certificate authentication
|
8
|
-
|
9
|
-
# 1.7.3
|
10
|
-
- Open a new shell if the current shell has been deleted
|
11
|
-
|
12
|
-
# 1.7.2
|
13
|
-
- Fix regression where BOM appears in 2008R2 output and is not stripped
|
14
|
-
|
15
|
-
# 1.7.1
|
16
|
-
- Fix OS version comparisons for Windows 10 using `Gem::Version` instead of strings
|
17
|
-
|
18
|
-
# 1.7.0
|
19
|
-
- Bump rubyntlm gem to 0.6.0 to get channel binding support for HTTPS fixing connections to endoints with `CbtHardeningLevel` set to `Strict`
|
20
|
-
- Fix for parsing binary data in command output
|
21
|
-
|
22
|
-
# 1.6.1
|
23
|
-
- Use codepage 437 by default on os versions older than Windows 7 and Windows Server 2008 R2
|
24
|
-
|
25
|
-
# 1.6.0
|
26
|
-
- Adding `:negotiate` transport providing NTLM/Negotiate encryption of WinRM requests and responses
|
27
|
-
- Removed dependency on UUIDTools gem
|
28
|
-
- Extending accepted error codes for retry behavior to include `Errno::ETIMEDOUT`
|
29
|
-
- Correct deprecation warning for WinRMWebService.run_powershell_script
|
30
|
-
|
31
|
-
# 1.5.0
|
32
|
-
- Deprecating `WinRM::WinRMWebService` methods `cmd`, `run_cmd`, `powershell`, and `run_powershell_script` in favor of the `run_cmd` and `run_powershell_script` methods of the `WinRM::CommandExecutor` class. The `CommandExecutor` allows multiple commands to be run from the same WinRM shell providing a significant performance improvement when issuing multiple calls.
|
33
|
-
- Added an `:ssl_peer_fingerprint` option to be used instead of `:no_ssl_peer_verification` and allows a specific certificate to be verified.
|
34
|
-
- Opening a winrm shell is retriable with configurable delay and retry limit.
|
35
|
-
- Logging apends to `stdout` by default and can be replaced with a logger from a consuming application.
|
36
|
-
|
37
|
-
# 1.4.0
|
38
|
-
- Added WinRM::Version so the gem version is available at runtime for consumers.
|
39
|
-
|
40
|
-
# 1.3.6
|
41
|
-
- Remove BOM from response (Issue #159) added by Windows 2008R2
|
42
|
-
|
43
|
-
# 1.3.5
|
44
|
-
- Widen logging version constraints to include 2.0
|
45
|
-
- Use codepage 65001 (UTF-8)
|
46
|
-
|
47
|
-
# 1.3.4
|
48
|
-
- Relaxed version pins on dev dependencies
|
49
|
-
|
50
|
-
# 1.3.3
|
51
|
-
- Fixed issue 133, rwinrm allow hostnames with dashes
|
52
|
-
- Use duck typing for powershell script read
|
53
|
-
|
54
|
-
# 1.3.2
|
55
|
-
- Add spec.license attribute to gemspec
|
56
|
-
- Bump RSpec dependency 3.0 to 3.2
|
57
|
-
|
58
|
-
# 1.3.1
|
59
|
-
- Fixed issue 129, long running commands could cause a stackoverflow exception
|
60
|
-
- Fixed use of sub! in run_command results in spurious capture/replacement of \& sequences
|
61
|
-
- Fixed issue 124 rwinrm won't take '.' characters in username
|
62
|
-
|
63
|
-
# 1.3.0
|
64
|
-
- Fixed multiple issues with WinRMHTTPTransportError incorrectly being raised
|
65
|
-
- Refactored and added more unit and integration tests
|
66
|
-
- Added ability to write to stdin
|
67
|
-
- Added rwinrm binary to launch remote shell
|
68
|
-
- Added WINRM_LOG env var to set log level
|
69
|
-
- Retry Kerberos auth once if 401 response is received
|
70
|
-
- Remove Savon dependency and use newer versions of underlying dependencies
|
71
|
-
- Remove Nokogiri dependency and replace with native Ruby XML
|
72
|
-
- Fixed issue 85, ensure WQL response is not nil
|
73
|
-
- All WinRM library errors inherit from base class WinRMError
|
74
|
-
- Integrations tests should now pass on Windows Server 2008+
|
75
|
-
- Bump Ruby NTLM gem version dependency
|
76
|
-
- HTTP client receive timeout is now configurable via set_timeout
|
77
|
-
- Added backwards compatible Output class to make it easier to collect output
|
78
|
-
- Bumped gssapi dependency from 1.0 to 1.2 and fixed issue 54
|
79
|
-
- Added Rubocop to build
|
80
|
-
- Fixed error when commands contain a newline character
|
81
|
-
|
82
|
-
# 1.2.0
|
83
|
-
- Allow user to disable SSL peer ceritifcate validation #44
|
84
|
-
- Allow commands with "'" chars on Ruby 2.x, fixes #69
|
85
|
-
- Fixed uninitialized constant Module::Kconv in Ruby 2.x, fixes #65
|
86
|
-
- Commands with non-ASCII chars should work, #70
|
1
|
+
# WinRM Gem Changelog
|
2
|
+
|
3
|
+
# 1.8.1
|
4
|
+
- Http receive timeout should always be equal to 10 seconds greater than the winrm operation timeout and not default to one hour
|
5
|
+
|
6
|
+
# 1.8.0
|
7
|
+
- Add certificate authentication
|
8
|
+
|
9
|
+
# 1.7.3
|
10
|
+
- Open a new shell if the current shell has been deleted
|
11
|
+
|
12
|
+
# 1.7.2
|
13
|
+
- Fix regression where BOM appears in 2008R2 output and is not stripped
|
14
|
+
|
15
|
+
# 1.7.1
|
16
|
+
- Fix OS version comparisons for Windows 10 using `Gem::Version` instead of strings
|
17
|
+
|
18
|
+
# 1.7.0
|
19
|
+
- Bump rubyntlm gem to 0.6.0 to get channel binding support for HTTPS fixing connections to endoints with `CbtHardeningLevel` set to `Strict`
|
20
|
+
- Fix for parsing binary data in command output
|
21
|
+
|
22
|
+
# 1.6.1
|
23
|
+
- Use codepage 437 by default on os versions older than Windows 7 and Windows Server 2008 R2
|
24
|
+
|
25
|
+
# 1.6.0
|
26
|
+
- Adding `:negotiate` transport providing NTLM/Negotiate encryption of WinRM requests and responses
|
27
|
+
- Removed dependency on UUIDTools gem
|
28
|
+
- Extending accepted error codes for retry behavior to include `Errno::ETIMEDOUT`
|
29
|
+
- Correct deprecation warning for WinRMWebService.run_powershell_script
|
30
|
+
|
31
|
+
# 1.5.0
|
32
|
+
- Deprecating `WinRM::WinRMWebService` methods `cmd`, `run_cmd`, `powershell`, and `run_powershell_script` in favor of the `run_cmd` and `run_powershell_script` methods of the `WinRM::CommandExecutor` class. The `CommandExecutor` allows multiple commands to be run from the same WinRM shell providing a significant performance improvement when issuing multiple calls.
|
33
|
+
- Added an `:ssl_peer_fingerprint` option to be used instead of `:no_ssl_peer_verification` and allows a specific certificate to be verified.
|
34
|
+
- Opening a winrm shell is retriable with configurable delay and retry limit.
|
35
|
+
- Logging apends to `stdout` by default and can be replaced with a logger from a consuming application.
|
36
|
+
|
37
|
+
# 1.4.0
|
38
|
+
- Added WinRM::Version so the gem version is available at runtime for consumers.
|
39
|
+
|
40
|
+
# 1.3.6
|
41
|
+
- Remove BOM from response (Issue #159) added by Windows 2008R2
|
42
|
+
|
43
|
+
# 1.3.5
|
44
|
+
- Widen logging version constraints to include 2.0
|
45
|
+
- Use codepage 65001 (UTF-8)
|
46
|
+
|
47
|
+
# 1.3.4
|
48
|
+
- Relaxed version pins on dev dependencies
|
49
|
+
|
50
|
+
# 1.3.3
|
51
|
+
- Fixed issue 133, rwinrm allow hostnames with dashes
|
52
|
+
- Use duck typing for powershell script read
|
53
|
+
|
54
|
+
# 1.3.2
|
55
|
+
- Add spec.license attribute to gemspec
|
56
|
+
- Bump RSpec dependency 3.0 to 3.2
|
57
|
+
|
58
|
+
# 1.3.1
|
59
|
+
- Fixed issue 129, long running commands could cause a stackoverflow exception
|
60
|
+
- Fixed use of sub! in run_command results in spurious capture/replacement of \& sequences
|
61
|
+
- Fixed issue 124 rwinrm won't take '.' characters in username
|
62
|
+
|
63
|
+
# 1.3.0
|
64
|
+
- Fixed multiple issues with WinRMHTTPTransportError incorrectly being raised
|
65
|
+
- Refactored and added more unit and integration tests
|
66
|
+
- Added ability to write to stdin
|
67
|
+
- Added rwinrm binary to launch remote shell
|
68
|
+
- Added WINRM_LOG env var to set log level
|
69
|
+
- Retry Kerberos auth once if 401 response is received
|
70
|
+
- Remove Savon dependency and use newer versions of underlying dependencies
|
71
|
+
- Remove Nokogiri dependency and replace with native Ruby XML
|
72
|
+
- Fixed issue 85, ensure WQL response is not nil
|
73
|
+
- All WinRM library errors inherit from base class WinRMError
|
74
|
+
- Integrations tests should now pass on Windows Server 2008+
|
75
|
+
- Bump Ruby NTLM gem version dependency
|
76
|
+
- HTTP client receive timeout is now configurable via set_timeout
|
77
|
+
- Added backwards compatible Output class to make it easier to collect output
|
78
|
+
- Bumped gssapi dependency from 1.0 to 1.2 and fixed issue 54
|
79
|
+
- Added Rubocop to build
|
80
|
+
- Fixed error when commands contain a newline character
|
81
|
+
|
82
|
+
# 1.2.0
|
83
|
+
- Allow user to disable SSL peer ceritifcate validation #44
|
84
|
+
- Allow commands with "'" chars on Ruby 2.x, fixes #69
|
85
|
+
- Fixed uninitialized constant Module::Kconv in Ruby 2.x, fixes #65
|
86
|
+
- Commands with non-ASCII chars should work, #70
|