Class: Metasploit::Framework::LoginScanner::MySQL

Inherits:
Object
  • Object
show all
Includes:
Base, RexSocket, Tcp::Client
Defined in:
lib/metasploit/framework/login_scanner/mysql.rb

Overview

This is the LoginScanner class for dealing with MySQL Database servers. It is responsible for taking a single target, and a list of credentials and attempting them. It then saves the results.

Constant Summary collapse

DEFAULT_PORT =
3306
LIKELY_PORTS =
[3306]
LIKELY_SERVICE_NAMES =
['mysql']
PRIVATE_TYPES =
[:password]
REALM_KEY =
nil

Instance Attribute Summary collapse

Attributes included from Tcp::Client

#max_send_size, #send_delay, #sock

Instance Method Summary collapse

Methods included from Tcp::Client

#chost, #connect, #cport, #disconnect, #proxies, #rhost, #rport, #set_tcp_evasions, #ssl, #ssl_version

Instance Attribute Details

#use_client_as_proofObject

Returns the value of attribute use_client_as_proof.



20
21
22
# File 'lib/metasploit/framework/login_scanner/mysql.rb', line 20

def use_client_as_proof
  @use_client_as_proof
end

Instance Method Details

#attempt_login(credential) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
83
84
85
# File 'lib/metasploit/framework/login_scanner/mysql.rb', line 28

def (credential)
  result_options = {
    credential:   credential,
    host:         host,
    port:         port,
    protocol:     'tcp',
    service_name: 'mysql'
  }

  begin
    # manage our behind the scenes socket. Close any existing one and open a new one
    disconnect if self.sock
    self.sock = connect

    mysql_conn = ::Mysql.connect(host, credential.public, credential.private, '', port, io: self.sock)

  rescue ::SystemCallError, Rex::ConnectionError => e
    result_options.merge!({
      status: Metasploit::Model::Login::Status::UNABLE_TO_CONNECT,
      proof: e
    })
  rescue Mysql::ClientError => e
    result_options.merge!({
      status: Metasploit::Model::Login::Status::UNABLE_TO_CONNECT,
      proof: e
    })
  rescue Mysql::HostNotPrivileged => e
    result_options.merge!({
      status: Metasploit::Model::Login::Status::UNABLE_TO_CONNECT,
      proof: e
    })
  rescue Mysql::AccessDeniedError => e
    result_options.merge!({
      status: Metasploit::Model::Login::Status::INCORRECT,
      proof: e
    })
  rescue Mysql::HostIsBlocked => e
    result_options.merge!({
      status: Metasploit::Model::Login::Status::UNABLE_TO_CONNECT,
      proof: e
    })
  end

  if mysql_conn
    result_options[:status] = Metasploit::Model::Login::Status::SUCCESSFUL

    # This module no long owns the socket, return it as proof so the calling context can perform additional operations
    # Additionally assign values to nil to avoid closing the socket etc automatically
    if use_client_as_proof
      result_options[:proof] = mysql_conn
      nil
    else
      mysql_conn.close
    end
  end

  ::Metasploit::Framework::LoginScanner::Result.new(result_options)
end

#set_sane_defaultsObject

This method sets the sane defaults for things like timeouts and TCP evasion options



89
90
91
92
93
94
# File 'lib/metasploit/framework/login_scanner/mysql.rb', line 89

def set_sane_defaults
  self.connection_timeout ||= 30
  self.port               ||= DEFAULT_PORT
  self.max_send_size      ||= 0
  self.send_delay         ||= 0
end