Skip to content

Commit

Permalink
Use module cache for aux modules in RPC suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanusz-r7 committed Mar 7, 2024
1 parent 5881b9d commit d9ebfbc
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/msf/core/rpc/v10/rpc_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -465,20 +465,22 @@ def rpc_meterpreter_directory_separator(sid)
# @example Here's how you would use this from the client:
# rpc.call('session.compatible_modules', 3)
def rpc_compatible_modules( sid)
ret = []

mtypes = ['post', 'auxiliary']
mtypes.each do |mtype|
names = self.framework.send(mtype.to_sym).module_refnames.map{ |x| "#{mtype}/#{x}" }
names.each do |mname|
m = _find_module(mtype, mname)
if m.respond_to?(:session_compatible?) && m.session_compatible?(sid)
ret << m.fullname
end
end
# New cached module searching logic for aux modules
session_type = self.framework.sessions[sid].type
search_params = { 'session_type' => [[session_type], []], 'type' => [['auxiliary'], []] }
cached_aux_modules = Msf::Modules::Metadata::Cache.instance.find(search_params)
aux_module_fullnames = cached_aux_modules.each.map(&:fullname) || []

post_modules = []
mtype = "post"
names = self.framework.post.module_refnames.map{ |x| "post/#{x}" }
names.each do |mname|
m = _find_module(mtype, mname)
next if not m.session_compatible?(sid)
post_modules << m.fullname
end

{ "modules" => ret }
{ "modules" => aux_module_fullnames + post_modules }
end

private
Expand Down

0 comments on commit d9ebfbc

Please sign in to comment.