Method: ViolentRuby::UnixPasswordCracker#crack_passwords

Defined in:
lib/violent_ruby/unix_password_cracker/unix_password_cracker.rb

#crack_passwords(args = {}) {|Hash| ... } ⇒ Object Also known as: crack, crack!, get_crackn, release_the_kraken

Crack unix passwords.

Examples:

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

Parameters:

  • args (Hash) (defaults to: {})

    The options when crack’n some passwords.

Options Hash (args):

  • :file (String)

    The path to an /etc/passwd file.

  • :dictionary (String)

    The path to a dictionry of passwords.

Yields:

  • (Hash)


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/violent_ruby/unix_password_cracker/unix_password_cracker.rb', line 99

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)
        break
      else
        yield format_result(user, password)
      end
    end
  end
end