Skip to content

Commit

Permalink
Make the add_equals_to_base64 function private
Browse files Browse the repository at this point in the history
  • Loading branch information
smcintyre-r7 committed Oct 10, 2023
1 parent 59da286 commit 47b0c01
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions lib/metasploit/framework/password_crackers/hashcat/formatter.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
# This method takes a string which is likely base64 encoded
# however, there is an arbitrary amount of = missing from the end
# so we attempt to add = until we are able to decode it
#
# @param str [String] the base64-ish string
# @return [String] the corrected string
private
def add_equals_to_base64(str)
['', '=', '=='].each do |equals|
begin
to_test = "#{str}#{equals}"
Base64.strict_decode64(to_test)
return to_test
rescue ArgumentError
nil
end
end
nil
end


# This method takes a {framework.db.cred}, and normalizes it
# to the string format hashcat is expecting.
# https://hashcat.net/wiki/doku.php?id=example_hashes
Expand Down Expand Up @@ -66,6 +45,24 @@ def hash_to_hashcat(cred)

# https://hashcat.net/forum/thread-7854-post-42417.html#pid42417 ironically gives Token encoding exception
c = cred.private.data.sub('$pbkdf2-sha256', 'sha256').split('$')

# This method takes a string which is likely base64 encoded
# however, there is an arbitrary amount of = missing from the end
# so we attempt to add = until we are able to decode it
#
# @param str [String] the base64-ish string
# @return [String] the corrected string
def add_equals_to_base64(str)
['', '=', '=='].each do |equals|
to_test = "#{str}#{equals}"
Base64.strict_decode64(to_test)
return to_test
rescue ArgumentError
next
end
nil
end

c[2] = add_equals_to_base64(c[2].gsub('.', '+')) # pad back out
c[3] = add_equals_to_base64(c[3].gsub('.', '+')) # pad back out
return c.join(':')
Expand Down Expand Up @@ -132,8 +129,6 @@ def hash_to_hashcat(cred)
when /^krb5$/
return cred.private.data.to_s
end


end
nil
end

0 comments on commit 47b0c01

Please sign in to comment.