Skip to content

Commit 908a695

Browse files
committed
Add option handling to msfdb
Can now specify custom interface and port. Now able to specify starting in HTTPS mode.
1 parent 973f3ba commit 908a695

File tree

2 files changed

+82
-7
lines changed

2 files changed

+82
-7
lines changed

lib/msf/core/db_manager/http/http_db_manager_service.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ def start(opts)
1616

1717
require_environment!(parsed_options)
1818

19-
ssl_opts = {}
20-
ssl_opts[:private_key_file] = '/Users/jbarnett/rapid7/goliath/key.pem'
21-
ssl_opts[:cert_chain_file] = '/Users/jbarnett/rapid7/goliath/cert.pem'
22-
ssl_opts[:verify_peer] = false
23-
opts[:ssl] = true
24-
opts[:ssl_opts] = ssl_opts
19+
if opts[:ssl]
20+
ssl_opts = {}
21+
ssl_opts[:private_key_file] = opts[:ssl_key]
22+
ssl_opts[:cert_chain_file] = opts[:ssl_cert]
23+
ssl_opts[:verify_peer] = false
24+
opts[:ssl] = true
25+
opts[:ssl_opts] = ssl_opts
26+
end
2527

2628
init_db
2729
start_http_server(opts)
@@ -41,6 +43,7 @@ def start_http_server(opts)
4143
}
4244

4345
if opts[:ssl] && opts[:ssl] = true
46+
puts "Starting in HTTPS mode"
4447
server.ssl = true
4548
server.ssl_options = opts[:ssl_opts]
4649
end

msfdb

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,76 @@
77
require 'pathname'
88
require Pathname.new(__FILE__).realpath.expand_path.parent.join('config', 'boot')
99
require 'msf/core/db_manager/http/http_db_manager_service'
10-
HttpDBManagerService.new().start(:Port => '8080', :Host => '0.0.0.0')
10+
require 'optparse'
11+
12+
class HelpError < StandardError; end
13+
14+
class SwitchError < StandardError
15+
def initialize(msg="Missing required switch.")
16+
super(msg)
17+
end
18+
end
19+
20+
def parse_args(args)
21+
opts = {}
22+
opt = OptionParser.new
23+
banner = "msfdb - A remote database process for Metasploit Framework.\n"
24+
banner << "Usage: #{$0} [options] <var=val>"
25+
opt.banner = banner
26+
opt.separator('')
27+
opt.separator('Options:')
28+
29+
# Defaults:
30+
opts[:interface] = '0.0.0.0'
31+
opts[:port] = 8080
32+
opts[:ssl] = false
33+
opts[:ssl_cert] = nil
34+
opts[:ssl_key] = nil
35+
36+
opt.on('-i', '--interface <interface>', String, 'Interface to listen on') do |p|
37+
opts[:interface] = p
38+
end
39+
40+
opt.on('-p', '--port <port number>', Integer, 'Port to listen on') do |p|
41+
opts[:port] = p
42+
end
43+
44+
opt.on('-s', '--ssl', 'Enable SSL on the server') do |p|
45+
opts[:ssl] = true
46+
end
47+
48+
opt.on('-c', '--cert <path/to/cert.pem>', String, 'Path to your SSL Certificate file') do |p|
49+
opts[:ssl_cert] = p
50+
end
51+
52+
opt.on('-k', '--key <path/to/key.pem>', String, 'Path to your SSL Key file') do |p|
53+
opts[:ssl_key] = p
54+
end
55+
56+
opt.on_tail('-h', '--help', 'Show this message') do
57+
raise HelpError, "#{opt}"
58+
end
59+
60+
begin
61+
opt.parse!(args)
62+
rescue OptionParser::InvalidOption => e
63+
raise UsageError, "Invalid option\n#{opt}"
64+
rescue OptionParser::MissingArgument => e
65+
raise UsageError, "Missing required argument for option\n#{opt}"
66+
end
67+
68+
opts
69+
end
70+
71+
begin
72+
opts = parse_args(ARGV)
73+
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?)
74+
HttpDBManagerService.new.start(:Port => opts[:port],
75+
:Host => opts[:interface],
76+
:ssl => opts[:ssl],
77+
:ssl_cert => opts[:ssl_cert],
78+
:ssl_key => opts[:ssl_key])
79+
rescue HelpError => e
80+
$stderr.puts e.message
81+
end
82+

0 commit comments

Comments
 (0)