2017-07-07 18:33:42 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# -*- coding: binary -*-
|
|
|
|
#
|
2017-10-02 16:17:45 +00:00
|
|
|
# Starts the HTTP DB Service interface
|
2017-07-07 18:33:42 +00:00
|
|
|
|
2017-12-13 22:53:51 +00:00
|
|
|
require 'optparse'
|
|
|
|
|
|
|
|
class HelpError < StandardError; end
|
|
|
|
|
|
|
|
class SwitchError < StandardError
|
|
|
|
def initialize(msg="Missing required switch.")
|
|
|
|
super(msg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-04 22:56:23 +00:00
|
|
|
def require_deps
|
|
|
|
require 'pathname'
|
|
|
|
require Pathname.new(__FILE__).realpath.expand_path.parent.join('config', 'boot')
|
|
|
|
require 'msf/core/db_manager/http/http_db_manager_service'
|
|
|
|
end
|
|
|
|
|
2017-12-13 22:53:51 +00:00
|
|
|
def parse_args(args)
|
|
|
|
opts = {}
|
|
|
|
opt = OptionParser.new
|
2018-02-01 22:28:36 +00:00
|
|
|
banner = "msfdb_ws - Metasploit data store as a web service.\n"
|
2017-12-13 22:53:51 +00:00
|
|
|
banner << "Usage: #{$0} [options] <var=val>"
|
|
|
|
opt.banner = banner
|
|
|
|
opt.separator('')
|
|
|
|
opt.separator('Options:')
|
|
|
|
|
|
|
|
# Defaults:
|
|
|
|
opts[:interface] = '0.0.0.0'
|
|
|
|
opts[:port] = 8080
|
|
|
|
opts[:ssl] = false
|
|
|
|
opts[:ssl_cert] = nil
|
|
|
|
opts[:ssl_key] = nil
|
|
|
|
|
|
|
|
opt.on('-i', '--interface <interface>', String, 'Interface to listen on') do |p|
|
|
|
|
opts[:interface] = p
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.on('-p', '--port <port number>', Integer, 'Port to listen on') do |p|
|
|
|
|
opts[:port] = p
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.on('-s', '--ssl', 'Enable SSL on the server') do |p|
|
|
|
|
opts[:ssl] = true
|
|
|
|
end
|
|
|
|
|
2018-01-19 21:46:24 +00:00
|
|
|
opt.on('-c', '--cert <path/to/cert.pem>', String, 'Path to SSL Certificate file') do |p|
|
2017-12-13 22:53:51 +00:00
|
|
|
opts[:ssl_cert] = p
|
|
|
|
end
|
|
|
|
|
2018-01-19 21:46:24 +00:00
|
|
|
opt.on('-k', '--key <path/to/key.pem>', String, 'Path to SSL Key file') do |p|
|
2017-12-13 22:53:51 +00:00
|
|
|
opts[:ssl_key] = p
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.on_tail('-h', '--help', 'Show this message') do
|
|
|
|
raise HelpError, "#{opt}"
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
opt.parse!(args)
|
|
|
|
rescue OptionParser::InvalidOption => e
|
|
|
|
raise UsageError, "Invalid option\n#{opt}"
|
|
|
|
rescue OptionParser::MissingArgument => e
|
|
|
|
raise UsageError, "Missing required argument for option\n#{opt}"
|
|
|
|
end
|
|
|
|
|
|
|
|
opts
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
opts = parse_args(ARGV)
|
2018-02-05 21:23:00 +00:00
|
|
|
raise SwitchError.new("certificate file must be specified when using -s") if opts[:ssl] && (opts[:ssl_cert].nil?)
|
2018-08-04 22:56:23 +00:00
|
|
|
require_deps
|
2017-12-13 22:53:51 +00:00
|
|
|
HttpDBManagerService.new.start(:Port => opts[:port],
|
|
|
|
:Host => opts[:interface],
|
|
|
|
:ssl => opts[:ssl],
|
|
|
|
:ssl_cert => opts[:ssl_cert],
|
|
|
|
:ssl_key => opts[:ssl_key])
|
|
|
|
rescue HelpError => e
|
|
|
|
$stderr.puts e.message
|
|
|
|
end
|
|
|
|
|