2011-07-09 02:14:24 +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-09 02:14:24 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
require 'msf/core'
|
2014-06-25 15:13:41 +00:00
|
|
|
require 'msf/core/auxiliary/jtr'
|
2011-07-09 02:14:24 +00:00
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2011-07-09 02:14:24 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Auxiliary::JohnTheRipper
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
2013-10-15 20:31:03 +00:00
|
|
|
'Name' => 'John the Ripper Password Cracker (Fast Mode)',
|
|
|
|
'Description' => %Q{
|
2013-08-30 21:28:54 +00:00
|
|
|
This module uses John the Ripper to identify weak passwords that have been
|
|
|
|
acquired as hashed files (loot) or raw LANMAN/NTLM hashes (hashdump). The goal
|
|
|
|
of this module is to find trivial passwords in a short amount of time. To
|
|
|
|
crack complex passwords or use large wordlists, John the Ripper should be
|
|
|
|
used outside of Metasploit. This initial version just handles LM/NTLM credentials
|
|
|
|
from hashdump and uses the standard wordlist and rules.
|
|
|
|
},
|
2013-10-15 20:31:03 +00:00
|
|
|
'Author' => 'hdm',
|
|
|
|
'License' => MSF_LICENSE # JtR itself is GPLv2, but this wrapper is MSF (BSD)
|
2013-08-30 21:28:54 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
2014-06-23 19:40:32 +00:00
|
|
|
cracker = new_john_cracker
|
|
|
|
|
2014-07-21 23:24:35 +00:00
|
|
|
# generate our wordlist and close the file handle
|
2014-06-23 19:40:32 +00:00
|
|
|
wordlist = wordlist_file
|
|
|
|
wordlist.close
|
|
|
|
print_status "Wordlist file written out to #{wordlist.path}"
|
|
|
|
cracker.wordlist = wordlist.path
|
|
|
|
cracker.hash_path = hash_file
|
|
|
|
|
|
|
|
['lm','nt'].each do |format|
|
|
|
|
# dupe our original cracker so we can safely change options between each run
|
|
|
|
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
|
|
|
|
if datastore['KoreLogic']
|
|
|
|
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-23 19:40:32 +00:00
|
|
|
cracker_instance.crack do |line|
|
|
|
|
print_status line.chomp
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
|
2014-06-23 19:40:32 +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:26:12 +00:00
|
|
|
if format == 'lm'
|
2014-07-21 23:24:35 +00:00
|
|
|
print_status "Cracking #{format} hashes in incremental mode (All4)..."
|
2014-06-23 20:26:12 +00:00
|
|
|
cracker_instance.rules = nil
|
|
|
|
cracker_instance.wordlist = nil
|
2014-07-21 23:24:35 +00:00
|
|
|
cracker_instance.incremental = 'All4'
|
2014-06-23 20:26:12 +00:00
|
|
|
cracker_instance.crack do |line|
|
|
|
|
print_status line.chomp
|
|
|
|
end
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
|
2014-06-23 20:26:12 +00:00
|
|
|
print_status "Cracking #{format} hashes in incremental mode (Digits)..."
|
|
|
|
cracker_instance.rules = nil
|
|
|
|
cracker_instance.wordlist = nil
|
|
|
|
cracker_instance.incremental = 'Digits'
|
2014-06-23 19:40:32 +00:00
|
|
|
cracker_instance.crack do |line|
|
|
|
|
print_status line.chomp
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
|
2014-06-23 19:40:32 +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 >=7
|
|
|
|
username = fields.shift
|
|
|
|
core_id = fields.pop
|
2014-06-23 20:26:12 +00:00
|
|
|
|
|
|
|
# pop off dead space here
|
|
|
|
2.times{ fields.pop }
|
|
|
|
|
|
|
|
# get the NT and LM hashes
|
|
|
|
nt_hash = fields.pop
|
|
|
|
lm_hash = fields.pop
|
2014-06-23 19:40:32 +00:00
|
|
|
password = fields.join(':')
|
|
|
|
|
2014-06-23 20:26:12 +00:00
|
|
|
if format == 'lm'
|
2014-06-23 20:32:50 +00:00
|
|
|
if password.blank?
|
|
|
|
if nt_hash == Metasploit::Credential::NTLMHash::BLANK_NT_HASH
|
|
|
|
password = ''
|
|
|
|
else
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
2014-06-23 20:26:12 +00:00
|
|
|
password = john_lm_upper_to_ntlm(password, nt_hash)
|
2014-07-23 20:25:32 +00:00
|
|
|
# password can be nil if the hash is broken (i.e., the NT and
|
|
|
|
# LM sides don't actually match) or if john was only able to
|
|
|
|
# crack one half of the LM hash. In the latter case, we'll
|
|
|
|
# have a line like:
|
|
|
|
# username:???????WORD:...:...:::
|
|
|
|
next if password.nil?
|
2014-06-23 20:26:12 +00:00
|
|
|
end
|
|
|
|
|
2014-06-23 19:40:32 +00:00
|
|
|
print_good "#{username}:#{password}:#{core_id}"
|
2014-06-23 20:32:50 +00:00
|
|
|
create_cracked_credential( username: username, password: password, core_id: core_id)
|
2014-06-23 19:40:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-08-30 21:28:54 +00:00
|
|
|
|
2014-06-23 19:40:32 +00:00
|
|
|
def hash_file
|
|
|
|
hashlist = Rex::Quickfile.new("hashes_tmp")
|
|
|
|
Metasploit::Credential::NTLMHash.joins(:cores).where(metasploit_credential_cores: { workspace_id: myworkspace.id } ).each do |hash|
|
|
|
|
hash.cores.each do |core|
|
|
|
|
user = core.public.username
|
|
|
|
hash_string = "#{hash.data}"
|
|
|
|
id = core.id
|
|
|
|
hashlist.puts "#{user}:#{id}:#{hash_string}:::#{id}"
|
|
|
|
end
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2014-06-23 19:40:32 +00:00
|
|
|
hashlist.close
|
|
|
|
print_status "Hashes Written out to #{hashlist.path}"
|
|
|
|
hashlist.path
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2011-07-09 02:14:24 +00:00
|
|
|
end
|