2011-10-26 22:33:12 +00:00
|
|
|
##
|
2017-07-24 13:26:21 +00:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2011-10-26 22:33:12 +00:00
|
|
|
##
|
|
|
|
|
2014-06-20 20:22:37 +00:00
|
|
|
require 'msf/core/auxiliary/jtr'
|
2011-10-26 22:33:12 +00:00
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Auxiliary::JohnTheRipper
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'John the Ripper MySQL Password Cracker (Fast Mode)',
|
|
|
|
'Description' => %Q{
|
|
|
|
This module uses John the Ripper to identify weak passwords that have been
|
|
|
|
acquired from the mysql_hashdump module. Passwords that have been successfully
|
|
|
|
cracked are then saved as proper credentials
|
|
|
|
},
|
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'theLightCosine',
|
|
|
|
'hdm'
|
|
|
|
] ,
|
|
|
|
'License' => MSF_LICENSE # JtR itself is GPLv2, but this wrapper is MSF (BSD)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
2014-06-20 20:21:35 +00:00
|
|
|
cracker = new_john_cracker
|
2013-08-30 21:28:54 +00:00
|
|
|
|
2015-04-03 11:12:23 +00:00
|
|
|
# generate our wordlist and close the file handle
|
2014-06-20 20:21:35 +00:00
|
|
|
wordlist = wordlist_file
|
2017-07-10 16:18:20 +00:00
|
|
|
unless wordlist
|
|
|
|
print_error('This module cannot run without a database connected. Use db_connect to connect to a database.')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
wordlist.close
|
2014-06-20 20:21:35 +00:00
|
|
|
print_status "Wordlist file written out to #{wordlist.path}"
|
|
|
|
cracker.wordlist = wordlist.path
|
|
|
|
cracker.hash_path = hash_file
|
|
|
|
|
|
|
|
['mysql','mysql-sha1'].each do |format|
|
|
|
|
cracker_instance = cracker.dup
|
|
|
|
cracker_instance.format = format
|
|
|
|
print_status "Cracking #{format} hashes in normal wordlist mode..."
|
2015-01-07 18:32:26 +00:00
|
|
|
# Turn on KoreLogic rules if the user asked for it
|
2019-01-15 13:04:11 +00:00
|
|
|
if datastore['KORELOGIC']
|
2015-01-07 18:32:26 +00:00
|
|
|
cracker_instance.rules = 'KoreLogicRules'
|
2015-01-07 18:36:07 +00:00
|
|
|
print_status "Applying KoreLogic ruleset..."
|
2015-01-07 18:32:26 +00:00
|
|
|
end
|
2014-06-20 20:21:35 +00:00
|
|
|
cracker_instance.crack do |line|
|
|
|
|
print_status line.chomp
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
|
2014-06-20 20:21:35 +00:00
|
|
|
print_status "Cracking #{format} hashes in single mode..."
|
|
|
|
cracker_instance.rules = 'single'
|
|
|
|
cracker_instance.crack do |line|
|
|
|
|
print_status line.chomp
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
|
2014-06-23 20:36:17 +00:00
|
|
|
print_status "Cracking #{format} hashes in incremental mode (Digits)..."
|
|
|
|
cracker_instance.incremental = 'Digits'
|
2014-06-20 20:21:35 +00:00
|
|
|
cracker_instance.crack do |line|
|
|
|
|
print_status line.chomp
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
|
2014-06-20 20:21:35 +00:00
|
|
|
print_status "Cracked Passwords this run:"
|
|
|
|
cracker_instance.each_cracked_password do |password_line|
|
|
|
|
password_line.chomp!
|
|
|
|
next if password_line.blank?
|
|
|
|
fields = password_line.split(":")
|
|
|
|
# If we don't have an expected minimum number of fields, this is probably not a hash line
|
|
|
|
next unless fields.count >=3
|
|
|
|
username = fields.shift
|
|
|
|
core_id = fields.pop
|
|
|
|
password = fields.join(':') # Anything left must be the password. This accounts for passwords with : in them
|
|
|
|
print_good password_line
|
|
|
|
create_cracked_credential( username: username, password: password, core_id: core_id)
|
|
|
|
end
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2014-06-20 20:21:35 +00:00
|
|
|
end
|
2013-08-30 21:28:54 +00:00
|
|
|
|
2014-06-20 20:21:35 +00:00
|
|
|
def hash_file
|
|
|
|
hashlist = Rex::Quickfile.new("hashes_tmp")
|
2018-06-13 17:09:58 +00:00
|
|
|
framework.db.creds(workspace: myworkspace, type: 'Metasploit::Credential::NonreplayableHash').each do |core|
|
|
|
|
if core.private.jtr_format =~ /mysql|mysql-sha1/
|
2014-06-20 20:21:35 +00:00
|
|
|
user = core.public.username
|
2018-06-13 17:09:58 +00:00
|
|
|
hash_string = core.private.data
|
2014-06-20 20:21:35 +00:00
|
|
|
id = core.id
|
|
|
|
hashlist.puts "#{user}:#{hash_string}:#{id}:"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
hashlist.close
|
|
|
|
print_status "Hashes Written out to #{hashlist.path}"
|
|
|
|
hashlist.path
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2011-10-26 23:31:12 +00:00
|
|
|
|
|
|
|
|
2011-10-26 22:33:12 +00:00
|
|
|
end
|