Module: Rex::Post::SMB::Ui::Console::CommandDispatcher

Includes:
Msf::Ui::Console::CommandDispatcher::Session
Included in:
Core, Shares
Defined in:
lib/rex/post/smb/ui/console/command_dispatcher.rb

Overview

Base class for all command dispatchers within the SMB console user interface.

Defined Under Namespace

Classes: Core, Shares

Instance Attribute Summary

Attributes included from Ui::Text::DispatcherShell::CommandDispatcher

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from Msf::Ui::Console::CommandDispatcher::Session

#cmd_background, #cmd_background_help, #cmd_exit, #cmd_irb, #cmd_irb_help, #cmd_irb_tabs, #cmd_pry, #cmd_pry_help, #cmd_resource, #cmd_resource_help, #cmd_resource_tabs, #cmd_sessions, #cmd_sessions_help, #commands

Methods included from Ui::Text::DispatcherShell::CommandDispatcher

#cmd_help, #cmd_help_help, #cmd_help_tabs, #commands, #deprecated_cmd, #deprecated_commands, #deprecated_help, #help_to_s, included, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #tab_complete_directory, #tab_complete_filenames, #tab_complete_generic, #tab_complete_source_address, #update_prompt

Instance Method Details

#active_shareRubySMB::SMB2::Tree

Returns the active share

Returns:

  • (RubySMB::SMB2::Tree)


60
61
62
63
# File 'lib/rex/post/smb/ui/console/command_dispatcher.rb', line 60

def active_share
  console = shell
  console.active_share
end

#clientRubySMB::Client

Returns the smb client context.

Returns:

  • (RubySMB::Client)


34
35
36
37
# File 'lib/rex/post/smb/ui/console/command_dispatcher.rb', line 34

def client
  console = shell
  console.client
end

#docs_dirObject

Return the subdir of the `documentation/` directory that should be used to find usage documentation



90
91
92
# File 'lib/rex/post/smb/ui/console/command_dispatcher.rb', line 90

def docs_dir
  File.join(super, 'smb_session')
end

#filter_commands(all, reqs) ⇒ Object

Returns the commands that meet the requirements



68
69
70
71
72
73
74
75
# File 'lib/rex/post/smb/ui/console/command_dispatcher.rb', line 68

def filter_commands(all, reqs)
  all.delete_if do |cmd, _desc|
    if reqs[cmd]&.any? { |req| !client.commands.include?(req) }
      @filtered_commands << cmd
      true
    end
  end
end

#initialize(console) ⇒ Object

Initializes an instance of the core command set using the supplied session and client for interactivity.

Parameters:



24
25
26
27
28
# File 'lib/rex/post/smb/ui/console/command_dispatcher.rb', line 24

def initialize(console)
  super
  @msf_loaded = nil
  @filtered_commands = []
end

#log_error(msg) ⇒ Object

Log that an error occurred.



111
112
113
114
115
116
117
# File 'lib/rex/post/smb/ui/console/command_dispatcher.rb', line 111

def log_error(msg)
  print_error(msg)

  elog(msg, 'smb')

  dlog("Call stack:\n#{$ERROR_POSITION.join("\n")}", 'smb')
end

#msf_loaded?Boolean

Returns true if the client has a framework object.

Used for firing framework session events

Returns:

  • (Boolean)


99
100
101
102
103
104
105
106
# File 'lib/rex/post/smb/ui/console/command_dispatcher.rb', line 99

def msf_loaded?
  return @msf_loaded unless @msf_loaded.nil?

  # if we get here we must not have initialized yet

  @msf_loaded = !session.framework.nil?
  @msf_loaded
end

#sessionMsf::Sessions::SMB

Returns the smb session context.

Returns:



51
52
53
54
# File 'lib/rex/post/smb/ui/console/command_dispatcher.rb', line 51

def session
  console = shell
  console.session
end

#simple_clientRex::Proto::SMB::SimpleClient

Returns the smb simple client.



43
44
45
# File 'lib/rex/post/smb/ui/console/command_dispatcher.rb', line 43

def simple_client
  shell.simple_client
end

#unknown_command(cmd, line) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/rex/post/smb/ui/console/command_dispatcher.rb', line 77

def unknown_command(cmd, line)
  if @filtered_commands.include?(cmd)
    print_error("The \"#{cmd}\" command is not supported by this session type (#{session.session_type})")
    return :handled
  end

  super
end