Browse Source

Improved CTRL-C edge case, Invalid Options edge case, help output, version output

Aaron Soto 1 year ago
parent
commit
7e5214fef5
No account linked to committer's email address

+ 14
- 9
lib/metasploit/framework/parsed_options/base.rb View File

@@ -39,7 +39,13 @@ class Metasploit::Framework::ParsedOptions::Base
39 39
   #
40 40
 
41 41
   def initialize(arguments=ARGV)
42
-    @positional = option_parser.parse(arguments)
42
+    begin
43
+      @positional = option_parser.parse(arguments)
44
+    rescue OptionParser::InvalidOption
45
+      puts "ERROR: Invalid command line option provided."
46
+      puts option_parser
47
+      exit(1)
48
+    end
43 49
   end
44 50
 
45 51
   # Translates {#options} to the `application`'s config
@@ -102,20 +108,19 @@ class Metasploit::Framework::ParsedOptions::Base
102 108
   def option_parser
103 109
     @option_parser ||= OptionParser.new { |option_parser|
104 110
       option_parser.separator ''
105
-      option_parser.separator 'Common options'
111
+      option_parser.separator 'Common options:'
106 112
 
107 113
       option_parser.on(
108 114
           '-E',
109 115
           '--environment ENVIRONMENT',
110 116
           %w{development production test},
111
-          "The Rails environment. Will use RAIL_ENV environment variable if that is set.  " \
112
-          "Defaults to production if neither option not RAILS_ENV environment variable is set."
117
+          "Set Rails environment, defaults to RAIL_ENV environment variable or 'production'"
113 118
       ) do |environment|
114 119
         options.environment = environment
115 120
       end
116 121
 
117 122
       option_parser.separator ''
118
-      option_parser.separator 'Database options'
123
+      option_parser.separator 'Database options:'
119 124
 
120 125
       option_parser.on(
121 126
           '-M',
@@ -138,7 +143,7 @@ class Metasploit::Framework::ParsedOptions::Base
138 143
       end
139 144
 
140 145
       option_parser.separator ''
141
-      option_parser.separator 'Framework options'
146
+      option_parser.separator 'Framework options:'
142 147
 
143 148
 
144 149
       option_parser.on('-c', '-c FILE', 'Load the specified configuration file') do |file|
@@ -146,7 +151,7 @@ class Metasploit::Framework::ParsedOptions::Base
146 151
       end
147 152
 
148 153
       option_parser.on(
149
-          '-v',
154
+          '-v','-V',
150 155
           '--version',
151 156
           'Show version'
152 157
       ) do
@@ -154,7 +159,7 @@ class Metasploit::Framework::ParsedOptions::Base
154 159
       end
155 160
 
156 161
       option_parser.separator ''
157
-      option_parser.separator 'Module options'
162
+      option_parser.separator 'Module options:'
158 163
 
159 164
       option_parser.on(
160 165
           '--defer-module-loads',
@@ -166,7 +171,7 @@ class Metasploit::Framework::ParsedOptions::Base
166 171
       option_parser.on(
167 172
           '-m',
168 173
           '--module-path DIRECTORY',
169
-          'An additional module path'
174
+          'Load an additional module path'
170 175
       ) do |directory|
171 176
         options.modules.path = directory
172 177
       end

+ 1
- 2
lib/metasploit/framework/parsed_options/console.rb View File

@@ -33,7 +33,6 @@ class Metasploit::Framework::ParsedOptions::Console < Metasploit::Framework::Par
33 33
       super.tap { |option_parser|
34 34
         option_parser.banner = "Usage: #{option_parser.program_name} [options]"
35 35
 
36
-        option_parser.separator ''
37 36
         option_parser.separator 'Console options:'
38 37
 
39 38
         option_parser.on('-a', '--ask', "Ask before exiting Metasploit or accept 'exit -y'") do
@@ -67,7 +66,7 @@ class Metasploit::Framework::ParsedOptions::Console < Metasploit::Framework::Par
67 66
         option_parser.on(
68 67
             '-x',
69 68
             '--execute-command COMMAND',
70
-            'Execute the specified string as console commands (use ; for multiples)'
69
+            'Execute the specified console commands (use ; for multiples)'
71 70
         ) do |commands|
72 71
           options.console.commands += commands.split(/\s*;\s*/)
73 72
         end

+ 9
- 4
msfconsole View File

@@ -42,7 +42,12 @@ end
42 42
 #
43 43
 
44 44
 # @see https://github.com/rails/rails/blob/v3.2.17/railties/lib/rails/generators/rails/app/templates/script/rails#L3-L5
45
-require Pathname.new(__FILE__).realpath.expand_path.parent.join('config', 'boot')
46
-require 'metasploit/framework/command/console'
47
-require 'msf/core/payload_generator'
48
-Metasploit::Framework::Command::Console.start
45
+begin
46
+  require Pathname.new(__FILE__).realpath.expand_path.parent.join('config', 'boot')
47
+  require 'metasploit/framework/command/console'
48
+  require 'msf/core/payload_generator'
49
+  Metasploit::Framework::Command::Console.start
50
+rescue Interrupt
51
+  puts "\nAborting..."
52
+  exit(1)
53
+end

Loading…
Cancel
Save