Class: Rex::Proto::MySQL::Client

Inherits:
Mysql
  • Object
show all
Defined in:
lib/rex/proto/mysql/client.rb

Overview

This is a Rex Proto wrapper around the ::Mysql client which is currently coming from the ‘ruby-mysql’ gem. The purpose of this wrapper is to provide ‘peerhost’ and ‘peerport’ methods to ensure the client interfaces are consistent between various SQL implementations/protocols.

Instance Method Summary collapse

Instance Method Details

#current_databaseString

Returns The database this client is currently connected to.

Returns:

  • (String)

    The database this client is currently connected to



27
28
29
30
# File 'lib/rex/proto/mysql/client.rb', line 27

def current_database
  # Current database is stored as an array under the type 1 key.
  session_track.fetch(1, ['']).first
end

#detect_platform_and_archHash

Returns Detect the platform and architecture of the MySQL server:

  • :arch [String] The server architecture.

  • :platform [String] The server platform.

Returns:

  • (Hash)

    Detect the platform and architecture of the MySQL server:

    • :arch [String] The server architecture.

    • :platform [String] The server platform.



87
88
89
90
91
92
93
94
95
# File 'lib/rex/proto/mysql/client.rb', line 87

def detect_platform_and_arch
  result = {}

  server_vars = query("show variables where variable_name in ('version_compile_machine', 'version_compile_os')").entries.to_h
  result[:arch] = map_compile_arch_to_architecture(server_vars['version_compile_machine'])
  result[:platform] = map_compile_os_to_platform(server_vars['version_compile_os'])

  result
end

#map_compile_arch_to_architecture(compile_arch) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rex/proto/mysql/client.rb', line 56

def map_compile_arch_to_architecture(compile_arch)
  return '' if compile_arch.blank?

  compile_arch = compile_arch.downcase.encode(::Encoding::BINARY)

  if compile_arch.match?('sparc')
    if compile_arch.include?('64')
      arch = ARCH_SPARC64
    else
      arch = ARCH_SPARC
    end
  elsif compile_arch.match?('arm')
    if compile_arch.match?('64')
      arch = ARCH_AARCH64
    elsif compile_arch.match?('arm')
      arch = ARCH_ARMLE
    end
  elsif compile_arch.match?('64')
    arch = ARCH_X86_64
  elsif compile_arch.match?('86') || compile_arch.match?('i686')
    arch = ARCH_X86
  else
    arch = compile_arch
  end

  arch
end

#map_compile_os_to_platform(compile_os) ⇒ Object

List of supported MySQL platforms & architectures: www.mysql.com/support/supportedplatforms/database.html



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rex/proto/mysql/client.rb', line 34

def map_compile_os_to_platform(compile_os)
  return '' if compile_os.blank?

  compile_os = compile_os.downcase.encode(::Encoding::BINARY)

  if compile_os.match?('linux')
    platform = Msf::Platform::Linux.realname
  elsif compile_os.match?('unix')
    platform = Msf::Platform::Unix.realname
  elsif compile_os.match?(/(darwin|mac|osx)/)
    platform = Msf::Platform::OSX.realname
  elsif compile_os.match?('win')
    platform = Msf::Platform::Windows.realname
  elsif compile_os.match?('solaris')
    platform = Msf::Platform::Solaris.realname
  else
    platform = compile_os
  end

  platform
end

#peerhostString

Returns The remote IP address that the Mysql server is running on.

Returns:

  • (String)

    The remote IP address that the Mysql server is running on



12
13
14
# File 'lib/rex/proto/mysql/client.rb', line 12

def peerhost
  io.remote_address.ip_address
end

#peerinfoString

Returns The remote peer information containing IP and port.

Returns:

  • (String)

    The remote peer information containing IP and port



22
23
24
# File 'lib/rex/proto/mysql/client.rb', line 22

def peerinfo
  "#{peerhost}:#{peerport}"
end

#peerportInteger

Returns The remote port that the Mysql server is running on.

Returns:

  • (Integer)

    The remote port that the Mysql server is running on



17
18
19
# File 'lib/rex/proto/mysql/client.rb', line 17

def peerport
  io.remote_address.ip_port
end