Module: Msf::Ui::Console::CommandDispatcher

Includes:
Rex::Ui::Text::DispatcherShell::CommandDispatcher
Included in:
Plugin::Aggregator::AggregatorCommandDispatcher, Plugin::Alias::AliasCommandDispatcher, Plugin::BeSECURE::BeSECURECommandDispatcher, Plugin::Beholder::BeholderCommandDispatcher, Plugin::Capture::ConsoleCommandDispatcher, Plugin::CredCollect::CredCollectCommandDispatcher, Plugin::FFAutoRegen::FFAutoRegenCommandDispatcher, Plugin::FuzzyUse::ConsoleCommandDispatcher, Plugin::Lab::LabCommandDispatcher, Plugin::Nessus::ConsoleCommandDispatcher, Plugin::Nexpose::NexposeCommandDispatcher, Plugin::OpenVAS::OpenVASCommandDispatcher, Plugin::PcapLog::PcapLogDispatcher, Plugin::Requests::ConsoleCommandDispatcher, Plugin::Sample::ConsoleCommandDispatcher, Plugin::SessionNotifier::SessionNotifierCommandDispatcher, Plugin::Sqlmap::SqlmapCommandDispatcher, Plugin::ThreadTest::ConsoleCommandDispatcher, Plugin::TokenAdduser::TokenCommandDispatcher, Plugin::TokenHunter::TokenCommandDispatcher, Plugin::Wiki::WikiCommandDispatcher, Plugin::Wmap::WmapCommandDispatcher, Core, Creds, DNS, Db, Developer, Jobs, Modules, Resource, ModuleCommandDispatcher
Defined in:
lib/msf/ui/console/command_dispatcher.rb,
lib/msf/ui/console/command_dispatcher/db.rb,
lib/msf/ui/console/command_dispatcher/dns.rb,
lib/msf/ui/console/command_dispatcher/nop.rb,
lib/msf/ui/console/command_dispatcher/core.rb,
lib/msf/ui/console/command_dispatcher/jobs.rb,
lib/msf/ui/console/command_dispatcher/post.rb,
lib/msf/ui/console/command_dispatcher/creds.rb,
lib/msf/ui/console/command_dispatcher/common.rb,
lib/msf/ui/console/command_dispatcher/encoder.rb,
lib/msf/ui/console/command_dispatcher/evasion.rb,
lib/msf/ui/console/command_dispatcher/exploit.rb,
lib/msf/ui/console/command_dispatcher/modules.rb,
lib/msf/ui/console/command_dispatcher/payload.rb,
lib/msf/ui/console/command_dispatcher/session.rb,
lib/msf/ui/console/command_dispatcher/resource.rb,
lib/msf/ui/console/command_dispatcher/auxiliary.rb,
lib/msf/ui/console/command_dispatcher/local_file_system.rb

Overview

The common command dispatcher base class that is shared for component-specific command dispatching.

Defined Under Namespace

Modules: Common, Session Classes: Auxiliary, Core, Creds, DNS, Db, Developer, Encoder, Evasion, Exploit, Jobs, LocalFileSystem, Modules, Nop, Payload, Post, Resource

Instance Attribute Summary collapse

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

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from Rex::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, #unknown_command, #update_prompt

Instance Attribute Details

#driverObject

The driver that this command dispatcher is associated with.



145
146
147
# File 'lib/msf/ui/console/command_dispatcher.rb', line 145

def driver
  @driver
end

Instance Method Details

#active_moduleObject

Returns the active module if one has been selected, otherwise nil is returned.



39
40
41
# File 'lib/msf/ui/console/command_dispatcher.rb', line 39

def active_module
  driver.active_module
end

#active_module=(mod) ⇒ Object

Sets the active module for this driver instance.



46
47
48
# File 'lib/msf/ui/console/command_dispatcher.rb', line 46

def active_module=(mod)
  driver.active_module = mod
end

#active_sessionObject

Returns the active session if one has been selected, otherwise nil is returned.



54
55
56
# File 'lib/msf/ui/console/command_dispatcher.rb', line 54

def active_session
  driver.active_session
end

#active_session=(mod) ⇒ Object

Sets the active session for this driver instance.



61
62
63
# File 'lib/msf/ui/console/command_dispatcher.rb', line 61

def active_session=(mod)
  driver.active_session = mod
end

#build_range_array(id_list) ⇒ Array<String>?

Generate an array of job or session IDs from a given range String. Always returns an Array unless an incorrect input is given. In that case, the result will always be nil, even if only one argument is incorrect.

Parameters:

  • id_list (String)

    Range or list description such as 1-5 or 1,3,5 etc

Returns:

  • (Array<String>, nil)

    Representing the range



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/msf/ui/console/command_dispatcher.rb', line 101

def build_range_array(id_list)
  item_list = []
  unless id_list.blank?
    temp_list = id_list.split(',')
    temp_list.each do |ele|
      return if ele.count('-') > 1 # Eg. 'sessions -u -1-,5', incorrect syntax
      return if ele.last == '-' # Last item of array is a '-', resulting in an incomplete range
      return if ele.first == '.' || ele.last == '.' #Eg. 'sessions -u .1..' or 'sessions -u ..
      return unless ele =~ (/^\d+((\.\.|-)\d+)?$/) || ele =~ (/^-?\d+$/) # Not a number or range

      # Check if the item is negative, as this will not always be a range
      if ele =~ (/^-?\d+$/) && ele.to_i < 0 # if ele is a single negative number
        item_list.push(ele.to_i)
      elsif ele.include? '-'
        temp_array = (ele.split("-").inject { |s, e| s.to_i..e.to_i }).to_a
        item_list.concat(temp_array)
      elsif ele.include? '..'
        temp_array = (ele.split("..").inject { |s, e| s.to_i..e.to_i }).to_a
        item_list.concat(temp_array)
      else
        item_list.push(ele.to_i)
      end
    end
  end

  item_list.uniq.sort
end

#docs_dirObject

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



90
91
92
# File 'lib/msf/ui/console/command_dispatcher.rb', line 90

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

#frameworkObject

Returns the framework instance associated with this command dispatcher.



31
32
33
# File 'lib/msf/ui/console/command_dispatcher.rb', line 31

def framework
  return driver.framework
end

#initialize(driver) ⇒ Object

Initializes a command dispatcher instance.



21
22
23
24
25
26
# File 'lib/msf/ui/console/command_dispatcher.rb', line 21

def initialize(driver)
  super

  self.driver = driver
  self.driver.on_command_proc = Proc.new { |command| framework.events.on_ui_command(command) }
end

#load_config(_path = nil) ⇒ Object

Load the configuration required for this CommandDispatcher, configuring any internal state as required.



82
83
84
# File 'lib/msf/ui/console/command_dispatcher.rb', line 82

def load_config(_path = nil)
  # noop
end

#log_error(err) ⇒ Object

Logs an error message to the screen and the log file. The callstack is also printed.



69
70
71
72
73
74
75
76
# File 'lib/msf/ui/console/command_dispatcher.rb', line 69

def log_error(err)
  print_error(err)

  wlog(err)

  # If it's a syntax error, log the call stack that it originated from.
  dlog("Call stack:\n#{$@.join("\n")}", 'core', LEV_1)
end

#remove_lines(text, to_match) ⇒ String

Remove lines with specific substring

Parameters:

  • text (String)

    Block of text to search over

  • to_match (String)

    String that when found, causes the whole line to be removed, including trailing "n" if present

Returns:

  • (String)

    Text sans lines containing to_match



137
138
139
140
# File 'lib/msf/ui/console/command_dispatcher.rb', line 137

def remove_lines(text, to_match)
  to_match = Regexp.escape(to_match)
  text.gsub(/^.*(#{to_match}).*(#{Regexp.escape $/})?/, '')
end