2011-10-26 23:31:12 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/framework/
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'digest/md5'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
|
|
|
#Included to grab the john.pot and use some utiltiy functions
|
|
|
|
include Msf::Auxiliary::JohnTheRipper
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
2011-10-26 23:31:12 +00:00
|
|
|
'Name' => 'Postgres SQL md5 Password Cracker',
|
2011-10-26 23:38:18 +00:00
|
|
|
'Version' => '$Revision$',
|
2011-10-26 23:31:12 +00:00
|
|
|
'Description' => %Q{
|
2011-10-26 22:34:33 +00:00
|
|
|
This module attempts to crack Postgres SQL md5 password hashes.
|
2011-11-20 02:12:07 +00:00
|
|
|
It creates hashes based on information saved in the MSF Database
|
2011-11-05 15:43:28 +00:00
|
|
|
such as hostnames, usernames, passwords, and database schema information.
|
2011-10-26 23:31:12 +00:00
|
|
|
The user can also supply an additional external wordlist if they wish.
|
2011-10-26 22:34:33 +00:00
|
|
|
},
|
2011-10-26 23:31:12 +00:00
|
|
|
'Author' => ['TheLightCosine <thelightcosine[at]gmail.com>'],
|
|
|
|
'License' => MSF_LICENSE
|
2011-10-26 22:34:33 +00:00
|
|
|
)
|
2011-11-20 02:12:07 +00:00
|
|
|
|
2011-10-26 23:31:12 +00:00
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptPath.new('Wordlist', [false, 'The path to an optional Wordlist']),
|
|
|
|
OptBool.new('Munge',[false, 'Munge the Wordlist (Slower)', false])
|
|
|
|
])
|
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
deregister_options('JOHN_BASE','JOHN_PATH')
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
2011-10-26 23:31:12 +00:00
|
|
|
|
|
|
|
print_status("Processing wordlist...")
|
2011-10-26 22:34:33 +00:00
|
|
|
@seed= build_seed()
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
print_status("Wordlist length: #{@seed.length}")
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
myloots = myworkspace.loots.find(:all, :conditions => ['ltype=?', 'postgres.hashes'])
|
|
|
|
unless myloots.nil?
|
|
|
|
myloots.each do |myloot|
|
|
|
|
begin
|
|
|
|
postgres_array = CSV.read(myloot.path).drop(1)
|
2011-11-20 02:12:07 +00:00
|
|
|
rescue
|
2011-10-26 22:34:33 +00:00
|
|
|
print_error("Unable to process #{myloot.path}")
|
|
|
|
end
|
|
|
|
postgres_array.each do |row|
|
|
|
|
print_status("Attempting to crack hash: #{row[0]}:#{row[1]}")
|
|
|
|
password = crack_hash(row[0],row[1])
|
|
|
|
if password
|
|
|
|
print_good("Username: #{row[0]} Pass: #{password}")
|
|
|
|
report_auth_info(
|
|
|
|
:host => myloot.host.address,
|
|
|
|
:port => myloot.service.port,
|
|
|
|
:sname => 'postgres',
|
|
|
|
:user => row[0],
|
|
|
|
:pass => password
|
|
|
|
)
|
2011-11-20 02:12:07 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
end
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
def crack_hash(username,hash)
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
@seed.each do |word|
|
|
|
|
tmphash = Digest::MD5.hexdigest("#{word}#{username}")
|
|
|
|
if tmphash == hash
|
|
|
|
return word
|
|
|
|
end
|
|
|
|
end
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
return nil
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
end
|
2011-10-26 23:31:12 +00:00
|
|
|
|
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
def build_seed
|
2011-10-26 23:31:12 +00:00
|
|
|
|
|
|
|
seed = []
|
2011-10-26 22:34:33 +00:00
|
|
|
#Seed the wordlist with Database , Table, and Instance Names
|
|
|
|
schemas = myworkspace.notes.find(:all, :conditions => ['ntype like ?', '%.schema%'])
|
|
|
|
unless schemas.nil? or schemas.empty?
|
|
|
|
schemas.each do |anote|
|
|
|
|
anote.data.each do |key,value|
|
|
|
|
seed << key
|
|
|
|
value.each{|a| seed << a}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
instances = myworkspace.notes.find(:all, :conditions => ['ntype=?', 'mssql.instancename'])
|
|
|
|
unless instances.nil? or instances.empty?
|
|
|
|
instances.each do |anote|
|
|
|
|
seed << anote.data['InstanceName']
|
|
|
|
end
|
|
|
|
end
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
# Seed the wordlist with usernames, passwords, and hostnames
|
|
|
|
|
|
|
|
myworkspace.hosts.find(:all).each {|o| seed << john_expand_word( o.name ) if o.name }
|
2011-11-20 02:12:07 +00:00
|
|
|
myworkspace.creds.each do |o|
|
2011-10-26 22:34:33 +00:00
|
|
|
seed << john_expand_word( o.user ) if o.user
|
|
|
|
seed << john_expand_word( o.pass ) if (o.pass and o.ptype !~ /hash/)
|
|
|
|
end
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
# Grab any known passwords out of the john.pot file
|
|
|
|
john_cracked_passwords.values {|v| seed << v }
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
#Grab the default John Wordlist
|
2011-11-28 23:52:34 +00:00
|
|
|
john = File.open(john_wordlist_path, "rb")
|
2011-10-26 22:34:33 +00:00
|
|
|
john.each_line{|line| seed << line.chomp}
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
if datastore['Wordlist']
|
2011-11-28 23:52:34 +00:00
|
|
|
wordlist= File.open(datastore['Wordlist'], "rb")
|
2011-10-26 22:34:33 +00:00
|
|
|
wordlist.each_line{|line| seed << line.chomp}
|
|
|
|
end
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
unless seed.empty?
|
|
|
|
seed.flatten!
|
|
|
|
seed.uniq!
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
if datastore['Munge']
|
|
|
|
mungedseed=[]
|
|
|
|
seed.each do |word|
|
2011-11-20 02:12:07 +00:00
|
|
|
munged = word.gsub(/[sS]/, "$").gsub(/[aA]/,"@").gsub(/[oO]/,"0")
|
2011-10-26 22:34:33 +00:00
|
|
|
mungedseed << munged
|
|
|
|
munged.gsub!(/[eE]/, "3")
|
|
|
|
munged.gsub!(/[tT]/, "7")
|
|
|
|
mungedseed << munged
|
|
|
|
end
|
|
|
|
seed << mungedseed
|
|
|
|
seed.flatten!
|
|
|
|
seed.uniq!
|
|
|
|
end
|
|
|
|
end
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
return seed
|
|
|
|
end
|
2011-10-26 23:31:12 +00:00
|
|
|
|
2011-10-26 22:34:33 +00:00
|
|
|
end
|