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.
-
#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 |
#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.
99 100 101 |
# File 'lib/ronin/db/credential.rb', line 99 def self.for_user(name) joins(:user_name).where(user_name: {name: name}) end |
.import(cred) ⇒ Credential
Imports the given credential.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/ronin/db/credential.rb', line 184 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.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/ronin/db/credential.rb', line 158 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.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ronin/db/credential.rb', line 118 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.
144 145 146 |
# File 'lib/ronin/db/credential.rb', line 144 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.
224 225 226 |
# File 'lib/ronin/db/credential.rb', line 224 def plain_text self.password.plain_text if self.password end |
#to_s ⇒ String
Converts the credentials to a String.
236 237 238 |
# File 'lib/ronin/db/credential.rb', line 236 def to_s "#{self.user_name}:#{self.password}" end |
#user ⇒ String
The user the credential belongs to.
212 213 214 |
# File 'lib/ronin/db/credential.rb', line 212 def user self.user_name.name if self.user_name end |