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

GSoC/Meterpreter_Web_Console
Aaron Soto 2018-03-20 13:34:15 -05:00
parent 65b0d9555f
commit 7e5214fef5
No known key found for this signature in database
GPG Key ID: A974121808B92094
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)
begin
@positional = option_parser.parse(arguments) @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
begin
require Pathname.new(__FILE__).realpath.expand_path.parent.join('config', 'boot') require Pathname.new(__FILE__).realpath.expand_path.parent.join('config', 'boot')
require 'metasploit/framework/command/console' require 'metasploit/framework/command/console'
require 'msf/core/payload_generator' require 'msf/core/payload_generator'
Metasploit::Framework::Command::Console.start Metasploit::Framework::Command::Console.start
rescue Interrupt
puts "\nAborting..."
exit(1)
end