Add option handling to msfdb

Can now specify custom interface and port.
Now able to specify starting in HTTPS mode.
GSoC/Meterpreter_Web_Console
James Barnett 2017-12-13 16:53:51 -06:00
parent 973f3bacd8
commit 908a695932
No known key found for this signature in database
GPG Key ID: 647983861A4EC5EA
2 changed files with 82 additions and 7 deletions

View File

@ -16,12 +16,14 @@ class HttpDBManagerService
require_environment!(parsed_options) require_environment!(parsed_options)
ssl_opts = {} if opts[:ssl]
ssl_opts[:private_key_file] = '/Users/jbarnett/rapid7/goliath/key.pem' ssl_opts = {}
ssl_opts[:cert_chain_file] = '/Users/jbarnett/rapid7/goliath/cert.pem' ssl_opts[:private_key_file] = opts[:ssl_key]
ssl_opts[:verify_peer] = false ssl_opts[:cert_chain_file] = opts[:ssl_cert]
opts[:ssl] = true ssl_opts[:verify_peer] = false
opts[:ssl_opts] = ssl_opts opts[:ssl] = true
opts[:ssl_opts] = ssl_opts
end
init_db init_db
start_http_server(opts) start_http_server(opts)
@ -41,6 +43,7 @@ class HttpDBManagerService
} }
if opts[:ssl] && opts[:ssl] = true if opts[:ssl] && opts[:ssl] = true
puts "Starting in HTTPS mode"
server.ssl = true server.ssl = true
server.ssl_options = opts[:ssl_opts] server.ssl_options = opts[:ssl_opts]
end end

74
msfdb
View File

@ -7,4 +7,76 @@
require 'pathname' require 'pathname'
require Pathname.new(__FILE__).realpath.expand_path.parent.join('config', 'boot') require Pathname.new(__FILE__).realpath.expand_path.parent.join('config', 'boot')
require 'msf/core/db_manager/http/http_db_manager_service' require 'msf/core/db_manager/http/http_db_manager_service'
HttpDBManagerService.new().start(:Port => '8080', :Host => '0.0.0.0') require 'optparse'
class HelpError < StandardError; end
class SwitchError < StandardError
def initialize(msg="Missing required switch.")
super(msg)
end
end
def parse_args(args)
opts = {}
opt = OptionParser.new
banner = "msfdb - A remote database process for Metasploit Framework.\n"
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
opt.on('-c', '--cert <path/to/cert.pem>', String, 'Path to your SSL Certificate file') do |p|
opts[:ssl_cert] = p
end
opt.on('-k', '--key <path/to/key.pem>', String, 'Path to your SSL Key file') do |p|
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)
raise SwitchError.new("certificate file and key file must be specified when using -s") if opts[:ssl] && (opts[:ssl_key].nil? || opts[:ssl_cert].nil?)
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