Class: Ronin::DB::Password

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Model, Model::Importable
Defined in:
lib/ronin/db/password.rb

Overview

Represents a password used by services or websites.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model::Importable

included

Methods included from Model

included

Instance Attribute Details

#credentialsArray<Credential>

The credentials which use the password.

Returns:



54
# File 'lib/ronin/db/password.rb', line 54

has_many :credentials, dependent: :destroy

#idInteger

The primary key of the password.

Returns:

  • (Integer)


41
# File 'lib/ronin/db/password.rb', line 41

attribute :id, :integer

#plain_textString

The clear-text of the password.

Returns:

  • (String)


47
# File 'lib/ronin/db/password.rb', line 47

attribute :plain_text, :string

#user_namesArray<UserName>

The user names which use the password.

Returns:



60
# File 'lib/ronin/db/password.rb', line 60

has_many :user_names, through: :credentials

Class Method Details

.import(password) ⇒ Password

Parses a password.

Parameters:

  • password (#to_s)

    The password to import.

Returns:



88
89
90
# File 'lib/ronin/db/password.rb', line 88

def self.import(password)
  create(plain_text: password.to_s)
end

.lookup(password) ⇒ Password?

Looks up the password.

Parameters:

  • password (#to_s)

    The password to lookup.

Returns:

  • (Password, nil)

    The found password.



73
74
75
# File 'lib/ronin/db/password.rb', line 73

def self.lookup(password)
  find_by(plain_text: password.to_s)
end

Instance Method Details

#countInteger

The number of credentials which use this password.

Returns:

  • (Integer)

    The number of credentials that use the password.



147
148
149
# File 'lib/ronin/db/password.rb', line 147

def count
  self.credentials.count
end

#digest(algorithm, prepend_salt: nil, append_salt: nil) ⇒ String

Hashes the password.

Examples:

pass = Password.new(plain_text: 'secret')

pass.digest(:sha1)
# => "e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4"

pass.digest(:sha1, prepend_salt: "A\x90\x00")
# => "e2817656a48c49f24839ccf9295b389d8f985904"

pass.digest(:sha1, append_salt: "BBBB")
# => "aa6ca21e446d425fc044bbb26e950a788444a5b8"

Parameters:

  • algorithm (Symbol, String)

    The digest algorithm to use.

  • prepend_salt (String, nil) (defaults to: nil)

    The salt data to prepend to the password.

  • append_salt (String, nil) (defaults to: nil)

    The salt data to append to the password.

Returns:

  • (String)

    The hex-digest of the hashed password.

Raises:

  • (ArgumentError)

    Unknown Digest algorithm.



124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/ronin/db/password.rb', line 124

def digest(algorithm, prepend_salt: nil, append_salt: nil)
  digest_class = begin
                   Digest.const_get(algorithm.upcase)
                 rescue LoadError
                   raise(ArgumentError,"Unknown Digest algorithm #{algorithm}")
                 end

  hash = digest_class.new
  hash << prepend_salt.to_s if prepend_salt
  hash << self.plain_text
  hash << append_salt.to_s if append_salt

  return hash.hexdigest
end

#to_sString

Converts the password into a String.

Returns:

  • (String)

    The clear-text of the password.



159
160
161
# File 'lib/ronin/db/password.rb', line 159

def to_s
  self.plain_text
end