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/msf/base/sessions/smb.rb
Views: 11784
# -*- coding: binary -*-12require 'rex/post/smb'34class Msf::Sessions::SMB5#6# This interface supports basic interaction.7#8include Msf::Session::Basic9include Msf::Sessions::Scriptable1011# @return [Rex::Post::SMB::Ui::Console] The interactive console12attr_accessor :console13# @return [RubySMB::Client] The SMB client14attr_accessor :client15# @return [Rex::Proto::SMB::SimpleClient]16attr_accessor :simple_client17attr_accessor :platform, :arch18attr_reader :framework1920# @param[Rex::IO::Stream] rstream21# @param [Hash] opts22# @option opts [RubySMB::Client] :client23def initialize(rstream, opts = {})24@client = opts.fetch(:client)25@simple_client = ::Rex::Proto::SMB::SimpleClient.new(client.dispatcher.tcp_socket, client: client)26self.console = Rex::Post::SMB::Ui::Console.new(self)27super(rstream, opts)28end2930def bootstrap(datastore = {}, handler = nil)31session = self32session.init_ui(user_input, user_output)3334@info = "SMB #{datastore['USERNAME']} @ #{@peer_info}"35end3637def execute_file(full_path, args)38if File.extname(full_path) == '.rb'39Rex::Script::Shell.new(self, full_path).run(args)40else41console.load_resource(full_path)42end43end4445def process_autoruns(datastore)46['InitialAutoRunScript', 'AutoRunScript'].each do |key|47next if datastore[key].nil? || datastore[key].empty?4849args = Shellwords.shellwords(datastore[key])50print_status("Session ID #{sid} (#{tunnel_to_s}) processing #{key} '#{datastore[key]}'")51execute_script(args.shift, *args)52end53end5455def type56self.class.type57end5859# Returns the type of session.60#61def self.type62'smb'63end6465def self.can_cleanup_files66false67end6869#70# Returns the session description.71#72def desc73'SMB'74end7576def address77@address ||= simple_client.peerhost78end7980def port81@port ||= simple_client.peerport82end8384##85# :category: Msf::Session::Interactive implementors86#87# Initializes the console's I/O handles.88#89def init_ui(input, output)90self.user_input = input91self.user_output = output92console.init_ui(input, output)93console.set_log_source(log_source)9495super96end9798##99# :category: Msf::Session::Interactive implementors100#101# Resets the console's I/O handles.102#103def reset_ui104console.unset_log_source105console.reset_ui106end107108def exit109console.stop110end111112##113# :category: Msf::Session::Interactive implementors114#115# Override the basic session interaction to use shell_read and116# shell_write instead of operating on rstream directly.117def _interact118framework.events.on_session_interact(self)119framework.history_manager.with_context(name: type.to_sym) do120_interact_stream121end122end123124##125# :category: Msf::Session::Interactive implementors126#127def _interact_stream128framework.events.on_session_interact(self)129130console.framework = framework131# Call the console interaction of the smb client and132# pass it a block that returns whether or not we should still be133# interacting. This will allow the shell to abort if interaction is134# canceled.135console.interact { interacting != true }136console.framework = nil137138# If the stop flag has been set, then that means the user exited. Raise139# the EOFError so we can drop this handle like a bad habit.140raise EOFError if (console.stopped? == true)141end142143end144145146