Class: Ronin::DB::Credential
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Ronin::DB::Credential
- Includes:
- Model, Model::Importable
- Defined in:
- lib/ronin/db/credential.rb
Overview
Represents Credentials used to access services or websites.
Instance Attribute Summary collapse
-
#email_address ⇒ EmailAddress?
The optional email address associated with the Credential.
-
#id ⇒ Integer
Primary key of the credential.
-
#notes ⇒ Array<Note>
The associated notes.
-
#open_ports ⇒ Array<OpenPort>
The open ports that accept this credential pair.
-
#password ⇒ Password
Password of the credential.
-
#service_credentials ⇒ Array<ServiceCredential>
The service credentials.
-
#urls ⇒ Array<URL>
The URLs that accept this credential pair.
-
#user_name ⇒ UserName?
User name of the credential.
-
#web_credentials ⇒ Array<WebCredential>
The Web credentials.
Class Method Summary collapse
-
.for_user(name) ⇒ Array<Credential>
Searches for all credentials for a specific user.
-
.import(cred) ⇒ Credential
Imports the given credential.
-
.lookup(cred) ⇒ Credential?
Looks up the given credential.
-
.with_email_address(email) ⇒ Array<WebCredential>
Searches all web credentials that are associated with an email address.
-
.with_password(password) ⇒ Array<Credential>
Searches for all credentials with a common password.
Instance Method Summary collapse
-
#plain_text ⇒ String
The clear-text password of the credential.
-
#to_s ⇒ String
Converts the credentials to a String.
-
#user ⇒ String
The user the credential belongs to.
Methods included from Model::Importable
Methods included from Model
Instance Attribute Details
#email_address ⇒ EmailAddress?
The optional email address associated with the Credential
54 |
# File 'lib/ronin/db/credential.rb', line 54 belongs_to :email_address, optional: true |
#id ⇒ Integer
Primary key of the credential.
40 |
# File 'lib/ronin/db/credential.rb', line 40 attribute :id, :integer |
#notes ⇒ Array<Note>
The associated notes.
94 |
# File 'lib/ronin/db/credential.rb', line 94 has_many :notes, dependent: :destroy |
#open_ports ⇒ Array<OpenPort>
The open ports that accept this credential pair.
74 |
# File 'lib/ronin/db/credential.rb', line 74 has_many :open_ports, through: :service_credentials |
#password ⇒ Password
Password of the credential.
62 |
# File 'lib/ronin/db/credential.rb', line 62 belongs_to :password, required: true |
#service_credentials ⇒ Array<ServiceCredential>
The service credentials.
68 |
# File 'lib/ronin/db/credential.rb', line 68 has_many :service_credentials, dependent: :destroy |
#urls ⇒ Array<URL>
The URLs that accept this credential pair.
86 |
# File 'lib/ronin/db/credential.rb', line 86 has_many :urls, through: :web_credentials |
#user_name ⇒ UserName?
User name of the credential.
46 |
# File 'lib/ronin/db/credential.rb', line 46 belongs_to :user_name, optional: true |
#web_credentials ⇒ Array<WebCredential>
The Web credentials.
80 |
# File 'lib/ronin/db/credential.rb', line 80 has_many :web_credentials, dependent: :destroy |
Class Method Details
.for_user(name) ⇒ Array<Credential>
Searches for all credentials for a specific user.
107 108 109 |
# File 'lib/ronin/db/credential.rb', line 107 def self.for_user(name) joins(:user_name).where(user_name: {name: name}) end |
.import(cred) ⇒ Credential
Imports the given credential.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/ronin/db/credential.rb', line 192 def self.import(cred) unless cred.include?(':') raise(ArgumentError,"credential must be of the form user:password or email:password: #{cred.inspect}") end user_or_email, password = cred.split(':',2) if user_or_email.include?('@') create( email_address: EmailAddress.find_or_import(user_or_email), password: Password.find_or_import(password) ) else create( user_name: UserName.find_or_import(user_or_email), password: Password.find_or_import(password) ) end end |
.lookup(cred) ⇒ Credential?
Looks up the given credential.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/ronin/db/credential.rb', line 166 def self.lookup(cred) unless cred.include?(':') raise(ArgumentError,"credential must be of the form user:password or email:password: #{cred.inspect}") end user_or_email, password = cred.split(':',2) query = if user_or_email.include?('@') with_email_address(user_or_email) else for_user(user_or_email) end query.with_password(password) return query.first end |
.with_email_address(email) ⇒ Array<WebCredential>
Searches all web credentials that are associated with an email address.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ronin/db/credential.rb', line 126 def self.with_email_address(email) unless email.include?('@') raise(ArgumentError,"invalid email address #{email.inspect}") end user, domain = email.split('@',2) return joins(email_address: [:user_name, :host_name]).where( email_address: { ronin_user_names: {name: user}, ronin_host_names: {name: domain} } ) end |
.with_password(password) ⇒ Array<Credential>
Searches for all credentials with a common password.
152 153 154 |
# File 'lib/ronin/db/credential.rb', line 152 def self.with_password(password) joins(:password).where(password: {plain_text: password}) end |
Instance Method Details
#plain_text ⇒ String
The clear-text password of the credential.
232 233 234 |
# File 'lib/ronin/db/credential.rb', line 232 def plain_text self.password.plain_text if self.password end |
#to_s ⇒ String
Converts the credentials to a String.
244 245 246 |
# File 'lib/ronin/db/credential.rb', line 244 def to_s "#{self.user_name}:#{self.password}" end |
#user ⇒ String
The user the credential belongs to.
220 221 222 |
# File 'lib/ronin/db/credential.rb', line 220 def user self.user_name.name if self.user_name end |