Class: Rex::Post::LDAP::Ui::Console
- Inherits:
-
Object
- Object
- Rex::Post::LDAP::Ui::Console
- Defined in:
- lib/rex/post/ldap/ui/console.rb
Overview
This class provides a shell driven interface to the LDAP client API.
Defined Under Namespace
Modules: CommandDispatcher
Instance Attribute Summary collapse
- #client ⇒ Rex::Proto::LDAP::Client
-
#commands ⇒ Object
protected
:nodoc:.
- #session ⇒ Msf::Sessions::LDAP
Attributes included from Ui::Text::DispatcherShell
#blocked, #busy, #dispatcher_stack
Attributes included from Ui::Text::Shell
#cont_flag, #cont_prompt, #disable_output, #framework, #hist_last_saved, #histfile, #history_manager, #input, #local_hostname, #local_username, #log_source, #name, #on_command_proc, #on_print_proc, #output, #prompt, #prompt_char, #stop_count, #stop_flag, #tab_complete_proc
Instance Method Summary collapse
- #format_prompt(val) ⇒ Object
- #help_to_s(opts = {}) ⇒ String
-
#initialize(session) ⇒ Console
constructor
Initialize the LDAP console.
-
#interact(&block) ⇒ Object
Called when someone wants to interact with the LDAP client.
-
#log_error(msg) ⇒ Object
Logs that an error occurred and persists the callstack.
-
#queue_cmd(cmd) ⇒ Object
Queues a command to be run when the interactive loop is entered.
-
#run_command(dispatcher, method, arguments) ⇒ Object
Runs the specified command wrapper in something to catch exceptions.
Methods included from SessionCompatibleModules
#format_session_compatible_modules, #session_compatible_modules
Methods included from Ui::Text::DispatcherShell
#append_dispatcher, #block_command, #blocked_command?, #current_dispatcher, #destack_dispatcher, #enstack_dispatcher, #remove_dispatcher, #run_single, #shellsplitex, #tab_complete, #tab_complete_helper, #tab_complete_stub, #unblock_command, #unknown_command
Methods included from Ui::Text::Shell
#_print_prompt, #get_input_line, #init_tab_complete, #init_ui, #log_input, #log_output, #parse_line, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #prompt_yesno, #reset_ui, #run, #set_log_source, #stop, #stopped?, #supports_color?, #tab_complete, #unset_log_source, #update_prompt, #with_history_manager_context
Methods included from Ui::Text::Resource
Constructor Details
#initialize(session) ⇒ Console
Initialize the LDAP console.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rex/post/ldap/ui/console.rb', line 29 def initialize(session) super('%undLDAP%clr', '>', Msf::Config.ldap_session_history, nil, :ldap) # The ldap client context self.session = session self.client = session.client # Queued commands array self.commands = [] # Point the input/output handles elsewhere reset_ui enstack_dispatcher(Rex::Post::LDAP::Ui::Console::CommandDispatcher::Client) enstack_dispatcher(Rex::Post::LDAP::Ui::Console::CommandDispatcher::Core) enstack_dispatcher(Msf::Ui::Console::CommandDispatcher::LocalFileSystem) # Set up logging to whatever logsink 'core' is using if !$dispatcher['ldap'] $dispatcher['ldap'] = $dispatcher['core'] end end |
Instance Attribute Details
#client ⇒ Rex::Proto::LDAP::Client
121 122 123 |
# File 'lib/rex/post/ldap/ui/console.rb', line 121 def client @client end |
#commands ⇒ Object (protected)
:nodoc:
132 133 134 |
# File 'lib/rex/post/ldap/ui/console.rb', line 132 def commands @commands end |
#session ⇒ Msf::Sessions::LDAP
118 119 120 |
# File 'lib/rex/post/ldap/ui/console.rb', line 118 def session @session end |
Instance Method Details
#format_prompt(val) ⇒ Object
123 124 125 126 127 |
# File 'lib/rex/post/ldap/ui/console.rb', line 123 def format_prompt(val) prompt = session.address.to_s substitute_colors("%undLDAP%clr (#{prompt}) > ", true) end |
#help_to_s(opts = {}) ⇒ String
102 103 104 |
# File 'lib/rex/post/ldap/ui/console.rb', line 102 def help_to_s(opts = {}) super + format_session_compatible_modules end |
#interact(&block) ⇒ Object
Called when someone wants to interact with the LDAP client. It’s assumed that init_ui has been called prior.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rex/post/ldap/ui/console.rb', line 56 def interact(&block) # Run queued commands commands.delete_if do |ent| run_single(ent) true end # Run the interactive loop run do |line| # Run the command run_single(line) # If a block was supplied, call it, otherwise return false if block block.call else false end end end |
#log_error(msg) ⇒ Object
Logs that an error occurred and persists the callstack.
109 110 111 112 113 114 115 |
# File 'lib/rex/post/ldap/ui/console.rb', line 109 def log_error(msg) print_error(msg) elog(msg, 'ldap') dlog("Call stack:\n#{$ERROR_POSITION.join("\n")}", 'ldap') end |
#queue_cmd(cmd) ⇒ Object
Queues a command to be run when the interactive loop is entered.
80 81 82 |
# File 'lib/rex/post/ldap/ui/console.rb', line 80 def queue_cmd(cmd) commands << cmd end |
#run_command(dispatcher, method, arguments) ⇒ Object
Runs the specified command wrapper in something to catch exceptions.
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rex/post/ldap/ui/console.rb', line 87 def run_command(dispatcher, method, arguments) super rescue Timeout::Error log_error('Operation timed out.') rescue Rex::InvalidDestination => e log_error(e.) rescue ::Errno::EPIPE, ::OpenSSL::SSL::SSLError, ::IOError, Net::LDAP::ResponseMissingOrInvalidError session.kill rescue ::StandardError => e log_error("Error running command #{method}: #{e.class} #{e}") elog(e) end |