Class: Metasploit::Credential::Core
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Metasploit::Credential::Core
- Includes:
- Model::Search
- Defined in:
- app/models/metasploit/credential/core.rb
Overview
Instance Attribute Summary collapse
-
#created_at ⇒ DateTime
When this core credential was created.
-
#logins ⇒ ActiveRecord::Relation<Metasploit::Credential::Login>
The logins using this core credential to log into a service.
-
#origin ⇒ Metasploit::Credential::Origin::Import, ...
The origin of this core credential.
-
#private ⇒ Metasploit::Credential::Private?
The Private either gathered from #realm or used to authenticate to the realm.
- #public ⇒ Metasploit::Credential::Public?
- #realm ⇒ Metasploit::Credential::Realm?
-
#tasks ⇒ ActiveRecord::Relation<Mdm::Task>
The tasks using this to track what tasks interacted with a given core.
-
#updated_at ⇒ DateTime
When this core credential was last updated.
-
#workspace ⇒ Mdm::Workspace
The ‘Mdm::Workspace` to which this core credential is scoped.
Class Method Summary collapse
-
.cores_from_host_sql(host_id) ⇒ String
Wrapper to provide raw SQL string UNIONing cores from a host via service origins or via session origins.
Instance Method Summary collapse
-
#login_host_id(host_id) ⇒ ActiveRecord::Relation
Finds Cores that have successfully logged into a given host.
-
#origin_service_host_id(host_id) ⇒ ActiveRecord::Relation
Finds Cores that have an origin_type of Service and are attached to the given host.
-
#origin_session_host_id(host_id) ⇒ ActiveRecord::Relation
Finds Cores that have an origin_type of Session that were collected from the given host.
-
#originating_host_id ⇒ ActiveRecord::Relation
Finds all Cores that have been collected in some way from a Host.
-
#origins(origin_class) ⇒ ActiveRecord::Relation
JOINs in origins of a specific type.
-
#services_hosts ⇒ ActiveRecord::Relation
Adds a JOIN for the Service and Host that a Core with an Origin type of Service would have.
-
#sessions_hosts ⇒ ActiveRecord::Relation
Adds a JOIN for the Session and Host that a Core with an Origin type of Session would have.
-
#with_logins ⇒ ActiveRecord::Relation
Eager loads Login objects associated to Cores.
-
#with_private ⇒ ActiveRecord::Relation
Eager loads Private objects associated to Cores.
-
#with_public ⇒ ActiveRecord::Relation
Eager loads Public objects associated to Cores.
-
#with_realm ⇒ ActiveRecord::Relation
Eager loads Realm objects associated to Cores.
-
#workspace_id(id) ⇒ ActiveRecord::Relation
Finds Cores that are attached to a given workspace.
Instance Attribute Details
#created_at ⇒ DateTime
When this core credential was created.
|
# File 'app/models/metasploit/credential/core.rb', line 86
|
#logins ⇒ ActiveRecord::Relation<Metasploit::Credential::Login>
The logins using this core credential to log into a service.
26 27 28 29 |
# File 'app/models/metasploit/credential/core.rb', line 26 has_many :logins, class_name: 'Metasploit::Credential::Login', dependent: :destroy, inverse_of: :core |
#origin ⇒ Metasploit::Credential::Origin::Import, ...
The origin of this core credential.
44 45 |
# File 'app/models/metasploit/credential/core.rb', line 44 belongs_to :origin, polymorphic: true |
#private ⇒ Metasploit::Credential::Private?
The Private either gathered from #realm or used to authenticate to the realm.
52 53 54 |
# File 'app/models/metasploit/credential/core.rb', line 52 belongs_to :private, class_name: 'Metasploit::Credential::Private', inverse_of: :cores |
#public ⇒ Metasploit::Credential::Public?
60 61 62 |
# File 'app/models/metasploit/credential/core.rb', line 60 belongs_to :public, class_name: 'Metasploit::Credential::Public', inverse_of: :cores |
#realm ⇒ Metasploit::Credential::Realm?
69 70 71 |
# File 'app/models/metasploit/credential/core.rb', line 69 belongs_to :realm, class_name: 'Metasploit::Credential::Realm', inverse_of: :cores |
#tasks ⇒ ActiveRecord::Relation<Mdm::Task>
The tasks using this to track what tasks interacted with a given core.
17 18 19 20 |
# File 'app/models/metasploit/credential/core.rb', line 17 has_and_belongs_to_many :tasks, class_name: "Mdm::Task", join_table: "credential_cores_tasks", uniq: true |
#updated_at ⇒ DateTime
When this core credential was last updated.
|
# File 'app/models/metasploit/credential/core.rb', line 91
|
#workspace ⇒ Mdm::Workspace
The ‘Mdm::Workspace` to which this core credential is scoped. Used to limit mixing of different networks credentials.
78 79 80 |
# File 'app/models/metasploit/credential/core.rb', line 78 belongs_to :workspace, class_name: 'Mdm::Workspace', inverse_of: :core_credentials |
Class Method Details
.cores_from_host_sql(host_id) ⇒ String
Wrapper to provide raw SQL string UNIONing cores from a host via service origins or via session origins. TODO: Fix this in Rails 4. In Rails 3 there is a known bug that prevents
.count from being called on the returned ActiveRecord::Relation.
https://github.com/rails/rails/issues/939
358 359 360 361 362 363 |
# File 'app/models/metasploit/credential/core.rb', line 358 def self.cores_from_host_sql(host_id) Arel::Nodes::Union.new( origin_service_host_id(host_id).ast, origin_session_host_id(host_id).ast ).to_sql end |
Instance Method Details
#login_host_id(host_id) ⇒ ActiveRecord::Relation
Finds Cores that have successfully logged into a given host
201 202 203 |
# File 'app/models/metasploit/credential/core.rb', line 201 scope :login_host_id, lambda { |host_id| joins(logins: { service: :host }).where(Mdm::Host.arel_table[:id].eq(host_id)) } |
#origin_service_host_id(host_id) ⇒ ActiveRecord::Relation
Finds Cores that have an origin_type of Service and are attached to the given host
226 227 228 229 230 |
# File 'app/models/metasploit/credential/core.rb', line 226 scope :origin_service_host_id, lambda { |host_id| core_table = Metasploit::Credential::Core.arel_table host_table = Mdm::Host.arel_table services_hosts.select(core_table[:id]).where(host_table[:id].eq(host_id)) } |
#origin_session_host_id(host_id) ⇒ ActiveRecord::Relation
Finds Cores that have an origin_type of Session that were collected from the given host
238 239 240 241 242 |
# File 'app/models/metasploit/credential/core.rb', line 238 scope :origin_session_host_id, lambda { |host_id| core_table = Metasploit::Credential::Core.arel_table host_table = Mdm::Host.arel_table sessions_hosts.select(core_table[:id]).where(host_table[:id].eq(host_id)) } |
#originating_host_id ⇒ ActiveRecord::Relation
Finds all Cores that have been collected in some way from a Host
284 285 286 287 288 |
# File 'app/models/metasploit/credential/core.rb', line 284 scope :originating_host_id, lambda { |host_id| core_table = Metasploit::Credential::Core.arel_table subquery = Metasploit::Credential::Core.cores_from_host_sql(host_id) where(core_table[:id].in(Arel::Nodes::SqlLiteral.new(subquery))) } |
#origins(origin_class) ⇒ ActiveRecord::Relation
JOINs in origins of a specific type
212 213 214 215 216 217 218 |
# File 'app/models/metasploit/credential/core.rb', line 212 scope :origins, lambda { |origin_class, table_alias=nil| core_table = Metasploit::Credential::Core.arel_table origin_table = origin_class.arel_table.alias(table_alias || origin_class.table_name) origin_joins = core_table.join(origin_table).on(origin_table[:id].eq(core_table[:origin_id]) .and(core_table[:origin_type].eq(origin_class.to_s))) joins(origin_joins.join_sources) } |
#services_hosts ⇒ ActiveRecord::Relation
Adds a JOIN for the Service and Host that a Core with an Origin type of Service would have
249 250 251 252 253 254 255 256 257 258 259 |
# File 'app/models/metasploit/credential/core.rb', line 249 scope :services_hosts, lambda { core_table = Metasploit::Credential::Core.arel_table service_table = Mdm::Service.arel_table host_table = Mdm::Host.arel_table origin_table = Metasploit::Credential::Origin::Service.arel_table.alias('origins_for_service') origins(Metasploit::Credential::Origin::Service, 'origins_for_service').joins( core_table.join(service_table).on(service_table[:id].eq(origin_table[:service_id])).join_sources, core_table.join(host_table).on(host_table[:id].eq(service_table[:host_id])).join_sources ) } |
#sessions_hosts ⇒ ActiveRecord::Relation
Adds a JOIN for the Session and Host that a Core with an Origin type of Session would have
266 267 268 269 270 271 272 273 274 275 276 |
# File 'app/models/metasploit/credential/core.rb', line 266 scope :sessions_hosts, lambda { core_table = Metasploit::Credential::Core.arel_table session_table = Mdm::Session.arel_table host_table = Mdm::Host.arel_table origin_table = Metasploit::Credential::Origin::Session.arel_table.alias('origins_for_session') origins(Metasploit::Credential::Origin::Session, 'origins_for_session').joins( core_table.join(session_table).on(session_table[:id].eq(origin_table[:session_id])).join_sources, core_table.join(host_table).on(host_table[:id].eq(session_table[:host_id])).join_sources ) } |
#with_logins ⇒ ActiveRecord::Relation
Eager loads Login objects associated to Cores
304 305 306 |
# File 'app/models/metasploit/credential/core.rb', line 304 scope :with_logins, ->() { includes(:logins) } |
#with_private ⇒ ActiveRecord::Relation
Eager loads Private objects associated to Cores
320 321 322 |
# File 'app/models/metasploit/credential/core.rb', line 320 scope :with_private, ->() { includes(:private) } |
#with_public ⇒ ActiveRecord::Relation
Eager loads Public objects associated to Cores
312 313 314 |
# File 'app/models/metasploit/credential/core.rb', line 312 scope :with_public, ->() { includes(:public) } |
#with_realm ⇒ ActiveRecord::Relation
Eager loads Realm objects associated to Cores
328 329 330 |
# File 'app/models/metasploit/credential/core.rb', line 328 scope :with_realm, ->() { includes(:realm) } |
#workspace_id(id) ⇒ ActiveRecord::Relation
Finds Cores that are attached to a given workspace
296 297 298 |
# File 'app/models/metasploit/credential/core.rb', line 296 scope :workspace_id, ->(id) { where(workspace_id: id) } |