Skip to content

Commit b1b8f86

Browse files
author
HD Moore
committed
Lands rapid7#5270, improvements to Msf::ModuleSet
2 parents 657ae2c + 9386d1c commit b1b8f86

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

lib/msf/core/module_set.rb

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def create(reference_name)
5757
# Notify any general subscribers of the creation event
5858
if instance
5959
self.framework.events.on_module_created(instance)
60+
else
61+
self.delete(reference_name)
6062
end
6163

6264
return instance
@@ -112,9 +114,7 @@ def each_module_filter(opts, name, entry)
112114
def each_module_ranked(opts = {}, &block)
113115
demand_load_modules
114116

115-
self.mod_ranked = rank_modules
116-
117-
each_module_list(mod_ranked, opts, &block)
117+
each_module_list(rank_modules, opts, &block)
118118
end
119119

120120
# Forces all modules in this set to be loaded.
@@ -138,7 +138,6 @@ def initialize(type = nil)
138138
self.architectures_by_module = {}
139139
self.platforms_by_module = {}
140140
self.mod_sorted = nil
141-
self.mod_ranked = nil
142141
self.mod_extensions = []
143142

144143
#
@@ -292,11 +291,6 @@ def each_module_list(ary, opts, &block)
292291
#
293292
# @return [Hash{Class => Array<String>}] Maps module class to Array of platform Strings.
294293
attr_accessor :platforms_by_module
295-
# @!attribute [rw] mod_ranked
296-
# Array of module names and module classes ordered by their Rank with the higher Ranks first.
297-
#
298-
# @return (see #rank_modules)
299-
attr_accessor :mod_ranked
300294
# @!attribute [rw] mod_sorted
301295
# Array of module names and module classes ordered by their names.
302296
#
@@ -315,14 +309,7 @@ def each_module_list(ary, opts, &block)
315309
# @return [Array<Array<String, Class>>] Array of arrays where the inner array is a pair of the module reference name
316310
# and the module class.
317311
def rank_modules
318-
self.mod_ranked = self.sort { |a_pair, b_pair|
319-
a_rank = module_rank(*a_pair)
320-
b_rank = module_rank(*b_pair)
321-
322-
# Compare their relevant rankings. Since we want highest to lowest,
323-
# we compare b_rank to a_rank in terms of higher/lower precedence
324-
b_rank <=> a_rank
325-
}
312+
self.sort_by { |pair| module_rank(*pair) }.reverse!
326313
end
327314

328315
# Retrieves the rank from a loaded, not-yet-loaded, or unloadable Metasploit Module.

0 commit comments

Comments
 (0)