forked from rapid7/metasploit-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msfdb_ws
executable file
·82 lines (66 loc) · 2.13 KB
/
msfdb_ws
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env ruby
# -*- coding: binary -*-
#
# Starts the HTTP DB Service interface
require 'pathname'
require Pathname.new(__FILE__).realpath.expand_path.parent.join('config', 'boot')
require 'msf/core/db_manager/http/http_db_manager_service'
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_ws - Metasploit data store as a web service.\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 SSL Certificate file') do |p|
opts[:ssl_cert] = p
end
opt.on('-k', '--key <path/to/key.pem>', String, 'Path to 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 must be specified when using -s") if opts[:ssl] && (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