winrm-elevated 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/VERSION +1 -1
- data/changelog.md +4 -1
- data/lib/winrm-elevated/runner.rb +16 -9
- data/winrm-elevated.gemspec +2 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0420d9b98e357f1cf14dbd04f4955b7ae22fc4e
|
4
|
+
data.tar.gz: a90fd7ad69ebd4a66061d06ffa44559ed42c3729
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1430d0e0c73f91c58b0235079bd94ddb2dea3a206eb2adae5154c3bdbd258e5abec7b9e86ffc4cb6492cb51188fcb297c08c96b0a613ce5293c8e910d54a724e
|
7
|
+
data.tar.gz: 0e80a6e1d4110639c9bb9529d16c782c49092c924ea70f97c78b605b9d193f0b8ba69562752eab7bdec617ad031b5979442bc7517034515b1396ca984971d448
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Runs PowerShell commands as elevated over Windows Remote Management (WinRM) via a scheduled task
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/winrm-elevated.svg)](http://badge.fury.io/rb/winrm-elevated)
|
3
3
|
|
4
|
+
This gem allows you to break out of the magical WinRM constraints thus allowing to reach out to network shares and even install Windows updates, .NET, SQL Server etc.
|
5
|
+
|
4
6
|
## Running commands elevated
|
5
7
|
```ruby
|
6
8
|
require 'winrm'
|
@@ -12,6 +14,16 @@ result = elevated_runner.powershell_elevated('dir', 'Administrator', 'password')
|
|
12
14
|
puts "Std out: #{result.output}"
|
13
15
|
```
|
14
16
|
|
17
|
+
## How does it work?
|
18
|
+
|
19
|
+
The gem works by creating a new logon session local to the Windows box by using a scheduled task. After this point WinRM is just used to read output from the scheduled task via a log file.
|
20
|
+
|
21
|
+
1. The command you'd like to run outside the WinRM context is encoded and placed inside the PowerShell script elevated_shell.ps1.
|
22
|
+
2. The script is uploaded to the machine over WinRM.
|
23
|
+
3. The script is executed over WinRM and the script does the following:
|
24
|
+
1. Scheduled task is created which will execute your command and redirect stdout and stderr to a location known by elevated_shell.ps1.
|
25
|
+
2. The scheduled task is executed.
|
26
|
+
3. elevated_shell.ps1 polls the stdout and stderr log files and writes them back to WinRM. The script continues in this loop until the scheduled task is complete.
|
15
27
|
|
16
28
|
## Troubleshooting
|
17
29
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/changelog.md
CHANGED
@@ -27,6 +27,7 @@ module WinRM
|
|
27
27
|
@winrm_service = winrm_service
|
28
28
|
@winrm_file_manager = WinRM::FS::FileManager.new(winrm_service)
|
29
29
|
@elevated_shell_path = 'c:/windows/temp/winrm-elevated-shell.ps1'
|
30
|
+
@uploaded = nil
|
30
31
|
end
|
31
32
|
|
32
33
|
# Run a command or PowerShell script elevated without any of the
|
@@ -49,18 +50,24 @@ module WinRM
|
|
49
50
|
private
|
50
51
|
|
51
52
|
def upload_elevated_shell_wrapper_script
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
file.close
|
57
|
-
@winrm_file_manager.upload(file.path, @elevated_shell_path)
|
58
|
-
ensure
|
59
|
-
file.close
|
60
|
-
file.unlink
|
53
|
+
return if @uploaded
|
54
|
+
with_temp_file do |temp_file|
|
55
|
+
@winrm_file_manager.upload(temp_file, @elevated_shell_path)
|
56
|
+
@uploaded = true
|
61
57
|
end
|
62
58
|
end
|
63
59
|
|
60
|
+
def with_temp_file
|
61
|
+
file = Tempfile.new(['winrm-elevated-shell', 'ps1'])
|
62
|
+
file.write(elevated_shell_script_content)
|
63
|
+
file.fsync
|
64
|
+
file.close
|
65
|
+
yield file.path
|
66
|
+
ensure
|
67
|
+
file.close
|
68
|
+
file.unlink
|
69
|
+
end
|
70
|
+
|
64
71
|
def elevated_shell_script_content
|
65
72
|
IO.read(File.expand_path('../scripts/elevated_shell.ps1', __FILE__))
|
66
73
|
end
|
data/winrm-elevated.gemspec
CHANGED
@@ -25,8 +25,8 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.extra_rdoc_files = %w(README.md LICENSE)
|
26
26
|
|
27
27
|
s.required_ruby_version = '>= 1.9.0'
|
28
|
-
s.add_runtime_dependency 'winrm', '~> 1.
|
29
|
-
s.add_runtime_dependency 'winrm-fs', '~> 0.
|
28
|
+
s.add_runtime_dependency 'winrm', '~> 1.5'
|
29
|
+
s.add_runtime_dependency 'winrm-fs', '~> 0.3.0'
|
30
30
|
s.add_development_dependency 'rspec', '~> 3.2'
|
31
31
|
s.add_development_dependency 'rake', '~> 10.3'
|
32
32
|
s.add_development_dependency 'rubocop', '~> 0.28'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: winrm-elevated
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shawn Neal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: winrm
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: winrm-fs
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.3.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.3.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
134
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.
|
135
|
+
rubygems_version: 2.5.2
|
136
136
|
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: Ruby library for running commands as elevated
|