1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-10-29 18:07:27 +01:00
This commit is contained in:
sinn3r 2015-01-15 15:13:03 -06:00
parent c3bb02081b
commit 35c808d70f

View File

@ -69,6 +69,10 @@ module Md5LookupUtility
# @return [String] The output file path (to save the cracked MD5 results)
attr_accessor :out_file
# @!attribute databases
# @return [Array] The database names recognized by md5cracker.org
attr_accessor :databases
def initialize(opts={})
self.rhost = 'md5cracker.org'
self.rport = 80
@ -85,12 +89,14 @@ module Md5LookupUtility
include Msf::Exploit::Remote::HttpClient
def initialize(opts={})
config = Md5LookupUtility::Config.new
super(
'DefaultOptions' =>
{
'SSL' => false, # Doesn't look like md5cracker.org supports HTTPS
'RHOST' => resolve_host(Md5LookupUtility::Config.rhost),
'RPORT' => Md5LookupUtility::Config.rport
'RHOST' => resolve_host(config.rhost),
'RPORT' => config.rport
}
)
end
@ -99,12 +105,7 @@ module Md5LookupUtility
# Returns the look up HTTP response
# @param md5_hash [String] The MD5 hash to lookup
# @param db_names [String] The databases check
# @raise [RuntimeError] If the MD5 hash is bullshit
def lookup(md5_hash, db_names)
if !is_md5_format?(md5_hash)
raise RuntimeError, "Not a valid MD5 hash: #{md5_hash}"
end
send_request_cgi({
'uri' => Md5LookupUtility::Config.target_uri,
'method' => 'GET',
@ -122,14 +123,6 @@ module Md5LookupUtility
Rex::Socket.resolv_to_dotted(host) rescue '144.76.226.137'
end
# Checks if the hash format is MD5 or not
# @param md5_hash [String] The MD5 hash (hex)
# @return [TrueClass/FlaseClass] True if the format is valid, otherwise false
def is_md5_format?(md5_hash)
(md5_hash =~ /^[a-f0-9]{32}$/i) ? true : false
end
end
@ -252,7 +245,7 @@ module Md5LookupUtility
end
# This class is the driver
# This class decides how this process works
class Driver
def initialize
begin
@ -263,8 +256,41 @@ module Md5LookupUtility
end
end
def run
# Main function
def run
input = @opts[:input]
dbs = @opts[:databases]
get_hash_results(input) do |result|
original_hash = result[:hash]
cracked_hash = result[:cracked_hash]
end
end
private
# Returns the hash results by actually invoking Md5Lookup
def get_hash_results(input)
search_engine = Md5LookupUtility::Md5Lookup.new
extract_hashes(input) do |hash|
$stderr.puts hash.inspect
end
end
# Extracts all the MD5 hashes one by one
def extract_hashes(input_file)
::File.open(input_file, 'rb').each_line do |hash|
next if !is_md5_format?(hash)
yield hash.strip # Make sure no newlines
end
end
# Checks if the hash format is MD5 or not
# @param md5_hash [String] The MD5 hash (hex)
# @return [TrueClass/FlaseClass] True if the format is valid, otherwise false
def is_md5_format?(md5_hash)
(md5_hash =~ /^[a-f0-9]{32}$/i) ? true : false
end
end