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/ldap/ui/console.rb
Views: 11789
# -*- coding: binary -*-12require 'English'3require 'rex/post/session_compatible_modules'45module Rex6module Post7module LDAP8module Ui9###10#11# This class provides a shell driven interface to the LDAP client API.12#13###14class Console1516include Rex::Ui::Text::DispatcherShell17include Rex::Post::SessionCompatibleModules1819# Dispatchers20require 'rex/post/ldap/ui/console/command_dispatcher'21require 'rex/post/ldap/ui/console/command_dispatcher/core'22require 'rex/post/ldap/ui/console/command_dispatcher/client'2324#25# Initialize the LDAP console.26#27# @param [Msf::Sessions::LDAP] session28def initialize(session)29super('%undLDAP%clr', '>', Msf::Config.ldap_session_history, nil, :ldap)3031# The ldap client context32self.session = session33self.client = session.client3435# Queued commands array36self.commands = []3738# Point the input/output handles elsewhere39reset_ui4041enstack_dispatcher(Rex::Post::LDAP::Ui::Console::CommandDispatcher::Client)42enstack_dispatcher(Rex::Post::LDAP::Ui::Console::CommandDispatcher::Core)43enstack_dispatcher(Msf::Ui::Console::CommandDispatcher::LocalFileSystem)4445# Set up logging to whatever logsink 'core' is using46if !$dispatcher['ldap']47$dispatcher['ldap'] = $dispatcher['core']48end49end5051#52# Called when someone wants to interact with the LDAP client. It's53# assumed that init_ui has been called prior.54#55def interact(&block)56# Run queued commands57commands.delete_if do |ent|58run_single(ent)59true60end6162# Run the interactive loop63run do |line|64# Run the command65run_single(line)6667# If a block was supplied, call it, otherwise return false68if block69block.call70else71false72end73end74end7576#77# Queues a command to be run when the interactive loop is entered.78#79def queue_cmd(cmd)80commands << cmd81end8283#84# Runs the specified command wrapper in something to catch exceptions.85#86def run_command(dispatcher, method, arguments)87super88rescue Timeout::Error89log_error('Operation timed out.')90rescue Rex::InvalidDestination => e91log_error(e.message)92rescue ::Errno::EPIPE, ::OpenSSL::SSL::SSLError, ::IOError, Net::LDAP::ResponseMissingOrInvalidError93session.kill94rescue ::StandardError => e95log_error("Error running command #{method}: #{e.class} #{e}")96elog(e)97end9899# @param [Hash] opts100# @return [String]101def help_to_s(opts = {})102super + format_session_compatible_modules103end104105#106# Logs that an error occurred and persists the callstack.107#108def log_error(msg)109print_error(msg)110111elog(msg, 'ldap')112113dlog("Call stack:\n#{$ERROR_POSITION.join("\n")}", 'ldap')114end115116# @return [Msf::Sessions::LDAP]117attr_reader :session118119# @return [Rex::Proto::LDAP::Client]120attr_reader :client # :nodoc:121122def format_prompt(val)123prompt = session.address.to_s124125substitute_colors("%undLDAP%clr (#{prompt}) > ", true)126end127128protected129130attr_writer :session, :client # :nodoc: # :nodoc:131attr_accessor :commands # :nodoc:132end133end134end135end136end137138139