Land #9738, msfconsole user-friendliness changes

4.x
William Vu 2018-04-01 02:12:53 -05:00 committed by Jeffrey Martin
parent 5560b201b0
commit d192be7764
No known key found for this signature in database
GPG Key ID: 0CD9BBC2AF15F171
3 changed files with 24 additions and 15 deletions

View File

@ -39,7 +39,13 @@ class Metasploit::Framework::ParsedOptions::Base
# #
def initialize(arguments=ARGV) 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 end
# Translates {#options} to the `application`'s config # Translates {#options} to the `application`'s config
@ -102,20 +108,19 @@ class Metasploit::Framework::ParsedOptions::Base
def option_parser def option_parser
@option_parser ||= OptionParser.new { |option_parser| @option_parser ||= OptionParser.new { |option_parser|
option_parser.separator '' option_parser.separator ''
option_parser.separator 'Common options' option_parser.separator 'Common options:'
option_parser.on( option_parser.on(
'-E', '-E',
'--environment ENVIRONMENT', '--environment ENVIRONMENT',
%w{development production test}, %w{development production test},
"The Rails environment. Will use RAIL_ENV environment variable if that is set. " \ "Set Rails environment, defaults to RAIL_ENV environment variable or 'production'"
"Defaults to production if neither option not RAILS_ENV environment variable is set."
) do |environment| ) do |environment|
options.environment = environment options.environment = environment
end end
option_parser.separator '' option_parser.separator ''
option_parser.separator 'Database options' option_parser.separator 'Database options:'
option_parser.on( option_parser.on(
'-M', '-M',
@ -138,7 +143,7 @@ class Metasploit::Framework::ParsedOptions::Base
end end
option_parser.separator '' 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| option_parser.on('-c', '-c FILE', 'Load the specified configuration file') do |file|
@ -146,7 +151,7 @@ class Metasploit::Framework::ParsedOptions::Base
end end
option_parser.on( option_parser.on(
'-v', '-v','-V',
'--version', '--version',
'Show version' 'Show version'
) do ) do
@ -154,7 +159,7 @@ class Metasploit::Framework::ParsedOptions::Base
end end
option_parser.separator '' option_parser.separator ''
option_parser.separator 'Module options' option_parser.separator 'Module options:'
option_parser.on( option_parser.on(
'--defer-module-loads', '--defer-module-loads',
@ -166,7 +171,7 @@ class Metasploit::Framework::ParsedOptions::Base
option_parser.on( option_parser.on(
'-m', '-m',
'--module-path DIRECTORY', '--module-path DIRECTORY',
'An additional module path' 'Load an additional module path'
) do |directory| ) do |directory|
options.modules.path = directory options.modules.path = directory
end end

View File

@ -33,7 +33,6 @@ class Metasploit::Framework::ParsedOptions::Console < Metasploit::Framework::Par
super.tap { |option_parser| super.tap { |option_parser|
option_parser.banner = "Usage: #{option_parser.program_name} [options]" option_parser.banner = "Usage: #{option_parser.program_name} [options]"
option_parser.separator ''
option_parser.separator 'Console options:' option_parser.separator 'Console options:'
option_parser.on('-a', '--ask', "Ask before exiting Metasploit or accept 'exit -y'") do 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( option_parser.on(
'-x', '-x',
'--execute-command COMMAND', '--execute-command COMMAND',
'Execute the specified string as console commands (use ; for multiples)' 'Execute the specified console commands (use ; for multiples)'
) do |commands| ) do |commands|
options.console.commands += commands.split(/\s*;\s*/) options.console.commands += commands.split(/\s*;\s*/)
end end

View File

@ -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 # @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') begin
require 'metasploit/framework/command/console' require Pathname.new(__FILE__).realpath.expand_path.parent.join('config', 'boot')
require 'msf/core/payload_generator' require 'metasploit/framework/command/console'
Metasploit::Framework::Command::Console.start require 'msf/core/payload_generator'
Metasploit::Framework::Command::Console.start
rescue Interrupt
puts "\nAborting..."
exit(1)
end