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

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



83
84
85
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher.rb', line 83

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

#filter_commands(all, reqs) ⇒ Object

Returns the commands that meet the requirements



61
62
63
64
65
66
67
68
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher.rb', line 61

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.



103
104
105
106
107
108
109
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher.rb', line 103

def log_error(msg)
  print_error(msg)

  elog(msg, 'meterpreter')

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

#msf_loaded?Boolean

Returns true if the client has a framework object.

Used for firing framework session events

Returns:

  • (Boolean)


92
93
94
95
96
97
98
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher.rb', line 92

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

#sessionObject

A meterpreter session is a client but for the smb session it has a (ruby smb) client adding this here for parity with the smb session



54
55
56
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher.rb', line 54

def session
  shell.client
end

#unknown_command(cmd, line) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher.rb', line 70

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