Skip to content

Commit bc7cd4b

Browse files
committed
Loop through module sets like super used to do
... since super doesn't exist any more. Also changes to using ModuleSet#[] inside ModuleManager#[] instead of ModuleSet#create to mimic original behavior when ModuleManager was a subclass of ModuleSet.
1 parent d57c24d commit bc7cd4b

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

lib/msf/core/module_manager.rb

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,21 @@ def [](key)
5050
module_set = module_set_by_type[type]
5151

5252
module_reference_name = names.join("/")
53-
module_set.create(module_reference_name)
53+
module_set[module_reference_name]
5454
end
5555

5656
# Creates a module instance using the supplied reference name.
5757
#
58-
# @param [String] name a module reference name. It may optionally be prefixed with a "<type>/", in which case the
59-
# module will be created from the {Msf::ModuleSet} for the given <type>.
58+
# @param name [String] A module reference name. It may optionally
59+
# be prefixed with a "<type>/", in which case the module will be
60+
# created from the {Msf::ModuleSet} for the given <type>.
61+
# Otherwise, we step through all sets until we find one that
62+
# matches.
6063
# @return (see Msf::ModuleSet#create)
6164
def create(name)
6265
# Check to see if it has a module type prefix. If it does,
6366
# try to load it from the specific module set for that type.
64-
names = name.split(File::SEPARATOR)
67+
names = name.split("/")
6568
potential_type_or_directory = names.first
6669

6770
# if first name is a type
@@ -72,20 +75,31 @@ def create(name)
7275
type = TYPE_BY_DIRECTORY[potential_type_or_directory]
7376
end
7477

78+
m = nil
7579
if type
7680
module_set = module_set_by_type[type]
7781

78-
module_reference_name = names[1 .. -1].join(File::SEPARATOR)
79-
module_set.create(module_reference_name)
80-
# Otherwise, just try to load it by name.
82+
# First element in names is the type, so skip it
83+
module_reference_name = names[1 .. -1].join("/")
84+
m = module_set.create(module_reference_name)
8185
else
82-
super
86+
# Then we don't have a type, so we have to step through each set
87+
# to see if we can create this module.
88+
module_set_by_type.each do |_, set|
89+
module_reference_name = names.join("/")
90+
m = set.create(module_reference_name)
91+
break if m
92+
end
8393
end
94+
95+
m
8496
end
8597

8698

87-
# @param framework [Msf::Framework] The framework for which this instance is managing the modules.
88-
# @param [Array<String>] types List of module types to load. Defaults to all module types in {Msf::MODULE_TYPES}.
99+
# @param framework [Msf::Framework] The framework for which this
100+
# instance is managing the modules.
101+
# @param types [Array<String>] List of module types to load.
102+
# Defaults to all module types in {Msf::MODULE_TYPES}.
89103
def initialize(framework, types=Msf::MODULE_TYPES)
90104
#
91105
# defaults

0 commit comments

Comments
 (0)