Merge branch 'feature/MSP-9715/linux_hashcracker' into staging/electro-release

bug/bundler_fix
James Lee 2014-06-25 16:15:44 -05:00
commit 48e93b7fc2
No known key found for this signature in database
GPG Key ID: 2D6094C7CEA0A321
1 changed files with 46 additions and 60 deletions

View File

@ -5,6 +5,7 @@
require 'msf/core' require 'msf/core'
require 'msf/core/auxiliary/jtr'
class Metasploit3 < Msf::Auxiliary class Metasploit3 < Msf::Auxiliary
@ -36,77 +37,62 @@ class Metasploit3 < Msf::Auxiliary
end end
def run def run
@wordlist = Rex::Quickfile.new("jtrtmp")
begin formats = [ 'md5', 'des', 'bsdi']
@wordlist.write( build_seed().join("\n") + "\n" ) if datastore['Crypt']
ensure format << 'crypt'
@wordlist.close
end end
myloots = myworkspace.loots.where('ltype=?', 'linux.hashes') cracker = new_john_cracker
return if myloots.nil? or myloots.empty?
build_hashlist(myloots) #generate our wordlist and close the file handle
wordlist = wordlist_file
wordlist.close
print_status "Wordlist file written out to #{wordlist.path}"
cracker.wordlist = wordlist.path
cracker.hash_path = hash_file
print_status("HashList: #{@hashlist.path}") formats.each do |format|
# dupe our original cracker so we can safely change options between each run
try('md5') cracker_instance = cracker.dup
try('des') cracker_instance.format = format
try('bsdi') print_status "Cracking #{format} hashes in normal wordlist mode..."
try('crypt') if datastore['Crypt'] cracker_instance.crack do |line|
print_status line.chomp
cracked = john_show_passwords(@hashlist.path) end
print_status("#{cracked[:cracked]} hashes were cracked!") print_status "Cracked Passwords this run:"
cracker_instance.each_cracked_password do |password_line|
cracked[:users].each_pair do |k,v| password_line.chomp!
if v[0] == "NO PASSWORD" next if password_line.blank?
passwd="" fields = password_line.split(":")
else # If we don't have an expected minimum number of fields, this is probably not a hash line
passwd=v[0] next unless fields.count >=7
username = fields.shift
core_id = fields.pop
4.times { 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 end
print_good("Host: #{v.last} User: #{k} Pass: #{passwd}")
report_auth_info(
:host => v.last,
:port => 22,
:sname => 'ssh',
:user => k,
:pass => passwd
)
end end
end end
def try(format) def hash_file
print_status("Trying Format:#{format} Wordlist: #{@wordlist.path}") hashlist = Rex::Quickfile.new("hashes_tmp")
john_crack(@hashlist.path, :wordlist => @wordlist.path, :rules => 'single', :format => format) Metasploit::Credential::NonreplayableHash.joins(:cores).where(metasploit_credential_cores: { workspace_id: myworkspace.id }, jtr_format: 'md5,des,bsdi,crypt').each do |hash|
print_status("Trying Format:#{format} Rule: All4...") hash.cores.each do |core|
john_crack(@hashlist.path, :incremental => "All4", :format => format) user = core.public.username
print_status("Trying Format:#{format} Rule: Digits5...") hash_string = "#{hash.data}"
john_crack(@hashlist.path, :incremental => "Digits5", :format => format) id = core.id
end hashlist.puts "#{user}:#{hash_string}:::::#{id}:"
def build_hashlist(myloots)
loot_data = []
myloots.each do |myloot|
usf = ''
begin
File.open(myloot.path, "rb") do |f|
usf = f.read(f.stat.size)
end
rescue Exception => e
print_error("Unable to read #{myloot.path} \n #{e}")
end
usf.each_line do |row|
row.gsub!("\n", ":#{myloot.host.address}\n")
loot_data << row
end end
end end
hashlist.close
@hashlist = Rex::Quickfile.new("jtrtmp") print_status "Hashes Written out to #{hashlist.path}"
@hashlist.write(loot_data.join) hashlist.path
@hashlist.close
end end
end end