CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/lib/msf/base/sessions/ldap.rb
Views: 1904
# -*- coding: binary -*-12require 'rex/post/ldap'34class Msf::Sessions::LDAP5#6# This interface supports basic interaction.7#8include Msf::Session::Basic9include Msf::Sessions::Scriptable1011# @return [Rex::Post::LDAP::Ui::Console] The interactive console12attr_accessor :console13# @return [Rex::Proto::LDAP::Client] The LDAP client14attr_accessor :client1516attr_accessor :platform, :arch17attr_reader :framework1819# @param[Rex::IO::Stream] rstream20# @param [Hash] opts21# @option opts [Rex::Proto::LDAP::Client] :client22def initialize(rstream, opts = {})23@client = opts.fetch(:client)24self.console = Rex::Post::LDAP::Ui::Console.new(self)25super(rstream, opts)26end2728def bootstrap(datastore = {}, handler = nil)29session = self30session.init_ui(user_input, user_output)3132@info = "LDAP #{datastore['USERNAME']} @ #{@peer_info}"33end3435def execute_file(full_path, args)36if File.extname(full_path) == '.rb'37Rex::Script::Shell.new(self, full_path).run(args)38else39console.load_resource(full_path)40end41end4243def process_autoruns(datastore)44['InitialAutoRunScript', 'AutoRunScript'].each do |key|45next if datastore[key].nil? || datastore[key].empty?4647args = Shellwords.shellwords(datastore[key])48print_status("Session ID #{sid} (#{tunnel_to_s}) processing #{key} '#{datastore[key]}'")49execute_script(args.shift, *args)50end51end5253def type54self.class.type55end5657# Returns the type of session.58#59def self.type60'ldap'61end6263def self.can_cleanup_files64false65end6667#68# Returns the session description.69#70def desc71'LDAP'72end7374def address75@address ||= client.peerhost76end7778def port79@port ||= client.peerport80end8182##83# :category: Msf::Session::Interactive implementors84#85# Initializes the console's I/O handles.86#87def init_ui(input, output)88self.user_input = input89self.user_output = output90console.init_ui(input, output)91console.set_log_source(log_source)9293super94end9596##97# :category: Msf::Session::Interactive implementors98#99# Resets the console's I/O handles.100#101def reset_ui102console.unset_log_source103console.reset_ui104end105106def exit107console.stop108end109110##111# :category: Msf::Session::Interactive implementors112#113# Override the basic session interaction to use shell_read and114# shell_write instead of operating on rstream directly.115def _interact116framework.events.on_session_interact(self)117framework.history_manager.with_context(name: type.to_sym) do118_interact_stream119end120end121122##123# :category: Msf::Session::Interactive implementors124#125def _interact_stream126framework.events.on_session_interact(self)127128console.framework = framework129# Call the console interaction of the ldap client and130# pass it a block that returns whether or not we should still be131# interacting. This will allow the shell to abort if interaction is132# canceled.133console.interact { interacting != true }134console.framework = nil135136# If the stop flag has been set, then that means the user exited. Raise137# the EOFError so we can drop this handle like a bad habit.138raise EOFError if (console.stopped? == true)139end140141end142143144