Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/post/meterpreter/ui/console/command_dispatcher.rb
Views: 11791
# -*- coding: binary -*-12module Rex3module Post4module Meterpreter5module Ui67###8#9# Base class for all command dispatchers within the meterpreter console user10# interface.11#12###13module Console::CommandDispatcher1415include Msf::Ui::Console::CommandDispatcher::Session1617#18# The hash of file names to class names after a module has already been19# loaded once on the client side.20#21@@file_hash = {}2223#24# Checks the file name to hash association to see if the module being25# requested has already been loaded once.26#27def self.check_hash(name)28@@file_hash[name]29end3031#32# Sets the file path to class name association for future reference.33#34def self.set_hash(name, klass)35@@file_hash[name] = klass36end3738def initialize(shell)39@msf_loaded = nil40@filtered_commands = []41super42end4344#45# Returns the meterpreter client context.46#47def client48shell.client49end5051# A meterpreter session *is* a client but for the smb session it *has* a (ruby smb) client52# adding this here for parity with the smb session53def session54shell.client55end5657#58# Returns the commands that meet the requirements59#60def filter_commands(all, reqs)61all.delete_if do |cmd, _desc|62if reqs[cmd]&.any? { |req| !client.commands.include?(req) }63@filtered_commands << cmd64true65end66end67end6869def unknown_command(cmd, line)70if @filtered_commands.include?(cmd)71print_error("The \"#{cmd}\" command is not supported by this Meterpreter type (#{client.session_type})")72return :handled73end7475super76end7778#79# Return the subdir of the `documentation/` directory that should be used80# to find usage documentation81#82def docs_dir83File.join(super, 'meterpreter')84end8586#87# Returns true if the client has a framework object.88#89# Used for firing framework session events90#91def msf_loaded?92return @msf_loaded unless @msf_loaded.nil?93# if we get here we must not have initialized yet9495@msf_loaded = !!(client.framework)96@msf_loaded97end9899#100# Log that an error occurred.101#102def log_error(msg)103print_error(msg)104105elog(msg, 'meterpreter')106107dlog("Call stack:\n#{$@.join("\n")}", 'meterpreter')108end109110end111112end113end114end115end116117118