Class: Msf::Modules::Metadata::Cache

Inherits:
Object
  • Object
show all
Includes:
Maps, Search, Stats, Store, Singleton
Defined in:
lib/msf/core/modules/metadata/cache.rb

Constant Summary

Constants included from Store

Store::BaseMetaDataFile, Store::UserMetaDataFile

Constants included from Search

Search::MODULE_TYPE_SHORTHANDS, Search::VALID_PARAMS

Instance Attribute Summary

Attributes included from Stats

#module_counts

Instance Method Summary collapse

Methods included from Stats

#update_stats

Methods included from Maps

#all_exploit_maps

Methods included from Store

#init_store

Methods included from Search

#find, parse_search_string

Instance Method Details

#get_metadataObject

Returns the module data cache, but first ensures all the metadata is loaded



31
32
33
34
35
36
# File 'lib/msf/core/modules/metadata/cache.rb', line 31

def 
  @mutex.synchronize {
    wait_for_load
    @module_metadata_cache.values
  }
end

#get_module_reference(type:, reference_name:) ⇒ Object



38
39
40
41
42
43
# File 'lib/msf/core/modules/metadata/cache.rb', line 38

def get_module_reference(type:, reference_name:)
  @mutex.synchronize do
    wait_for_load
    @module_metadata_cache["#{type}_#{reference_name}"]
  end
end

#module_metadata(type) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/msf/core/modules/metadata/cache.rb', line 89

def (type)
  @mutex.synchronize do
    wait_for_load
    # TODO: Should probably figure out a way to cache this
    @module_metadata_cache.filter_map { |_, | [.ref_name, ] if .type == type }.to_h
  end
end

#refresh_metadata(module_sets) ⇒ Object

Checks for modules loaded that are not a part of the cache and updates the underlying store if there are changes.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/msf/core/modules/metadata/cache.rb', line 48

def (module_sets)
  has_changes = false
  @mutex.synchronize {
    unchanged_module_references = get_unchanged_module_references
    module_sets.each do |mt|
      unchanged_reference_name_set = unchanged_module_references[mt[0]]

      mt[1].keys.sort.each do |mn|
        next if unchanged_reference_name_set.include? mn

        begin
          module_instance = mt[1].create(mn, cache_type: Msf::ModuleManager::Cache::MEMORY)
        rescue Exception => e
          elog "Unable to create module: #{mn}. #{e.message}"
        end

        unless module_instance
          wlog "Removing invalid module reference from cache: #{mn}"
          existed = remove_from_cache(mn)
          if existed
            has_changes = true
          end
          next
        end

        begin
          (module_instance)
          has_changes = true
        rescue Exception => e
          elog("Error updating module details for #{module_instance.fullname}", error: e)
        end
      end
    end
  }
  if has_changes
    update_store
    clear_maps
    update_stats
  end
end

#refresh_metadata_instance(module_instance) ⇒ Object

Refreshes cached module metadata as well as updating the store



20
21
22
23
24
25
26
# File 'lib/msf/core/modules/metadata/cache.rb', line 20

def (module_instance)
  @mutex.synchronize {
    dlog "Refreshing #{module_instance.refname} of type: #{module_instance.type}"
    (module_instance)
    update_store
  }
end