Skip to content

Commit

Permalink
add arch and platform detection for mssql sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
zgoldman-r7 committed Apr 18, 2024
1 parent 13a79ab commit ff56e6f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/msf/base/sessions/mssql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Msf::Sessions::MSSQL < Msf::Sessions::Sql

def initialize(rstream, opts = {})
@client = opts.fetch(:client)
self.platform = opts.fetch(:platform)
self.arch = opts.fetch(:arch)
self.console = ::Rex::Post::MSSQL::Ui::Console.new(self, opts)

super(rstream, opts)
Expand Down
12 changes: 12 additions & 0 deletions lib/rex/proto/mssql/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ def initialize(framework_module, framework, rhost, rport = 1433, proxies = nil)
@current_database = ''
end

# @return [Hash] Detect the platform and architecture of the MSSQL server:
# * :arch [String] The server architecture.
# * :platform [String] The server platform.
def detect_platform_and_arch
result = {}

server_vars = query("select @@version")
result[:arch] = ARCH_X86_64
result[:platform] = server_vars[:rows][0][0].match?('Windows') ? Msf::Platform::Windows.realname : Msf::Platform::Linux.realname
result
end

#
# This method connects to the server over TCP and attempts
# to authenticate with the supplied username and password
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 @@ -153,7 +153,7 @@ def run_host(ip)
def session_setup(result)
return unless (result.connection && result.proof)

my_session = Msf::Sessions::MSSQL.new(result.connection, { client: result.proof })
my_session = Msf::Sessions::MSSQL.new(result.connection, { client: result.proof, **result.proof.detect_platform_and_arch })
merge_me = {
'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 @@ -5,7 +5,7 @@

RSpec.describe Msf::Sessions::MSSQL do
let(:client) { instance_double(Rex::Proto::MSSQL::Client) }
let(:opts) { { client: client } }
let(:opts) { { client: client, platform: Msf::Platform::Linux.realname, arch: ARCH_X86_64 } }
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 @@ -5,7 +5,7 @@

RSpec.describe Rex::Post::MSSQL::Ui::Console::CommandDispatcher::Core do
let(:client) { instance_double(Rex::Proto::MSSQL::Client) }
let(:session) { Msf::Sessions::MSSQL.new(nil, { client: client }) }
let(:session) { Msf::Sessions::MSSQL.new(nil, { client: client, platform: Msf::Platform::Linux.realname, arch: ARCH_X86_64 }) }
let(:address) { '192.0.2.1' }
let(:port) { '1433' }
let(:peer_info) { "#{address}:#{port}" }
Expand Down

0 comments on commit ff56e6f

Please sign in to comment.