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/sql/ui/console/command_dispatcher.rb
Views: 11791
1
# -*- coding: binary -*-
2
3
require 'rex/post/sql/ui/console/command_dispatcher/client'
4
require 'rex/post/sql/ui/console/command_dispatcher/core'
5
6
module Rex
7
module Post
8
module Sql
9
module Ui
10
module Console
11
12
###
13
#
14
# Base class for all command dispatchers within the Generic SQL console user interface.
15
#
16
###
17
module CommandDispatcher
18
19
include Msf::Ui::Console::CommandDispatcher::Session
20
21
#
22
# Initializes an instance of the core command set using the supplied session and client
23
# for interactivity.
24
#
25
# @param [Rex::Post::PostgreSQL::Ui::Console] console
26
def initialize(console)
27
super
28
@msf_loaded = nil
29
@filtered_commands = []
30
end
31
32
#
33
# Returns the SQL client context.
34
# @return [Object]
35
def client
36
console = shell
37
console.client
38
end
39
40
#
41
# Returns the PostgreSQL session context.
42
#
43
# @return [Msf::Sessions::PostgreSQL]
44
def session
45
console = shell
46
console.session
47
end
48
49
#
50
# Returns the commands that meet the requirements
51
#
52
def filter_commands(all, reqs)
53
all.delete_if do |cmd, _desc|
54
if reqs[cmd]&.any? { |req| !client.commands.include?(req) }
55
@filtered_commands << cmd
56
true
57
end
58
end
59
end
60
61
def unknown_command(cmd, line)
62
if @filtered_commands.include?(cmd)
63
print_error("The \"#{cmd}\" command is not supported by this session type (#{session.session_type})")
64
return :handled
65
end
66
67
super
68
end
69
70
#
71
# Returns true if the client has a framework object.
72
#
73
# Used for firing framework session events
74
#
75
def msf_loaded?
76
return @msf_loaded unless @msf_loaded.nil?
77
78
# if we get here we must not have initialized yet
79
80
@msf_loaded = !session.framework.nil?
81
@msf_loaded
82
end
83
end
84
end
85
end
86
end
87
end
88
end
89
90