Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/proto/mysql/client.rb
Views: 11704
require 'mysql'12module Rex3module Proto4module MySQL56# This is a Rex Proto wrapper around the ::Mysql client which is currently coming from the 'ruby-mysql' gem.7# The purpose of this wrapper is to provide 'peerhost' and 'peerport' methods to ensure the client interfaces8# are consistent between various SQL implementations/protocols.9class Client < ::Mysql10# @return [String] The remote IP address that the Mysql server is running on11def peerhost12io.remote_address.ip_address13end1415# @return [Integer] The remote port that the Mysql server is running on16def peerport17io.remote_address.ip_port18end1920# @return [String] The remote peer information containing IP and port21def peerinfo22"#{peerhost}:#{peerport}"23end2425# @return [String] The database this client is currently connected to26def current_database27# Current database is stored as an array under the type 1 key.28session_track.fetch(1, ['']).first29end3031# List of supported MySQL platforms & architectures:32# https://www.mysql.com/support/supportedplatforms/database.html33def map_compile_os_to_platform(compile_os)34return '' if compile_os.blank?3536compile_os = compile_os.downcase.encode(::Encoding::BINARY)3738if compile_os.match?('linux')39platform = Msf::Platform::Linux.realname40elsif compile_os.match?('unix')41platform = Msf::Platform::Unix.realname42elsif compile_os.match?(/(darwin|mac|osx)/)43platform = Msf::Platform::OSX.realname44elsif compile_os.match?('win')45platform = Msf::Platform::Windows.realname46elsif compile_os.match?('solaris')47platform = Msf::Platform::Solaris.realname48else49platform = compile_os50end5152platform53end5455def map_compile_arch_to_architecture(compile_arch)56return '' if compile_arch.blank?5758compile_arch = compile_arch.downcase.encode(::Encoding::BINARY)5960if compile_arch.match?('sparc')61if compile_arch.include?('64')62arch = ARCH_SPARC6463else64arch = ARCH_SPARC65end66elsif compile_arch.match?('arm')67if compile_arch.match?('64')68arch = ARCH_AARCH6469elsif compile_arch.match?('arm')70arch = ARCH_ARMLE71end72elsif compile_arch.match?('64')73arch = ARCH_X86_6474elsif compile_arch.match?('86') || compile_arch.match?('i686')75arch = ARCH_X8676else77arch = compile_arch78end7980arch81end8283# @return [Hash] Detect the platform and architecture of the MySQL server:84# * :arch [String] The server architecture.85# * :platform [String] The server platform.86def detect_platform_and_arch87result = {}8889server_vars = query("show variables where variable_name in ('version_compile_machine', 'version_compile_os')").entries.to_h90result[:arch] = map_compile_arch_to_architecture(server_vars['version_compile_machine'])91result[:platform] = map_compile_os_to_platform(server_vars['version_compile_os'])9293result94end95end96end97end98end99100101