CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/post/mssql/ui/console.rb
Views: 1904
1
# -*- coding: binary -*-
2
3
require 'rex/post/sql/ui/console'
4
5
module Rex
6
module Post
7
module MSSQL
8
module Ui
9
###
10
#
11
# This class provides a shell driven interface to the MSSQL client API.
12
#
13
###
14
class Console
15
include Rex::Post::Sql::Ui::Console
16
include Rex::Ui::Text::DispatcherShell
17
18
# Dispatchers
19
require 'rex/post/mssql/ui/console/command_dispatcher'
20
require 'rex/post/mssql/ui/console/command_dispatcher/core'
21
require 'rex/post/mssql/ui/console/command_dispatcher/client'
22
23
#
24
# Initialize the MSSQL console.
25
#
26
# @param [Msf::Sessions::MSSQL] session
27
def initialize(session, opts={})
28
# The mssql client context
29
self.session = session
30
self.client = session.client
31
envchange = ::Rex::Proto::MSSQL::ClientMixin::ENVCHANGE
32
prompt = "%undMSSQL @ #{client.peerinfo} (#{client.initial_info_for_envchange(envchange: envchange::DATABASE)[:new]})%clr"
33
history_file = Msf::Config.history_file_for_session_type(session_type: session.type, interactive: false)
34
super(prompt, '>', history_file, nil, :mssql)
35
36
# Queued commands array
37
self.commands = []
38
39
# Point the input/output handles elsewhere
40
reset_ui
41
42
enstack_dispatcher(::Rex::Post::MSSQL::Ui::Console::CommandDispatcher::Core)
43
enstack_dispatcher(::Rex::Post::MSSQL::Ui::Console::CommandDispatcher::Client)
44
enstack_dispatcher(Msf::Ui::Console::CommandDispatcher::LocalFileSystem)
45
46
# Set up logging to whatever logsink 'core' is using
47
if ! $dispatcher['mssql']
48
$dispatcher['mssql'] = $dispatcher['core']
49
end
50
end
51
52
# @return [Msf::Sessions::MSSQL]
53
attr_reader :session
54
55
# @return [MSSQL::Client]
56
attr_reader :client
57
58
protected
59
60
attr_writer :session, :client # :nodoc:
61
attr_accessor :commands # :nodoc:
62
end
63
end
64
end
65
end
66
end
67
68