msfd 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 'rex/parser/arguments'
  21. # Declare the argument parser for msfd
  22. arguments = Rex::Parser::Arguments.new(
  23. "-a" => [ true, "Bind to this IP address instead of loopback" ],
  24. "-p" => [ true, "Bind to this port instead of 55554" ],
  25. "-s" => [ false, "Use SSL" ],
  26. "-f" => [ false, "Run the daemon in the foreground" ],
  27. "-A" => [ true, "Specify list of hosts allowed to connect" ],
  28. "-D" => [ true, "Specify list of hosts not allowed to connect" ],
  29. "-q" => [ false, "Do not print the banner on startup" ],
  30. "-h" => [ false, "Help banner" ])
  31. opts = {
  32. 'RunInForeground' => true,
  33. 'DisableBanner' => false
  34. }
  35. foreground = false
  36. # Parse command line arguments.
  37. arguments.parse(ARGV) { |opt, idx, val|
  38. case opt
  39. when "-a"
  40. opts['ServerHost'] = val
  41. when "-p"
  42. opts['ServerPort'] = val
  43. when "-f"
  44. foreground = true
  45. when "-s"
  46. opts['SSL'] = true
  47. when "-A"
  48. begin
  49. opts['HostsAllowed'] = val.split(',').map { |a|
  50. Rex::Socket.resolv_nbo(a)
  51. }
  52. rescue
  53. $stderr.puts "Bad argument for -A: #{$!}"
  54. exit
  55. end
  56. when "-D"
  57. begin
  58. opts['HostsDenied'] = val.split(',').map { |a|
  59. Rex::Socket.resolv_nbo(a)
  60. }
  61. rescue
  62. $stderr.puts "Bad argument for -D: #{$!}"
  63. exit
  64. end
  65. when "-q"
  66. opts['DisableBanner'] = true
  67. when "-h"
  68. print(
  69. "\nUsage: #{File.basename(__FILE__)} <options>\n" +
  70. arguments.usage)
  71. exit
  72. end
  73. }
  74. $stderr.puts "[*] Initializing msfd..."
  75. $stderr.puts "[*] Running msfd..."
  76. # Fork into the background if requested
  77. begin
  78. if (not foreground)
  79. exit(0) if Process.fork()
  80. end
  81. rescue ::NotImplementedError
  82. $stderr.puts "[-] Background mode is not available on this platform"
  83. end
  84. # Create an instance of the framework
  85. $framework = Msf::Simple::Framework.create
  86. # Run the plugin instance in the foreground.
  87. $framework.plugins.load('msfd', opts).run(opts)