Class: ViolentRuby::UnixPasswordCracker
- Inherits:
-
Object
- Object
- ViolentRuby::UnixPasswordCracker
- Defined in:
- lib/violent_ruby/unix_password_cracker/unix_password_cracker.rb
Overview
Unix Password Cracker provides a friendly interface to crack unix passwords. Because all hackers totes do this.
Create a new Unix Password Cracker
In order for the password cracker to work, we’re going to need a dictionary, and an /etc/passwd file we want to crack.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#check_password(encrypted_password, word) ⇒ Boolean
(also: #cracked?)
Check if a given encrypted password matches a given plaintext word when the same crytographic operation is performed on it.
-
#crack_passwords(args = {}) ⇒ Array<Hash>
(also: #crack!, #get_crackn, #release_the_kraken)
Crack unix passwords.
-
#initialize(args = {}) ⇒ UnixPasswordCracker
constructor
Create a new Unix Password Cracker.
-
#parse_etc_file(args = {}) ⇒ Hash
Parse a unix /etc/passwd file into a more mangeable form.
Constructor Details
#initialize(args = {}) ⇒ UnixPasswordCracker
Create a new Unix Password Cracker.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/violent_ruby/unix_password_cracker/unix_password_cracker.rb', line 25 def initialize(args = {}) @file = false @dictionary = false if args[:file] && File.readable?(args[:file]) @file = args[:file] @credentials = parse_etc_file(file: args[:file]) end return unless args[:dictionary] return unless File.readable?(args[:dictionary]) @dictionary = args[:dictionary] end |
Instance Attribute Details
#dictionary ⇒ Object
18 19 20 |
# File 'lib/violent_ruby/unix_password_cracker/unix_password_cracker.rb', line 18 def dictionary @dictionary end |
#file ⇒ Object
16 17 18 |
# File 'lib/violent_ruby/unix_password_cracker/unix_password_cracker.rb', line 16 def file @file end |
Instance Method Details
#check_password(encrypted_password, word) ⇒ Boolean Also known as: cracked?
Check if a given encrypted password matches a given plaintext word when the same crytographic operation is performed on it.
94 95 96 97 98 99 100 |
# File 'lib/violent_ruby/unix_password_cracker/unix_password_cracker.rb', line 94 def check_password(encrypted_password, word) if word.strip.crypt(encrypted_password[0, 2]) == encrypted_password true else false end end |
#crack_passwords(args = {}) ⇒ Array<Hash> Also known as: crack!, get_crackn, release_the_kraken
Crack unix passwords.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/violent_ruby/unix_password_cracker/unix_password_cracker.rb', line 70 def crack_passwords(args = {}) file = args[:file] || @file dict = args[:dictionary] || @dictionary results = [] parse_etc_file(file: file) do |user, password| File.readlines(dict).map(&:strip).each do |word| results << format_result(user, password, word) if cracked?(password, word) end end results end |
#parse_etc_file(args = {}) ⇒ Hash
Parse a unix /etc/passwd file into a more mangeable form.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/violent_ruby/unix_password_cracker/unix_password_cracker.rb', line 44 def parse_etc_file(args = {}) raise 'No /etc/passwd file given.' unless args[:file] raise "File #{args[:file]} not readable!" unless File.readable?(args[:file]) lines = File.readlines(args[:file]).collect do |line| line unless line.split(':').first.chars.first.include?('#') end users = lines.collect { |x| x.split(':')[0] }.map(&:strip) return users if args[:users] passwords = lines.collect { |x| x.split(':')[1] }.map(&:strip) return passwords if args[:passwords] users_passwords = Hash[users.zip(passwords)] if block_given? users_passwords.each do |user, password| yield user, password end else users_passwords end end |