Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save picatz/266a2d6af0c4406c6da7a34e38edb0b9 to your computer and use it in GitHub Desktop.
Save picatz/266a2d6af0c4406c6da7a34e38edb0b9 to your computer and use it in GitHub Desktop.
Violent Ruby: Unix Password Cracker Crack Unix Passwords Method
# Crack unix passwords.
#
# @example Basic Usage
# ViolentRuby::UnixPasswordCracker.new(file: "passwords.txt", dictionary: "dictionary.txt").crack_passwords do |result|
# next unless result[:cracked]
# puts "Cracked #{result[:username]}'s password: #{result[:plaintext_password]}"
# end
#
# @param args [Hash] The options when crack'n some passwords.
# @option args [String] :file The path to an /etc/passwd file.
# @option args [String] :dictionary The path to a dictionry of passwords.
#
# @yield [Hash]
def crack_passwords(args = {})
# Use the file and dictionry instance variables or the arguments.
file = args[:file] || @file
dict = args[:dictionary] || @dictionary
# Parse the given /etc/passwd file and compare with the dictionary.
parse_etc_file(file: file) do |user, password|
File.readlines(dict).map(&:strip).each do |word|
if cracked?(password, word)
yield format_result(user, password, word)
else
yield format_result(user, password)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment