Module: Msf::Module::DataStore

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#datastoreObject

Returns the value of attribute datastore.



10
11
12
# File 'lib/msf/core/module/data_store.rb', line 10

def datastore
  @datastore
end

Instance Method Details

#import_defaults(clear_datastore = true) ⇒ Object

Imports default options into the module’s datastore, optionally clearing all of the values currently set in the datastore.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/msf/core/module/data_store.rb', line 16

def import_defaults(clear_datastore = true)
  # Clear the datastore if the caller asked us to
  self.datastore.clear if clear_datastore

  self.datastore.import_options(self.options, 'self', true)

  # If there are default options, import their values into the datastore
  if (module_info['DefaultOptions'])
    if datastore.is_a?(Msf::DataStoreWithFallbacks)
      self.datastore.import_defaults_from_hash(module_info['DefaultOptions'], imported_by: 'import_defaults')
    else
      self.datastore.import_options_from_hash(module_info['DefaultOptions'], true, 'self')
    end
  end

  # Preference the defaults for the currently set target
  import_target_defaults
end

#import_target_defaultsObject

Import the target’s DefaultOptions hash into the datastore.



38
39
40
41
42
43
44
45
46
# File 'lib/msf/core/module/data_store.rb', line 38

def import_target_defaults
  return unless defined?(targets) && targets && target && target.default_options

  if self.datastore.is_a?(Msf::ModuleDataStoreWithFallbacks)
    datastore.import_defaults_from_hash(target.default_options, imported_by: 'import_target_defaults')
  else
    datastore.import_options_from_hash(target.default_options, true, 'self')
  end
end

#share_datastore(ds) ⇒ Object

Overrides the class’ own datastore with the one supplied. This is used to allow modules to share datastores, such as a payload sharing an exploit module’s datastore.



53
54
55
56
# File 'lib/msf/core/module/data_store.rb', line 53

def share_datastore(ds)
  self.datastore = ds
  self.datastore.import_options(self.options)
end