From d192be7764cdef68f688a1428fdb9367377b525d Mon Sep 17 00:00:00 2001 From: William Vu Date: Sun, 1 Apr 2018 02:12:53 -0500 Subject: [PATCH] Land #9738, msfconsole user-friendliness changes --- .../framework/parsed_options/base.rb | 23 +++++++++++-------- .../framework/parsed_options/console.rb | 3 +-- msfconsole | 13 +++++++---- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/metasploit/framework/parsed_options/base.rb b/lib/metasploit/framework/parsed_options/base.rb index 4ccfceeb29..1fe98418d5 100644 --- a/lib/metasploit/framework/parsed_options/base.rb +++ b/lib/metasploit/framework/parsed_options/base.rb @@ -39,7 +39,13 @@ class Metasploit::Framework::ParsedOptions::Base # def initialize(arguments=ARGV) - @positional = option_parser.parse(arguments) + begin + @positional = option_parser.parse(arguments) + rescue OptionParser::InvalidOption + puts "ERROR: Invalid command line option provided." + puts option_parser + exit(1) + end end # Translates {#options} to the `application`'s config @@ -102,20 +108,19 @@ class Metasploit::Framework::ParsedOptions::Base def option_parser @option_parser ||= OptionParser.new { |option_parser| option_parser.separator '' - option_parser.separator 'Common options' + option_parser.separator 'Common options:' option_parser.on( '-E', '--environment ENVIRONMENT', %w{development production test}, - "The Rails environment. Will use RAIL_ENV environment variable if that is set. " \ - "Defaults to production if neither option not RAILS_ENV environment variable is set." + "Set Rails environment, defaults to RAIL_ENV environment variable or 'production'" ) do |environment| options.environment = environment end option_parser.separator '' - option_parser.separator 'Database options' + option_parser.separator 'Database options:' option_parser.on( '-M', @@ -138,7 +143,7 @@ class Metasploit::Framework::ParsedOptions::Base end option_parser.separator '' - option_parser.separator 'Framework options' + option_parser.separator 'Framework options:' option_parser.on('-c', '-c FILE', 'Load the specified configuration file') do |file| @@ -146,7 +151,7 @@ class Metasploit::Framework::ParsedOptions::Base end option_parser.on( - '-v', + '-v','-V', '--version', 'Show version' ) do @@ -154,7 +159,7 @@ class Metasploit::Framework::ParsedOptions::Base end option_parser.separator '' - option_parser.separator 'Module options' + option_parser.separator 'Module options:' option_parser.on( '--defer-module-loads', @@ -166,7 +171,7 @@ class Metasploit::Framework::ParsedOptions::Base option_parser.on( '-m', '--module-path DIRECTORY', - 'An additional module path' + 'Load an additional module path' ) do |directory| options.modules.path = directory end diff --git a/lib/metasploit/framework/parsed_options/console.rb b/lib/metasploit/framework/parsed_options/console.rb index 3ff72a0b0a..70aba2ce82 100644 --- a/lib/metasploit/framework/parsed_options/console.rb +++ b/lib/metasploit/framework/parsed_options/console.rb @@ -33,7 +33,6 @@ class Metasploit::Framework::ParsedOptions::Console < Metasploit::Framework::Par super.tap { |option_parser| option_parser.banner = "Usage: #{option_parser.program_name} [options]" - option_parser.separator '' option_parser.separator 'Console options:' 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 option_parser.on( '-x', '--execute-command COMMAND', - 'Execute the specified string as console commands (use ; for multiples)' + 'Execute the specified console commands (use ; for multiples)' ) do |commands| options.console.commands += commands.split(/\s*;\s*/) end diff --git a/msfconsole b/msfconsole index b9ba9f0b52..5e2b72eb22 100755 --- a/msfconsole +++ b/msfconsole @@ -42,7 +42,12 @@ end # # @see https://github.com/rails/rails/blob/v3.2.17/railties/lib/rails/generators/rails/app/templates/script/rails#L3-L5 -require Pathname.new(__FILE__).realpath.expand_path.parent.join('config', 'boot') -require 'metasploit/framework/command/console' -require 'msf/core/payload_generator' -Metasploit::Framework::Command::Console.start +begin + require Pathname.new(__FILE__).realpath.expand_path.parent.join('config', 'boot') + require 'metasploit/framework/command/console' + require 'msf/core/payload_generator' + Metasploit::Framework::Command::Console.start +rescue Interrupt + puts "\nAborting..." + exit(1) +end