Skip to content

Commit

Permalink
Add MySQL Arch & Platform detection by query
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanusz-r7 committed Apr 8, 2024
1 parent 9982a46 commit edd63ca
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/msf/base/sessions/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Msf::Sessions::MySQL < Msf::Sessions::Sql
# @param [Hash] opts
def initialize(rstream, opts = {})
@client = opts.fetch(:client)
self.platform = opts.fetch(:platform)
self.arch = opts.fetch(:arch)
self.console = ::Rex::Post::MySQL::Ui::Console.new(self)
super(rstream, opts)
end
Expand Down
33 changes: 33 additions & 0 deletions lib/rex/proto/mysql/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,39 @@ def current_database
# Current database is stored as an array under the type 1 key.
session_track.fetch(1, ['']).first
end

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

server_vars = query("show variables where variable_name in ('version_compile_machine', 'version_compile_os')").entries
server_vars.each do |server_var|
name, value = server_var
macos_platforms = ['mac', 'osx', 'darwin']

case name
when 'version_compile_machine'
result[:arch] = value
when 'version_compile_os'
platform = value.downcase
if platform.include? 'linux'
result[:platform] = Msf::Platform::Linux.realname
elsif platform.include? 'win' # Check Windows before MacOS/Darwin as Darwin includes 'win'
result[:platform] = Msf::Platform::Windows.realname
elsif macos_platforms.map { |macos_platform| platform.include? macos_platform }.any?
result[:platform] = Msf::Platform::OSX.realname
else
result[:platform] = value
end
else
next
end
end

result
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion modules/auxiliary/scanner/mysql/mysql_login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def int_version(str)
def session_setup(result)
return unless (result.connection && result.proof)

my_session = Msf::Sessions::MySQL.new(result.connection, { client: result.proof })
my_session = Msf::Sessions::MySQL.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/mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

RSpec.describe Msf::Sessions::MySQL do
let(:client) { instance_double(::Rex::Proto::MySQL::Client) }
let(:opts) { { client: client } }
let(:opts) { { client: client, platform: 'Linux', arch: 'x86_64' } }
let(:console_class) { Rex::Post::MySQL::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 @@ -10,7 +10,7 @@
let(:address) { '192.0.2.1' }
let(:port) { '3306' }
let(:peerinfo) { "#{address}:#{port}" }
let(:session) { Msf::Sessions::MySQL.new(nil, { client: client }) }
let(:session) { Msf::Sessions::MySQL.new(nil, { client: client, platform: 'Linux', arch: 'x86_64' }) }
let(:console) do
console = Rex::Post::MySQL::Ui::Console.new(session)
console.disable_output = true
Expand Down

0 comments on commit edd63ca

Please sign in to comment.