Class: Msf::ModuleDataStoreWithFallbacks
- Inherits:
-
DataStoreWithFallbacks
- Object
- DataStoreWithFallbacks
- Msf::ModuleDataStoreWithFallbacks
- Defined in:
- lib/msf/core/module_data_store_with_fallbacks.rb
Overview
DataStore wrapper for modules that will attempt to back values against the framework’s datastore if they aren’t found in the module’s datastore. This is done to simulate global data store values.
Constant Summary
Constants inherited from DataStoreWithFallbacks
DataStoreWithFallbacks::GLOBAL_KEYS
Instance Attribute Summary
Attributes inherited from DataStoreWithFallbacks
#aliases, #defaults, #options, #user_defined
Instance Method Summary collapse
-
#copy ⇒ Msf::DataStore
Return a copy of this datastore.
-
#initialize(m) ⇒ ModuleDataStoreWithFallbacks
constructor
A new instance of ModuleDataStoreWithFallbacks.
-
#search_for(key) ⇒ DataStoreSearchResult
Search for a value within the current datastore, taking into consideration any registered aliases, fallbacks, etc.
-
#search_framework_datastore(key) ⇒ DataStoreSearchResult
protected
Search the framework datastore.
- #search_result(result, value, fallback_key: nil) ⇒ Object protected
Methods inherited from DataStoreWithFallbacks
#[], #[]=, #clear, #copy_state, #default?, #delete, #each, #each_key, #find_key_case, #from_file, #import_defaults_from_hash, #import_option, #import_options, #import_options_from_hash, #import_options_from_s, #key?, #key_error_for, #keys, #length, #merge, #merge!, #remove_option, #reverse_merge!, #store, #to_external_message_h, #to_file, #to_h, #to_s, #unset, #update_value
Constructor Details
#initialize(m) ⇒ ModuleDataStoreWithFallbacks
Returns a new instance of ModuleDataStoreWithFallbacks.
14 15 16 17 18 |
# File 'lib/msf/core/module_data_store_with_fallbacks.rb', line 14 def initialize(m) super() @_module = m end |
Instance Method Details
#copy ⇒ Msf::DataStore
Return a copy of this datastore. Only string values will be duplicated, other values will share the same reference
24 25 26 27 28 |
# File 'lib/msf/core/module_data_store_with_fallbacks.rb', line 24 def copy new_instance = self.class.new(@_module) new_instance.copy_state(self) new_instance end |
#search_for(key) ⇒ DataStoreSearchResult
Search for a value within the current datastore, taking into consideration any registered aliases, fallbacks, etc. If a value is not present in the current datastore, the global parent store will be referenced instead
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/msf/core/module_data_store_with_fallbacks.rb', line 35 def search_for(key) k = find_key_case(key) return search_result(:user_defined, @user_defined[k]) if @user_defined.key?(k) # Preference globally set values over a module's option default framework_datastore_search = search_framework_datastore(key) return framework_datastore_search if framework_datastore_search.found? && !framework_datastore_search.default? option = @options.fetch(k) { @options.find { |option_name, _option| option_name.casecmp?(k) }&.last } if option # If the key isn't present - check any additional fallbacks that have been registered with the option. # i.e. handling the scenario of SMBUser not being explicitly set, but the option has registered a more # generic 'Username' fallback option.fallbacks.each do |fallback| fallback_search = search_for(fallback) if fallback_search.found? return search_result(:option_fallback, fallback_search.value, fallback_key: fallback) end end end # Checking for imported default values, ignoring case again TODO: add Alias test for this imported_default_match = @defaults.find { |default_key, _default_value| default_key.casecmp?(k) } return search_result(:imported_default, imported_default_match.last) if imported_default_match return search_result(:option_default, option.default) if option search_framework_datastore(k) end |
#search_framework_datastore(key) ⇒ DataStoreSearchResult (protected)
Search the framework datastore
70 71 72 73 74 |
# File 'lib/msf/core/module_data_store_with_fallbacks.rb', line 70 def search_framework_datastore(key) return search_result(:not_found, nil) if @_module&.framework.nil? @_module.framework.datastore.search_for(key) end |
#search_result(result, value, fallback_key: nil) ⇒ Object (protected)
76 77 78 |
# File 'lib/msf/core/module_data_store_with_fallbacks.rb', line 76 def search_result(result, value, fallback_key: nil) DataStoreSearchResult.new(result, value, namespace: :module_data_store, fallback_key: fallback_key) end |