Mirror of metasploit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

msfrpcd 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env ruby
  2. # -*- coding: binary -*-
  3. #
  4. # $Id$
  5. #
  6. # This user interface listens on a port and provides clients that connect to
  7. # it with an RPC interface to the Metasploit Framework.
  8. #
  9. # $Revision$
  10. #
  11. msfbase = __FILE__
  12. while File.symlink?(msfbase)
  13. msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
  14. end
  15. $:.unshift(File.expand_path(File.join(File.dirname(msfbase), 'lib')))
  16. require 'msfenv'
  17. $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
  18. require 'rex/parser/arguments'
  19. # Declare the argument parser for msfrpcd
  20. arguments = Rex::Parser::Arguments.new(
  21. "-a" => [ true, "Bind to this IP address" ],
  22. "-p" => [ true, "Bind to this port instead of 55553" ],
  23. "-U" => [ true, "Specify the username to access msfrpcd" ],
  24. "-P" => [ true, "Specify the password to access msfrpcd" ],
  25. "-u" => [ true, "URI for Web server" ],
  26. "-t" => [ true, "Token Timeout (default 300 seconds" ],
  27. "-S" => [ false, "Disable SSL on the RPC socket" ],
  28. "-f" => [ false, "Run the daemon in the foreground" ],
  29. "-n" => [ false, "Disable database" ],
  30. "-h" => [ false, "Help banner" ])
  31. opts = {
  32. 'RunInForeground' => true,
  33. 'SSL' => true,
  34. 'ServerHost' => '0.0.0.0',
  35. 'ServerPort' => 55553,
  36. 'ServerType' => 'Msg',
  37. 'TokenTimeout' => 300,
  38. }
  39. foreground = false
  40. frameworkOpts = {}
  41. # Parse command line arguments.
  42. arguments.parse(ARGV) { |opt, idx, val|
  43. case opt
  44. when "-a"
  45. opts['ServerHost'] = val
  46. when "-S"
  47. opts['SSL'] = false
  48. when "-p"
  49. opts['ServerPort'] = val
  50. when '-U'
  51. opts['User'] = val
  52. when '-P'
  53. opts['Pass'] = val
  54. when "-t"
  55. opts['TokenTimeout'] = val.to_i
  56. when "-f"
  57. foreground = true
  58. when "-u"
  59. opts['URI'] = val
  60. when "-n"
  61. frameworkOpts['DisableDatabase'] = true
  62. when "-h"
  63. print("\nUsage: #{File.basename(__FILE__)} <options>\n" + arguments.usage)
  64. exit
  65. end
  66. }
  67. unless opts['Pass']
  68. $stderr.puts "[-] Error: a password must be specified (-P)"
  69. exit(0)
  70. end
  71. $0 = "msfrpcd"
  72. rpctype = 'MSG'
  73. $stderr.puts "[*] #{rpctype}RPC starting on #{opts['ServerHost']}:#{opts['ServerPort']} (#{opts['SSL'] ? "SSL" : "NO SSL"}):#{opts['ServerType']}..."
  74. $stderr.puts "[*] URI: #{opts['URI']}" if opts['URI']
  75. require 'msf/base'
  76. require 'msf/ui'
  77. # Fork into the background if requested
  78. begin
  79. if foreground
  80. $stdout.puts "[*] #{rpctype}RPC ready at #{Time.now}."
  81. else
  82. $stderr.puts "[*] #{rpctype}RPC backgrounding at #{Time.now}..."
  83. exit(0) if Process.fork()
  84. end
  85. rescue ::NotImplementedError
  86. $stderr.puts "[-] Background mode is not available on this platform"
  87. end
  88. # Create an instance of the framework
  89. $framework = Msf::Simple::Framework.create(frameworkOpts)
  90. # Run the plugin instance in the foreground.
  91. begin
  92. $framework.plugins.load("#{rpctype.downcase}rpc", opts).run
  93. rescue ::Interrupt
  94. $stderr.puts "[*] Shutting down"
  95. end