7
7
require 'pathname'
8
8
require Pathname . new ( __FILE__ ) . realpath . expand_path . parent . join ( 'config' , 'boot' )
9
9
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