Skip to content

Commit

Permalink
Rename cwd to database_name
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanusz-r7 committed Feb 12, 2024
1 parent 7735746 commit c40e2df
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
11 changes: 5 additions & 6 deletions lib/rex/post/mssql/ui/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ def initialize(session, opts={})
self.session = session
self.client = session.client
# EnvChange Type 1: Database
require 'pry-byebug'; binding.pry;
db_env_change = session.client.initial_connection_info[:envs].select { |hash| hash[:type] == 1 }[0]
db = db_env_change[:new]
self.cwd = db
prompt = "%undMSSQL @ #{client.sock.peerinfo} (#{cwd})%clr"
self.database_name = db
prompt = "%undMSSQL @ #{client.sock.peerinfo} (#{self.database_name})%clr"
history_manager = Msf::Config.mssql_session_history
super(prompt, '>', history_manager, nil, :mssql)

Expand Down Expand Up @@ -73,13 +72,13 @@ def log_error(msg)
attr_reader :client

# @return [String]
attr_accessor :cwd
attr_accessor :database_name

# @param [Object] val
# @return [String]
def format_prompt(val)
self.cwd ||= ''
prompt = "%undMSSQL @ #{client.sock.peerinfo} (#{@cwd})%clr > "
self.database_name ||= ''
prompt = "%undMSSQL @ #{client.sock.peerinfo} (#{@database_name})%clr > "
substitute_colors(prompt, true)
end

Expand Down
10 changes: 5 additions & 5 deletions lib/rex/post/mysql/ui/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def initialize(session)
# The mysql client context
self.session = session
self.client = session.client
self.cwd = client.database
prompt = "%undMySQL @ #{client.socket.peerinfo} (#{cwd})%clr"
self.database_name = client.database
prompt = "%undMySQL @ #{client.socket.peerinfo} (#{self.database_name})%clr"
history_manager = Msf::Config.mysql_session_history
super(prompt, '>', history_manager, nil, :mysql)

Expand Down Expand Up @@ -65,13 +65,13 @@ def log_error(msg)
attr_reader :client

# @return [String]
attr_accessor :cwd
attr_accessor :database_name

# @param [Object] val
# @return [String]
def format_prompt(val)
@cwd ||= client.database
prompt = "%undMySQL @ #{client.socket.peerinfo} (#{@cwd})%clr > "
@database_name ||= client.database
prompt = "%undMySQL @ #{client.socket.peerinfo} (#{@database_name})%clr > "
substitute_colors(prompt, true)
end

Expand Down
10 changes: 5 additions & 5 deletions lib/rex/post/postgresql/ui/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def initialize(session)
# The postgresql client context
self.session = session
self.client = session.client
self.cwd = client.params['database']
prompt = "%undPostgreSQL @ #{client.conn.peerinfo} (#{cwd})%clr"
self.database_name = client.params['database']
prompt = "%undPostgreSQL @ #{client.conn.peerinfo} (#{self.database_name})%clr"
history_manager = Msf::Config.postgresql_session_history
super(prompt, '>', history_manager, nil, :postgresql)

Expand Down Expand Up @@ -67,11 +67,11 @@ def log_error(msg)
attr_reader :client # :nodoc:

# @return [String]
attr_accessor :cwd
attr_accessor :database_name

def format_prompt(val)
cwd ||= client.params['database']
prompt = "%undPostgreSQL @ #{client.conn.peerinfo} (#{cwd})%clr > "
db_name ||= client.params['database']
prompt = "%undPostgreSQL @ #{client.conn.peerinfo} (#{db_name})%clr > "
substitute_colors(prompt, true)
end

Expand Down
2 changes: 1 addition & 1 deletion modules/auxiliary/scanner/mssql/mssql_login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def run_host(ip)
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,
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/msf/base/sessions/mssql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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, database_name: 'name' } }
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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
RSpec.describe Rex::Post::MSSQL::Ui::Console::CommandDispatcher::Core do
let(:rstream) { instance_double(::Rex::Socket) }
let(:client) { instance_double(Rex::Proto::MSSQL::Client) }
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}" }
Expand Down

0 comments on commit c40e2df

Please sign in to comment.