class Metasploit::Credential::Login

The use of a {#core core credential} against a {#service service}.

Public Class Methods

failed_logins_by_public(host_id) click to toggle source

Each username that is related to a login on the passed host and the logins of particular statuses that are related to that public, ordered by the login last attempt date. @param host_id [Integer] the host to filter cores by @return [Hash{String => Array}]

# File app/models/metasploit/credential/login.rb, line 181
def self.failed_logins_by_public(host_id)
  select(
    [
      Metasploit::Credential::Login[Arel.star],
      Metasploit::Credential::Public[:username]
    ]
  ).order(:last_attempted_at).
    joins(
    Metasploit::Credential::Login.join_association(:core),
    Metasploit::Credential::Core.join_association(:public, Arel::Nodes::OuterJoin)
  ).where(
    Metasploit::Credential::Core[:id].in(
      # We are concerned with per-username access attempts. This
      # can be across any of the cores on a host:
      Metasploit::Credential::Core.cores_from_host(host_id)
    ).and(
      Metasploit::Credential::Login[:status].in(
        [
          Metasploit::Model::Login::Status::DENIED_ACCESS,
          Metasploit::Model::Login::Status::DISABLED,
          Metasploit::Model::Login::Status::INCORRECT,
        ]
      ))
  ).group_by(&:username)
end
status_set() click to toggle source

The valid values for search {#status}.

@return [Set<String>] `Metasploit::Model::Login::Status::ALL` as a `Set`. @see Metasploit::Model::Search::Operation::Set#membership @see Metasploit::Model::Search::Operator::Attribute#attribute_set

# File app/models/metasploit/credential/login.rb, line 213
def self.status_set
  @status_set ||= Set.new(Metasploit::Model::Login::Status::ALL)
end

Private Instance Methods

blank_to_nil() click to toggle source

Converts blank {#access_level} to `nil`.

@return [void]

# File app/models/metasploit/credential/login.rb, line 226
def blank_to_nil
  if access_level.blank?
    self.access_level = nil
  end
end
consistent_last_attempted_at() click to toggle source

Validates that {#last_attempted_at} is `nil` when {#status} is {Metasploit:Credential::Login::Status::UNTRIED} and that {#last_attempted_at} is not `nil` when {#status} is not {Metasploit:Credential::Login::Status::UNTRIED}.

@return [void]

# File app/models/metasploit/credential/login.rb, line 236
def consistent_last_attempted_at
  if status == Metasploit::Model::Login::Status::UNTRIED
    unless last_attempted_at.nil?
      errors.add(:last_attempted_at, :untried)
    end
  else
    if last_attempted_at.nil?
      errors.add(:last_attempted_at, :tried)
    end
  end
end
consistent_workspaces() click to toggle source

Validates the {#service service's} `Mdm::Service#host`'s `Mdm::Host#workspace` matches {#core core's} {Metasploit::Credential::Core#workspace}.

# File app/models/metasploit/credential/login.rb, line 250
def consistent_workspaces
  unless core.try(:workspace) == service.try(:host).try(:workspace)
    errors.add(:base, :inconsistent_workspaces)
  end
end