Module: Msf::Module::Options

Included in:
Msf::Module
Defined in:
lib/msf/core/module/options.rb

Overview

Register, deregister, and validate #options.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/msf/core/module/options.rb', line 9

def options
  @options
end

Instance Method Details

#deregister_option_group(name:) ⇒ Object (protected)

De-registers an option group by name

Parameters:

  • name (String)

    Name for the group



95
96
97
# File 'lib/msf/core/module/options.rb', line 95

def deregister_option_group(name:)
  options.remove_group(name)
end

#deregister_options(*names) ⇒ Object (protected)

Removes the supplied options from the module’s option container and data store.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/msf/core/module/options.rb', line 30

def deregister_options(*names)
  names.each { |name|
    real_name = self.datastore.find_key_case(name)
    if self.datastore.is_a?(Msf::DataStoreWithFallbacks)
      self.datastore.remove_option(name)
    else
      self.datastore.delete(name)
    end
    self.options.remove_option(name)
    if real_name != name
      self.options.remove_option(real_name)
    end
  }
end

#register_advanced_options(options, owner = self.class) ⇒ Object (protected)

Register advanced options with a specific owning class.



50
51
52
53
# File 'lib/msf/core/module/options.rb', line 50

def register_advanced_options(options, owner = self.class)
  self.options.add_advanced_options(options, owner)
  import_defaults(false)
end

#register_evasion_options(options, owner = self.class) ⇒ Object (protected)

Register evasion options with a specific owning class.



58
59
60
61
# File 'lib/msf/core/module/options.rb', line 58

def register_evasion_options(options, owner = self.class)
  self.options.add_evasion_options(options, owner)
  import_defaults(false)
end

#register_option_group(name:, description:, option_names: [], required_options: [], merge: true) ⇒ Object (protected)

Registers a new option group, merging options by default

Parameters:

  • name (String)

    Name for the group

  • description (String)

    Description of the group

  • option_names (Array<String>) (defaults to: [])

    List of datastore option names

  • required_options (Array<String>) (defaults to: [])

    List of required datastore option names

  • merge (Boolean) (defaults to: true)

    whether to merge or overwrite the groups option names



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/msf/core/module/options.rb', line 78

def register_option_group(name:, description:, option_names: [], required_options: [], merge: true)
  existing_group = options.groups[name]
  if merge && existing_group
    existing_group.description = description
    existing_group.add_options(option_names)
  else
    option_group = Msf::OptionGroup.new(name: name,
                                        description: description,
                                        option_names: option_names,
                                        required_options: required_options)
    options.add_group(option_group)
  end
end

#register_options(options, owner = self.class) ⇒ Object (protected)

Register options with a specific owning class.



66
67
68
69
# File 'lib/msf/core/module/options.rb', line 66

def register_options(options, owner = self.class)
  self.options.add_options(options, owner)
  import_defaults(false)
end

#validateObject

This method ensures that the options associated with this module all have valid values according to each required option in the option container.



20
21
22
# File 'lib/msf/core/module/options.rb', line 20

def validate
  self.options.validate(self.datastore)
end