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.

msfd 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 msfconsole instance. The nice thing about this interface is that
  8. # it allows multiple clients to share one framework instance and thus makes it
  9. # possible for sessions to to be shared from a single vantage point.
  10. #
  11. # $Revision$
  12. #
  13. msfbase = __FILE__
  14. while File.symlink?(msfbase)
  15. msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
  16. end
  17. $:.unshift(File.expand_path(File.join(File.dirname(msfbase), 'lib')))
  18. require 'msfenv'
  19. $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
  20. require 'msf/base'
  21. require 'msf/ui'
  22. # Declare the argument parser for msfd
  23. arguments = Rex::Parser::Arguments.new(
  24. "-a" => [ true, "Bind to this IP address instead of loopback" ],
  25. "-p" => [ true, "Bind to this port instead of 55554" ],
  26. "-s" => [ false, "Use SSL" ],
  27. "-f" => [ false, "Run the daemon in the foreground" ],
  28. "-A" => [ true, "Specify list of hosts allowed to connect" ],
  29. "-D" => [ true, "Specify list of hosts not allowed to connect" ],
  30. "-q" => [ false, "Do not print the banner on startup" ],
  31. "-h" => [ false, "Help banner" ])
  32. opts = {
  33. 'RunInForeground' => true,
  34. 'DisableBanner' => false
  35. }
  36. foreground = false
  37. # Parse command line arguments.
  38. arguments.parse(ARGV) { |opt, idx, val|
  39. case opt
  40. when "-a"
  41. opts['ServerHost'] = val
  42. when "-p"
  43. opts['ServerPort'] = val
  44. when "-f"
  45. foreground = true
  46. when "-s"
  47. opts['SSL'] = true
  48. when "-A"
  49. begin
  50. opts['HostsAllowed'] = val.split(',').map { |a|
  51. Rex::Socket.resolv_nbo(a)
  52. }
  53. rescue
  54. $stderr.puts "Bad argument for -A: #{$!}"
  55. exit
  56. end
  57. when "-D"
  58. begin
  59. opts['HostsDenied'] = val.split(',').map { |a|
  60. Rex::Socket.resolv_nbo(a)
  61. }
  62. rescue
  63. $stderr.puts "Bad argument for -D: #{$!}"
  64. exit
  65. end
  66. when "-q"
  67. opts['DisableBanner'] = true
  68. when "-h"
  69. print(
  70. "\nUsage: #{File.basename(__FILE__)} <options>\n" +
  71. arguments.usage)
  72. exit
  73. end
  74. }
  75. $stderr.puts "[*] Initializing msfd..."
  76. $stderr.puts "[*] Running msfd..."
  77. # Fork into the background if requested
  78. begin
  79. if (not foreground)
  80. exit(0) if Process.fork()
  81. end
  82. rescue ::NotImplementedError
  83. $stderr.puts "[-] Background mode is not available on this platform"
  84. end
  85. # Create an instance of the framework
  86. $framework = Msf::Simple::Framework.create
  87. # Run the plugin instance in the foreground.
  88. $framework.plugins.load('msfd', opts).run(opts)