From 792708c07b1fd622fd48010c329d0a9540313bc8 Mon Sep 17 00:00:00 2001 From: Dean Welch Date: Wed, 7 Feb 2024 15:08:47 +0000 Subject: [PATCH] Remove all references to `Msf::SymbolicModule` --- lib/msf/core/module_manager/cache.rb | 4 +- lib/msf/core/module_set.rb | 14 +-- lib/msf/core/payload_set.rb | 3 +- spec/lib/msf/core/module_set_spec.rb | 90 +------------------ .../update_all_module_details_refresh.rb | 2 +- .../examples/msf/module_manager/cache.rb | 4 +- 6 files changed, 12 insertions(+), 105 deletions(-) diff --git a/lib/msf/core/module_manager/cache.rb b/lib/msf/core/module_manager/cache.rb index 8021c64332f5..a2c412f46c29 100644 --- a/lib/msf/core/module_manager/cache.rb +++ b/lib/msf/core/module_manager/cache.rb @@ -154,7 +154,7 @@ def refresh_cache_from_database(allowed_paths=[""]) # Return a module info from Msf::Modules::Metadata::Obj. # - # @note Also sets module_set(module_type)[module_reference_name] to Msf::SymbolicModule if it is not already set. + # @note Also sets module_set(module_type)[module_reference_name] to nil if it is not already set. # # @return [Hash{String => Hash{Symbol => Object}}] Maps path (Mdm::Module::Detail#file) to module information. Module # information is a Hash derived from Mdm::Module::Detail. It includes :modification_time, :parent_path, :type, @@ -193,7 +193,7 @@ def module_info_by_path_from_database!(allowed_paths=[""]) # which would potentially call {Msf::ModuleSet#create}. next unless typed_module_set unless typed_module_set.has_key?(reference_name) - typed_module_set[reference_name] = Msf::SymbolicModule + typed_module_set[reference_name] = nil end end diff --git a/lib/msf/core/module_set.rb b/lib/msf/core/module_set.rb index bab4ec56c258..969b6560bc8e 100644 --- a/lib/msf/core/module_set.rb +++ b/lib/msf/core/module_set.rb @@ -1,12 +1,6 @@ # -*- coding: binary -*- require 'pathname' -# -# Define used for a place-holder module that is used to indicate that the -# module has not yet been demand-loaded. Soon to go away. -# -Msf::SymbolicModule = '__SYMBOLIC__' - ### # # A module set contains zero or more named module classes of an arbitrary @@ -23,7 +17,7 @@ class Msf::ModuleSet < Hash # @return [Msf::Module] Class of the of the Msf::Module with the given reference name def [](name) module_class = super - if module_class == Msf::SymbolicModule || module_class.nil? + if module_class.nil? load_module_class(name) end @@ -39,7 +33,7 @@ def create(reference_name, cache_type: Msf::ModuleManager::Cache::FILESYSTEM) klass = load_module_class(reference_name, cache_type: cache_type) instance = nil # If the klass is valid for this reference_name, try to create it - unless klass.nil? or klass == Msf::SymbolicModule + unless klass.nil? instance = klass.new end @@ -180,7 +174,7 @@ def add_module(klass, reference_name, info = {}) # don't want to trigger a create, so use fetch cached_module = self.fetch(reference_name, nil) - if (cached_module and cached_module != Msf::SymbolicModule) + if cached_module ambiguous_module_reference_name_set.add(reference_name) # TODO this isn't terribly helpful since the refnames will always match, that's why they are ambiguous. @@ -287,7 +281,7 @@ def load_module_class(reference_name, cache_type: Msf::ModuleManager::Cache::FIL klass = fetch(reference_name, nil) # If there is no module associated with this class, then try to demand load it. - if klass.nil? || klass == Msf::SymbolicModule + if klass.nil? framework.modules.load_cached_module(module_type, reference_name, cache_type: cache_type) klass = fetch(reference_name, nil) end diff --git a/lib/msf/core/payload_set.rb b/lib/msf/core/payload_set.rb index aab0c93b2a36..45ce6124072e 100644 --- a/lib/msf/core/payload_set.rb +++ b/lib/msf/core/payload_set.rb @@ -119,8 +119,7 @@ def recalculate # Blow away anything that was cached but didn't exist during the # recalculation - self.delete_if do |k, v| - next if v == SymbolicModule + self.delete_if do |k, _v| !!(old_keys.include?(k) and not new_keys.include?(k)) end diff --git a/spec/lib/msf/core/module_set_spec.rb b/spec/lib/msf/core/module_set_spec.rb index 0820dc737c7f..60490dc8f60c 100644 --- a/spec/lib/msf/core/module_set_spec.rb +++ b/spec/lib/msf/core/module_set_spec.rb @@ -34,93 +34,7 @@ } end - context 'with Msf::SymbolicModule' do - before(:example) do - module_set['a'] = Msf::SymbolicModule - module_set['b'] = Msf::SymbolicModule - module_set['c'] = Msf::SymbolicModule - end - - describe '#create' do - # - # lets - # - - let(:b_class) do - Class.new - end - - let(:c_class) do - Class.new - end - - context 'returns nil' do - before(:example) do - allow(module_metadata_a).to receive(:rank).and_return(nil) - allow(module_metadata_b).to receive(:rank).and_return(Msf::AverageRanking) - allow(module_metadata_c).to receive(:rank).and_return(Msf::GoodRanking) - allow(Msf::Modules::Metadata::Cache.instance).to receive(:module_metadata).with(anything).and_return(module_metadata) - end - - specify do - expect do - rank_modules - end.not_to raise_error - end - - it 'is ranked as Normal' do - expect(rank_modules).to eq( - [ - ['c', module_metadata_c], - ['a', module_metadata_a], - ['b', module_metadata_b] - ] - ) - end - end - - context 'does not return nil' do - # - # lets - # - - let(:a_class) do - Class.new - end - - # - # Callbacks - # - - before(:example) do - allow(module_set).to receive(:create).with('a').and_return(a_class.new) - allow(module_set).to receive(:create).with('b').and_return(b_class.new) - allow(module_set).to receive(:create).with('c').and_return(c_class.new) - end - - context 'with Rank' do - before(:example) do - allow(module_metadata_a).to receive(:rank).and_return(Msf::LowRanking) - allow(module_metadata_b).to receive(:rank).and_return(Msf::AverageRanking) - allow(module_metadata_c).to receive(:rank).and_return(Msf::GoodRanking) - allow(Msf::Modules::Metadata::Cache.instance).to receive(:module_metadata).with(anything).and_return(module_metadata) - end - - it 'is ranked using Rank' do - expect(rank_modules).to eq( - [ - ['c', module_metadata_c], - ['b', module_metadata_b], - ['a', module_metadata_a] - ] - ) - end - end - end - end - end - - context 'without Msf::SymbolicModule' do + context 'with loaded modules' do # # lets # @@ -229,7 +143,7 @@ context 'when the module set has symbolic modules' do before(:each) do - subject[module_refname] = Msf::SymbolicModule + subject[module_refname] = nil end it 'attempts to create the module' do subject[module_refname] diff --git a/spec/support/shared/examples/msf/db_manager/update_all_module_details_refresh.rb b/spec/support/shared/examples/msf/db_manager/update_all_module_details_refresh.rb index 7f6be57013e7..88a99cb63125 100644 --- a/spec/support/shared/examples/msf/db_manager/update_all_module_details_refresh.rb +++ b/spec/support/shared/examples/msf/db_manager/update_all_module_details_refresh.rb @@ -14,7 +14,7 @@ end before(:example) do - module_set[module_detail.refname] = Msf::SymbolicModule + module_set[module_detail.refname] = nil framework.modules.send(:module_info_by_path)[module_detail.file] = { :parent_path => Metasploit::Framework.root.join('modules').to_path, diff --git a/spec/support/shared/examples/msf/module_manager/cache.rb b/spec/support/shared/examples/msf/module_manager/cache.rb index 8ebf3711ecee..5dafddaa1486 100644 --- a/spec/support/shared/examples/msf/module_manager/cache.rb +++ b/spec/support/shared/examples/msf/module_manager/cache.rb @@ -436,12 +436,12 @@ def module_info_by_path_from_database! end context 'without reference_name' do - it 'should set reference_name value to Msf::SymbolicModule' do + it 'should set reference_name value to nil' do module_info_by_path_from_database! # have to use fetch because [] will trigger de-symbolization and # instantiation. - expect(typed_module_set.fetch(reference_name)).to eq Msf::SymbolicModule + expect(typed_module_set.fetch(reference_name)).to eq nil end end end