Skip to content

Commit

Permalink
Improve specs coverage of Msf::RPC::RPC_Session
Browse files Browse the repository at this point in the history
  • Loading branch information
ekalinichev-r7 committed Mar 25, 2024
1 parent c548433 commit 39de2da
Show file tree
Hide file tree
Showing 2 changed files with 263 additions and 72 deletions.
19 changes: 8 additions & 11 deletions lib/msf/core/rpc/v10/rpc_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ def rpc_interactive_write(sid, data)
session.channels.each_value do |ch|
interacting ||= ch.respond_to?('interacting') && ch.interacting
end
else
interacting = session.interacting
end

if interacting
Expand Down Expand Up @@ -534,11 +536,6 @@ def rpc_compatible_modules( sid)
smb
].freeze

SHELL_OPERATION_SESSIONS = %w[
shell
powershell
]

def _find_module(_mtype, mname)
mod = framework.modules.create(mname)
error(500, 'Invalid Module') if mod.nil?
Expand All @@ -552,16 +549,16 @@ def _valid_session(sid, operation_type)

case operation_type
when 'ring'
error(500, "Session #{s.type} does not support ring operations") unless s.respond_to?(:ring)
error(500, "Session of #{session.type} type does not support ring operations") unless session.respond_to?(:ring)
when 'meterpreter'
error(500, 'Invalid session type') unless s.type == 'meterpreter'
error(500, 'Invalid session type') unless session.type == 'meterpreter'
when 'interactive'
unless INTERACTIVE_OPERATION_SESSIONS.include?(s.type)
error(500, "Session doesn't support interactive operations")
unless INTERACTIVE_OPERATION_SESSIONS.include?(session.type)
error(500, "Session of #{session.type} type doesn't support interactive operations")
end
when 'shell'
unless SHELL_OPERATION_SESSIONS.include?(s.type)
error(500, "Session doesn't support command shell operations")
if INTERACTIVE_OPERATION_SESSIONS.include?(session.type)
error(500, "Use `interactive_read` and `interactive_write` for sessions of #{session.type} type")
end
else
error(500, 'Invalid operation type')
Expand Down
Loading

0 comments on commit 39de2da

Please sign in to comment.