Land #18855, Use database_name for SQL sessions

This commit is contained in:
cgranleese-r7 2024-02-19 11:10:02 +00:00 committed by GitHub
commit db3b2de3f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 18 additions and 18 deletions

View File

@ -26,8 +26,7 @@ module Rex
# The mssql client context
self.session = session
self.client = session.client
self.cwd = session.client.mssql_query('SELECT DB_NAME();')[:rows][0][0]
prompt = "%undMSSQL @ #{client.sock.peerinfo} (#{cwd})%clr"
prompt = "%undMSSQL @ #{client.sock.peerinfo} (#{database_name})%clr"
history_manager = Msf::Config.mssql_session_history
super(prompt, '>', history_manager, nil, :mssql)
@ -126,13 +125,14 @@ module Rex
attr_reader :client
# @return [String]
attr_accessor :cwd
def database_name
session.client.mssql_query('SELECT DB_NAME();')[:rows][0][0]
end
# @param [Object] val
# @return [String]
def format_prompt(val)
self.cwd ||= ''
prompt = "%undMSSQL @ #{client.sock.peerinfo} (#{@cwd})%clr > "
prompt = "%undMSSQL @ #{client.sock.peerinfo} (#{database_name})%clr > "
substitute_colors(prompt, true)
end

View File

@ -23,8 +23,7 @@ module Rex
# The mysql client context
self.session = session
self.client = session.client
self.cwd = client.database
prompt = "%undMySQL @ #{client.socket.peerinfo} (#{cwd})%clr"
prompt = "%undMySQL @ #{client.socket.peerinfo} (#{database_name})%clr"
history_manager = Msf::Config.mysql_session_history
super(prompt, '>', history_manager, nil, :mysql)
@ -119,13 +118,14 @@ module Rex
attr_reader :client
# @return [String]
attr_accessor :cwd
def database_name
client.database
end
# @param [Object] val
# @return [String]
def format_prompt(val)
@cwd ||= client.database
prompt = "%undMySQL @ #{client.socket.peerinfo} (#{@cwd})%clr > "
prompt = "%undMySQL @ #{client.socket.peerinfo} (#{database_name})%clr > "
substitute_colors(prompt, true)
end

View File

@ -30,8 +30,7 @@ module Rex
# The postgresql client context
self.session = session
self.client = session.client
self.cwd = client.params['database']
prompt = "%undPostgreSQL @ #{client.conn.peerinfo} (#{cwd})%clr"
prompt = "%undPostgreSQL @ #{client.conn.peerinfo} (#{database_name})%clr"
history_manager = Msf::Config.postgresql_session_history
super(prompt, '>', history_manager, nil, :postgresql)
@ -136,11 +135,12 @@ module Rex
attr_reader :client # :nodoc:
# @return [String]
attr_accessor :cwd
def database_name
client.params['database']
end
def format_prompt(val)
cwd ||= client.params['database']
prompt = "%undPostgreSQL @ #{client.conn.peerinfo} (#{cwd})%clr > "
prompt = "%undPostgreSQL @ #{client.conn.peerinfo} (#{database_name})%clr > "
substitute_colors(prompt, true)
end

View File

@ -133,7 +133,7 @@ class MetasploitModule < Msf::Auxiliary
def session_setup(result, client)
return unless (result && client)
rstream = client.sock
my_session = Msf::Sessions::MSSQL.new(rstream, { client: client }) # is cwd right?
my_session = Msf::Sessions::MSSQL.new(rstream, { client: client })
merging = {
'USERPASS_FILE' => nil,
'USER_FILE' => nil,

View File

@ -6,7 +6,7 @@ require 'rex/post/mssql/ui/console/command_dispatcher/core'
RSpec.describe Msf::Sessions::MSSQL do
let(:rstream) { instance_double(::Rex::Socket) }
let(:client) { instance_double(Rex::Proto::MSSQL::Client) }
let(:opts) { { client: client, cwd: 'name' } }
let(:opts) { { client: client } }
let(:console_class) { Rex::Post::MSSQL::Ui::Console }
let(:user_input) { instance_double(Rex::Ui::Text::Input::Readline) }
let(:user_output) { instance_double(Rex::Ui::Text::Output::Stdio) }

View File

@ -9,7 +9,7 @@ RSpec.describe Rex::Post::MSSQL::Ui::Console::CommandDispatcher::Core do
let(:query_result) do
{ rows: [['mssql']]}
end
let(:session) { Msf::Sessions::MSSQL.new(nil, { client: client, cwd: 'mssql' }) }
let(:session) { Msf::Sessions::MSSQL.new(nil, { client: client }) }
let(:address) { '192.0.2.1' }
let(:port) { '1433' }
let(:peer_info) { "#{address}:#{port}" }