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/smb/ui/console/command_dispatcher.rb
Views: 11766
# -*- coding: binary -*-12require 'English'3require 'rex/ui/text/dispatcher_shell'45module Rex6module Post7module SMB8module Ui9###10#11# Base class for all command dispatchers within the SMB console user12# interface.13#14###15module Console::CommandDispatcher16include Msf::Ui::Console::CommandDispatcher::Session1718#19# Initializes an instance of the core command set using the supplied session and client20# for interactivity.21#22# @param [Rex::Post::SMB::Ui::Console] console23def initialize(console)24super25@msf_loaded = nil26@filtered_commands = []27end2829#30# Returns the smb client context.31#32# @return [RubySMB::Client]33def client34console = shell35console.client36end3738#39# Returns the smb simple client.40#41# @return [Rex::Proto::SMB::SimpleClient]42def simple_client43shell.simple_client44end4546#47# Returns the smb session context.48#49# @return [Msf::Sessions::SMB]50def session51console = shell52console.session53end5455#56# Returns the active share57#58# @return [RubySMB::SMB2::Tree]59def active_share60console = shell61console.active_share62end6364#65# Returns the commands that meet the requirements66#67def filter_commands(all, reqs)68all.delete_if do |cmd, _desc|69if reqs[cmd]&.any? { |req| !client.commands.include?(req) }70@filtered_commands << cmd71true72end73end74end7576def unknown_command(cmd, line)77if @filtered_commands.include?(cmd)78print_error("The \"#{cmd}\" command is not supported by this session type (#{session.session_type})")79return :handled80end8182super83end8485#86# Return the subdir of the `documentation/` directory that should be used87# to find usage documentation88#89def docs_dir90File.join(super, 'smb_session')91end9293#94# Returns true if the client has a framework object.95#96# Used for firing framework session events97#98def msf_loaded?99return @msf_loaded unless @msf_loaded.nil?100101# if we get here we must not have initialized yet102103@msf_loaded = !session.framework.nil?104@msf_loaded105end106107#108# Log that an error occurred.109#110def log_error(msg)111print_error(msg)112113elog(msg, 'smb')114115dlog("Call stack:\n#{$ERROR_POSITION.join("\n")}", 'smb')116end117end118end119end120end121end122123124