Module: Rex::Post::Meterpreter::Ui::Console::CommandDispatcher

Overview

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

Defined Under Namespace

Classes: Android, AppApi, Core, Espia, Extapi, Incognito, Kiwi, Lanattacks, Peinjector, Powershell, Priv, Python, Sniffer, Stdapi, Unhook, Winpmem

Constant Summary collapse

@@file_hash =

The hash of file names to class names after a module has already been loaded once on the client side.

{}

Instance Attribute Summary

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

#shell, #tab_complete_items

Class Method Summary collapse

Instance Method Summary collapse

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, #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

Class Method Details

.check_hash(name) ⇒ Object

Checks the file name to hash association to see if the module being requested has already been loaded once.


28
29
30
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher.rb', line 28

def self.check_hash(name)
  @@file_hash[name]
end

.set_hash(name, klass) ⇒ Object

Sets the file path to class name association for future reference.


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

def self.set_hash(name, klass)
  @@file_hash[name] = klass
end

Instance Method Details

#clientObject

Returns the meterpreter client context.


48
49
50
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher.rb', line 48

def client
  shell.client
end

#docs_dirObject

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


77
78
79
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher.rb', line 77

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

#filter_commands(all, reqs) ⇒ Object

Returns the commands that meet the requirements


55
56
57
58
59
60
61
62
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher.rb', line 55

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(shell) ⇒ Object


39
40
41
42
43
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher.rb', line 39

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

#log_error(msg) ⇒ Object

Log that an error occurred.


97
98
99
100
101
102
103
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher.rb', line 97

def log_error(msg)
  print_error(msg)

  elog(msg, 'meterpreter')

  dlog("Call stack:\n#{[email protected].join("\n")}", 'meterpreter')
end

#msf_loaded?Boolean

Returns true if the client has a framework object.

Used for firing framework session events

Returns:

  • (Boolean)

86
87
88
89
90
91
92
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher.rb', line 86

def msf_loaded?
  return @msf_loaded unless @msf_loaded.nil?
  # if we get here we must not have initialized yet

  @msf_loaded = !!(client.framework)
  @msf_loaded
end

#unknown_command(cmd, line) ⇒ Object


64
65
66
67
68
69
70
71
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher.rb', line 64

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

  super
end