Skip to content

Commit 386e148

Browse files
committed
Land rapid7#8728, Psexec via PSH related fixes
2 parents 8004b9d + b83787c commit 386e148

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lib/msf/core/exploit/powershell.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ def initialize(info = {})
1414
OptBool.new('Powershell::sub_vars', [true, 'Substitute variable names', false]),
1515
OptBool.new('Powershell::sub_funcs', [true, 'Substitute function names', false]),
1616
OptBool.new('Powershell::exec_in_place', [true, 'Produce PSH without executable wrapper', false]),
17+
OptBool.new('Powershell::remove_comspec', [true, 'Produce script calling powershell directly', false]),
18+
OptBool.new('Powershell::noninteractive', [true, 'Execute powershell without interaction', true]),
1719
OptBool.new('Powershell::encode_final_payload', [true, 'Encode final payload for -EncodedCommand', false]),
1820
OptBool.new('Powershell::encode_inner_payload', [true, 'Encode inner payload for -EncodedCommand', false]),
19-
OptBool.new('Powershell::use_single_quotes', [true, 'Wraps the -Command argument in single quotes', false]),
21+
OptBool.new('Powershell::wrap_double_quotes', [true, 'Wraps the -Command argument in single quotes', true]),
2022
OptBool.new('Powershell::no_equals', [true, 'Pad base64 until no "=" remains', false]),
2123
OptEnum.new('Powershell::method', [true, 'Payload delivery method', 'reflection', %w[net reflection old msil]])
2224
]
@@ -215,14 +217,13 @@ def run_hidden_psh(ps_code, payload_arch, encoded)
215217
# powershell script
216218
# @option opts [Boolean] :remove_comspec Removes the %COMSPEC%
217219
# environment variable at the start of the command line
218-
# @option opts [Boolean] :use_single_quotes Wraps the -Command
219-
# argument in single quotes unless :encode_final_payload
220+
# @option opts [Boolean] :wrap_double_quotes Wraps the -Command
221+
# argument in double quotes unless :encode_final_payload
220222
#
221223
# @return [String] Powershell command line with payload
222224
def cmd_psh_payload(pay, payload_arch, opts = {})
223-
options.validate(datastore)
224-
225-
%i[persist prepend_sleep exec_in_place encode_final_payload encode_inner_payload use_single_quotes no_equals method].map do |opt|
225+
%i[persist prepend_sleep exec_in_place encode_final_payload encode_inner_payload
226+
remove_comspec noninteractive wrap_double_quotes no_equals method].map do |opt|
226227
opts[opt] ||= datastore["Powershell::#{opt}"]
227228
end
228229

spec/lib/msf/core/exploit/powershell_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,13 @@ def decompress(code)
276276
end
277277
it 'shouldnt shorten args' do
278278
code = subject.cmd_psh_payload(payload, arch)
279-
expect(code.include?('-NoProfile -WindowStyle hidden -Command')).to be_truthy
279+
expect(code.include?('-NoProfile ')).to be_truthy
280+
expect(code.include?('-WindowStyle hidden')).to be_truthy
281+
expect(code.include?('-Command ')).to be_truthy
280282
end
281283
it 'should include -NoExit' do
282284
code = subject.cmd_psh_payload(payload, arch)
283-
expect(code.include?('-NoProfile -WindowStyle hidden -NoExit -Command')).to be_truthy
285+
expect(code.include?('-NoExit ')).to be_truthy
284286
end
285287
end
286288

0 commit comments

Comments
 (0)