Add option handling to msfdb
Can now specify custom interface and port. Now able to specify starting in HTTPS mode.GSoC/Meterpreter_Web_Console
parent
973f3bacd8
commit
908a695932
|
@ -16,12 +16,14 @@ class HttpDBManagerService
|
|||
|
||||
require_environment!(parsed_options)
|
||||
|
||||
ssl_opts = {}
|
||||
ssl_opts[:private_key_file] = '/Users/jbarnett/rapid7/goliath/key.pem'
|
||||
ssl_opts[:cert_chain_file] = '/Users/jbarnett/rapid7/goliath/cert.pem'
|
||||
ssl_opts[:verify_peer] = false
|
||||
opts[:ssl] = true
|
||||
opts[:ssl_opts] = ssl_opts
|
||||
if opts[:ssl]
|
||||
ssl_opts = {}
|
||||
ssl_opts[:private_key_file] = opts[:ssl_key]
|
||||
ssl_opts[:cert_chain_file] = opts[:ssl_cert]
|
||||
ssl_opts[:verify_peer] = false
|
||||
opts[:ssl] = true
|
||||
opts[:ssl_opts] = ssl_opts
|
||||
end
|
||||
|
||||
init_db
|
||||
start_http_server(opts)
|
||||
|
@ -41,6 +43,7 @@ class HttpDBManagerService
|
|||
}
|
||||
|
||||
if opts[:ssl] && opts[:ssl] = true
|
||||
puts "Starting in HTTPS mode"
|
||||
server.ssl = true
|
||||
server.ssl_options = opts[:ssl_opts]
|
||||
end
|
||||
|
|
74
msfdb
74
msfdb
|
@ -7,4 +7,76 @@
|
|||
require 'pathname'
|
||||
require Pathname.new(__FILE__).realpath.expand_path.parent.join('config', 'boot')
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue