Module: Msf::ModuleManager::Cache
- Extended by:
- ActiveSupport::Concern
- Included in:
- Msf::ModuleManager
- Defined in:
- lib/msf/core/module_manager/cache.rb
Overview
Concerns the module cache maintained by the Msf::ModuleManager.
Instance Attribute Summary collapse
- #module_info_by_path ⇒ Object protected
Instance Method Summary collapse
-
#cache_empty? ⇒ true, false
Returns whether the cache is empty.
-
#cache_in_memory(class_or_module, options = {}) ⇒ void
Updates the in-memory cache so that Loading#file_changed? will report
false
if the module is loaded again. -
#load_cached_module(type, reference_name) ⇒ false, true
Forces loading of the module with the given type and module reference name from the cache.
-
#module_info_by_path_from_database!(allowed_paths = [""]) ⇒ Hash{String => Hash{Symbol => Object}}
protected
Return a module info from Msf::Modules::Metadata::Obj.
-
#refresh_cache_from_database(allowed_paths = [""]) ⇒ void
Refreshes the in-memory cache from the database cache.
- #refresh_cache_from_module_files(module_class_or_instance = nil) ⇒ Object
Instance Attribute Details
#module_info_by_path ⇒ Object (protected)
139 140 141 |
# File 'lib/msf/core/module_manager/cache.rb', line 139 def module_info_by_path @module_info_by_path end |
Instance Method Details
#cache_empty? ⇒ true, false
Returns whether the cache is empty
15 16 17 |
# File 'lib/msf/core/module_manager/cache.rb', line 15 def cache_empty? module_info_by_path.empty? end |
#cache_in_memory(class_or_module, options = {}) ⇒ void
path, reference_name, and type must be passed as options because when class_or_module
is a payload Module, those attributes will either not be set or not exist on the module.
This method returns an undefined value.
Updates the in-memory cache so that Loading#file_changed? will report false
if the module is loaded again.
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 63 64 65 66 |
# File 'lib/msf/core/module_manager/cache.rb', line 37 def cache_in_memory(class_or_module, ={}) .assert_valid_keys(:path, :reference_name, :type) path = .fetch(:path) begin modification_time = File.mtime(path) rescue Errno::ENOENT => error log_lines = [] log_lines << "Could not find the modification of time of #{path}:" log_lines << error.class.to_s log_lines << error.to_s log_lines << "Call stack:" log_lines += error.backtrace = log_lines.join("\n") elog() else parent_path = class_or_module.module_parent.parent_path reference_name = .fetch(:reference_name) type = .fetch(:type) module_info_by_path[path] = { :modification_time => modification_time, :parent_path => parent_path, :reference_name => reference_name, :type => type } end end |
#load_cached_module(type, reference_name) ⇒ false, true
Forces loading of the module with the given type and module reference name from the cache.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/msf/core/module_manager/cache.rb', line 74 def load_cached_module(type, reference_name) loaded = false module_info = self.module_info_by_path.values.find { |inner_info| inner_info[:type] == type and inner_info[:reference_name] == reference_name } if module_info parent_path = module_info[:parent_path] # XXX borked loaders.each do |loader| if loader.loadable_module?(parent_path, type, reference_name) type = module_info[:type] reference_name = module_info[:reference_name] loaded = loader.load_module(parent_path, type, reference_name, :force => true) break if loaded end end end loaded end |
#module_info_by_path_from_database!(allowed_paths = [""]) ⇒ Hash{String => Hash{Symbol => Object}} (protected)
Also sets module_set(module_type) to Msf::SymbolicModule if it is not already set.
Return a module info from Msf::Modules::Metadata::Obj.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/msf/core/module_manager/cache.rb', line 148 def module_info_by_path_from_database!(allowed_paths=[""]) self.module_info_by_path = {} allowed_paths = allowed_paths.map{|x| x + "/"} = Msf::Modules::Metadata::Cache.instance. .each do || path = .path type = .type reference_name = .ref_name # Skip cached modules that are not in our allowed load paths next if allowed_paths.select{|x| path.index(x) == 0}.empty? # The load path is assumed to be the next level above the type directory type_dir = File.join('', Mdm::Module::Detail::DIRECTORY_BY_TYPE[type], '') parent_path = path.split(type_dir)[0..-2].join(type_dir) # TODO: rewrite module_info_by_path[path] = { :reference_name => reference_name, :type => type, :parent_path => parent_path, :modification_time => .mod_time } .aliases.each do |a| self.aliases[a] = .fullname end self.inv_aliases[.fullname] = .aliases unless .aliases.empty? typed_module_set = module_set(type) # Don't want to trigger as {Msf::ModuleSet#create} so check for # key instead of using ||= which would call {Msf::ModuleSet#[]} # which would potentially call {Msf::ModuleSet#create}. if typed_module_set unless typed_module_set.has_key?(reference_name) typed_module_set[reference_name] = Msf::SymbolicModule end end end self.module_info_by_path end |
#refresh_cache_from_database(allowed_paths = [""]) ⇒ void
This method returns an undefined value.
Refreshes the in-memory cache from the database cache.
131 132 133 |
# File 'lib/msf/core/module_manager/cache.rb', line 131 def refresh_cache_from_database(allowed_paths=[""]) self.module_info_by_path_from_database!(allowed_paths) end |
#refresh_cache_from_module_files ⇒ void #refresh_cache_from_module_files(module_class_or_instance) ⇒ void
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/msf/core/module_manager/cache.rb', line 109 def refresh_cache_from_module_files(module_class_or_instance = nil) if module_class_or_instance Msf::Modules::Metadata::Cache.instance.(module_class_or_instance) else module_sets = [ ['exploit', @framework.exploits], ['auxiliary', @framework.auxiliary], ['post', @framework.post], ['payload', @framework.payloads], ['encoder', @framework.encoders], ['nop', @framework.nops], ['evasion', @framework.evasion] ] Msf::Modules::Metadata::Cache.instance.(module_sets) end refresh_cache_from_database(self.module_paths) end |