Skip to content

Commit

Permalink
Fixes issue with module fullname matching as substring of other modules
Browse files Browse the repository at this point in the history
  • Loading branch information
cgranleese-r7 committed Sep 6, 2023
1 parent 6dc7ba1 commit e892a1e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/msf/ui/console/command_dispatcher/modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,22 @@ def show_favorites # :nodoc:
end

# find cache module instance and add it to @module_search_results
@module_search_results = Msf::Modules::Metadata::Cache.instance.find('fullname' => [saved_favs, []]).sort_by(&:fullname)
@module_search_results = Msf::Modules::Metadata::Cache.instance.find('fullname' => [saved_favs, []])

# This scenario is for when a module fullname is a substring of other module fullnames
# Example, searching for the payload/windows/meterpreter/reverse_tcp module can result in matches for:
# - windows/meterpreter/reverse_tcp_allports
# - windows/meterpreter/reverse_tcp_dns
# So if @module_search_results is greater than the amount of fav_modules, we need to filter the results to be more accurate
if fav_modules.length < @module_search_results.length
filtered_results = []
fav_modules.each do |fullname, _mod_obj|
filtered_results << @module_search_results.select do |search_result|
search_result.fullname == fullname
end
end
@module_search_results = filtered_results.flatten.sort_by(&:fullname)
end

show_module_metadata('Favorites', fav_modules)
print_module_search_results_usage
Expand Down

0 comments on commit e892a1e

Please sign in to comment.