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.

msfdb_ws 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env ruby
  2. # -*- coding: binary -*-
  3. #
  4. # Starts the HTTP DB Service interface
  5. require 'optparse'
  6. class HelpError < StandardError; end
  7. class SwitchError < StandardError
  8. def initialize(msg="Missing required switch.")
  9. super(msg)
  10. end
  11. end
  12. def require_deps
  13. require 'pathname'
  14. require Pathname.new(__FILE__).realpath.expand_path.parent.join('config', 'boot')
  15. require 'msf/core/web_services/http_db_manager_service'
  16. end
  17. def parse_args(args)
  18. opts = {}
  19. opt = OptionParser.new
  20. banner = "msfdb_ws - Metasploit data store as a web service.\n"
  21. banner << "Usage: #{$0} [options] <var=val>"
  22. opt.banner = banner
  23. opt.separator('')
  24. opt.separator('Options:')
  25. # Defaults:
  26. opts[:interface] = '0.0.0.0'
  27. opts[:port] = 8080
  28. opts[:ssl] = false
  29. opts[:ssl_cert] = nil
  30. opts[:ssl_key] = nil
  31. opt.on('-i', '--interface <interface>', String, 'Interface to listen on') do |p|
  32. opts[:interface] = p
  33. end
  34. opt.on('-p', '--port <port number>', Integer, 'Port to listen on') do |p|
  35. opts[:port] = p
  36. end
  37. opt.on('-s', '--ssl', 'Enable SSL on the server') do |p|
  38. opts[:ssl] = true
  39. end
  40. opt.on('-c', '--cert <path/to/cert.pem>', String, 'Path to SSL Certificate file') do |p|
  41. opts[:ssl_cert] = p
  42. end
  43. opt.on('-k', '--key <path/to/key.pem>', String, 'Path to SSL Key file') do |p|
  44. opts[:ssl_key] = p
  45. end
  46. opt.on_tail('-h', '--help', 'Show this message') do
  47. raise HelpError, "#{opt}"
  48. end
  49. begin
  50. opt.parse!(args)
  51. rescue OptionParser::InvalidOption => e
  52. raise UsageError, "Invalid option\n#{opt}"
  53. rescue OptionParser::MissingArgument => e
  54. raise UsageError, "Missing required argument for option\n#{opt}"
  55. end
  56. opts
  57. end
  58. begin
  59. opts = parse_args(ARGV)
  60. raise SwitchError.new("certificate file must be specified when using -s") if opts[:ssl] && (opts[:ssl_cert].nil?)
  61. require_deps
  62. HttpDBManagerService.new.start(:Port => opts[:port],
  63. :Host => opts[:interface],
  64. :ssl => opts[:ssl],
  65. :ssl_cert => opts[:ssl_cert],
  66. :ssl_key => opts[:ssl_key])
  67. rescue HelpError => e
  68. $stderr.puts e.message
  69. end