Class: Metasploit::Framework::ParsedOptions::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/metasploit/framework/parsed_options/base.rb

Overview

Options parsed from the command line that can be used to change the ‘Metasploit::Framework::Application.config` and `Rails.env`

Direct Known Subclasses

Console, RemoteDB

Constant Summary collapse

DEFAULT_ENVIRONMENT =

msfconsole boots in production mode instead of the normal rails default of development.

'production'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments = ARGV) ⇒ Base

Instance Methods



41
42
43
44
45
46
47
48
49
# File 'lib/metasploit/framework/parsed_options/base.rb', line 41

def initialize(arguments=ARGV)
  begin
    @positional = option_parser.parse(arguments)
  rescue OptionParser::InvalidOption
    puts "ERROR: Invalid command line option provided."
    puts option_parser
    exit(1)
  end
end

Instance Attribute Details

#positionalObject (readonly)

Attributes



35
36
37
# File 'lib/metasploit/framework/parsed_options/base.rb', line 35

def positional
  @positional
end

Instance Method Details

#configure(application) ⇒ void

This method returns an undefined value.

Translates #options to the ‘application`’s config

Parameters:

  • application (Rails::Application)


55
56
57
# File 'lib/metasploit/framework/parsed_options/base.rb', line 55

def configure(application)
  application.config['config/database'] = options.database.config
end

#environment!void

This method returns an undefined value.

Sets the ‘RAILS_ENV` environment variable.

  1. If the -E/–environment option is given, then its value is used.

  2. The default value, ‘production’, is used.



65
66
67
68
69
70
71
# File 'lib/metasploit/framework/parsed_options/base.rb', line 65

def environment!
  if defined?(Rails) && Rails.instance_variable_defined?(:@_env) && Rails.env != options.environment
    raise "#{self.class}##{__method__} called too late to set RAILS_ENV: Rails.env already memoized"
  end

  ENV['RAILS_ENV'] = options.environment
end

#optionsActiveSupport::OrderedOptions

Options parsed from

Returns:

  • (ActiveSupport::OrderedOptions)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/metasploit/framework/parsed_options/base.rb', line 76

def options
  unless @options
    options = ActiveSupport::OrderedOptions.new

    options.database = ActiveSupport::OrderedOptions.new

    options.database.config = Metasploit::Framework::Database.configurations_pathname.try(:to_path)
    options.database.disable = false
    options.database.migrations_paths = []

    # If RAILS_ENV is set, then it will be used, but if RAILS_ENV is set and the --environment option is given, then
    # --environment value will be used to reset ENV[RAILS_ENV].
    options.environment = ENV['RAILS_ENV'] || DEFAULT_ENVIRONMENT

    options.framework = ActiveSupport::OrderedOptions.new
    options.framework.config = nil

    options.modules = ActiveSupport::OrderedOptions.new
    options.modules.defer_loads = false
    options.modules.path = nil

    @options = options
  end

  @options
end