CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/post/ldap/ui/console/command_dispatcher.rb
Views: 11791
1
# -*- coding: binary -*-
2
3
require 'English'
4
require 'rex/ui/text/dispatcher_shell'
5
6
module Rex
7
module Post
8
module LDAP
9
module Ui
10
###
11
#
12
# Base class for all command dispatchers within the LDAP console user
13
# interface.
14
#
15
###
16
module Console::CommandDispatcher
17
include Msf::Ui::Console::CommandDispatcher::Session
18
19
#
20
# Initializes an instance of the core command set using the supplied session and client
21
# for interactivity.
22
#
23
# @param [Rex::Post::LDAP::Ui::Console] console
24
def initialize(console)
25
super
26
@msf_loaded = nil
27
@filtered_commands = []
28
end
29
30
#
31
# Returns the LDAP client context.
32
#
33
# @return [Rex::Proto::LDAP::Client]
34
def client
35
console = shell
36
console.client
37
end
38
39
#
40
# Returns the LDAP session context.
41
#
42
# @return [Msf::Sessions::LDAP]
43
def session
44
console = shell
45
console.session
46
end
47
48
#
49
# Returns the commands that meet the requirements
50
#
51
def filter_commands(all, reqs)
52
all.delete_if do |cmd, _desc|
53
if reqs[cmd]&.any? { |req| !client.commands.include?(req) }
54
@filtered_commands << cmd
55
true
56
end
57
end
58
end
59
60
def unknown_command(cmd, line)
61
if @filtered_commands.include?(cmd)
62
print_error("The \"#{cmd}\" command is not supported by this session type (#{session.session_type})")
63
return :handled
64
end
65
66
super
67
end
68
69
#
70
# Return the subdir of the `documentation/` directory that should be used
71
# to find usage documentation
72
#
73
def docs_dir
74
File.join(super, 'ldap_session')
75
end
76
77
#
78
# Returns true if the client has a framework object.
79
#
80
# Used for firing framework session events
81
#
82
def msf_loaded?
83
return @msf_loaded unless @msf_loaded.nil?
84
85
# if we get here we must not have initialized yet
86
87
@msf_loaded = !session.framework.nil?
88
@msf_loaded
89
end
90
91
#
92
# Log that an error occurred.
93
#
94
def log_error(msg)
95
print_error(msg)
96
97
elog(msg, 'ldap')
98
99
dlog("Call stack:\n#{$ERROR_POSITION.join("\n")}", 'ldap')
100
end
101
end
102
end
103
end
104
end
105
end
106
107