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.
Instance Attribute Summary collapse
-
#dictionary ⇒ String
Path to dictionary file.
-
#file ⇒ String
(also: #etc)
Path to the /etc/passwd file.
Instance Method Summary collapse
-
#check_password(encrypted_password, plaintext_password, strip = true) ⇒ 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 = {}) {|Hash| ... } ⇒ Object
(also: #crack, #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.
34 35 36 37 |
# File 'lib/violent_ruby/unix_password_cracker/unix_password_cracker.rb', line 34 def initialize(args = {}) @file = args[:file] if args[:file] @dictionary = args[:dictionary] if args[:dictionary] end |
Instance Attribute Details
#dictionary ⇒ String
Returns Path to dictionary file.
23 24 25 |
# File 'lib/violent_ruby/unix_password_cracker/unix_password_cracker.rb', line 23 def dictionary @dictionary end |
#file ⇒ String Also known as: etc
Returns Path to the /etc/passwd file.
19 20 21 |
# File 'lib/violent_ruby/unix_password_cracker/unix_password_cracker.rb', line 19 def file @file end |
Instance Method Details
#check_password(encrypted_password, plaintext_password, strip = true) ⇒ 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.
142 143 144 145 146 147 148 149 |
# File 'lib/violent_ruby/unix_password_cracker/unix_password_cracker.rb', line 142 def check_password(encrypted_password, plaintext_password, strip = true) plaintext_password.strip! if strip # sometimes passwords have trailing spaces if plaintext_password.crypt(encrypted_password[0, 2]) == encrypted_password true else false end end |
#crack_passwords(args = {}) {|Hash| ... } ⇒ Object Also known as: crack, crack!, get_crackn, release_the_kraken
Crack unix passwords.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# 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) else yield format_result(user, password) end end end end |
#parse_etc_file(args = {}) ⇒ Hash
Parse a unix /etc/passwd file into a more mangeable form.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/violent_ruby/unix_password_cracker/unix_password_cracker.rb', line 59 def parse_etc_file(args = {}) # Readlines from /etc/passwd file. lines = File.readlines(args[:file]).collect do |line| line unless line.split(':').first.chars.first.include?('#') end # Collect the users and passwords from the lines. users = lines.collect { |x| x.split(':')[0] }.map(&:strip) passwords = lines.collect { |x| x.split(':')[1] }.map(&:strip) # Friendly behavior to return just users or passwords. return users if args[:users] return passwords if args[:passwords] # Zip'm together into a hash. users_passwords = Hash[users.zip(passwords)] # Yield each pair when a block is given, or return all at once. if block_given? users_passwords.each do |user, password| yield user, password end else users_passwords end end |