Class: Metasploit::Framework::Credential

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/metasploit/framework/credential.rb

Overview

This class provides an in-memory representation of a conceptual Credential

It contains the public, private, and realm if any.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Credential

Returns a new instance of Credential.

Parameters:

  • attributes (Hash{Symbol => String,nil}) (defaults to: {})

63
64
65
66
67
68
69
# File 'lib/metasploit/framework/credential.rb', line 63

def initialize(attributes={})
  attributes.each do |attribute, value|
    public_send("#{attribute}=", value)
  end

  self.paired = true if self.paired.nil?
end

Instance Attribute Details

#pairedBoolean

Returns Whether BOTH a public and private are required (defaults to `true`).

Returns:

  • (Boolean)

    Whether BOTH a public and private are required (defaults to `true`)


14
15
16
# File 'lib/metasploit/framework/credential.rb', line 14

def paired
  @paired
end

#parentObject

Returns the parent object that had .to_credential called on it to create this object.

Returns:

  • (Object)

    the parent object that had .to_credential called on it to create this object


17
18
19
# File 'lib/metasploit/framework/credential.rb', line 17

def parent
  @parent
end

#privateString?

The private credential component (e.g. username)

Returns:


23
24
25
# File 'lib/metasploit/framework/credential.rb', line 23

def private
  @private
end

#private_typeString

The type of private credential this object represents, e.g. a password or an NTLM hash.

Returns:

  • (String)

29
30
31
# File 'lib/metasploit/framework/credential.rb', line 29

def private_type
  @private_type
end

#publicString?

The public credential component (e.g. password)

Returns:


35
36
37
# File 'lib/metasploit/framework/credential.rb', line 35

def public
  @public
end

#realmString?

Returns The type of #realm.

Returns:

  • (String, nil)

    The type of #realm


38
39
40
# File 'lib/metasploit/framework/credential.rb', line 38

def realm
  @realm
end

#realm_keyObject

Returns the value of attribute realm_key


41
42
43
# File 'lib/metasploit/framework/credential.rb', line 41

def realm_key
  @realm_key
end

Instance Method Details

#==(other) ⇒ Object


85
86
87
88
89
# File 'lib/metasploit/framework/credential.rb', line 85

def ==(other)
  other.respond_to?(:public) && other.public == self.public &&
  other.respond_to?(:private) && other.private == self.private &&
  other.respond_to?(:realm) && other.realm == self.realm
end

#inspectObject


71
72
73
# File 'lib/metasploit/framework/credential.rb', line 71

def inspect
  "#<#{self.class} \"#{self}\" >"
end

#to_credentialObject


91
92
93
94
# File 'lib/metasploit/framework/credential.rb', line 91

def to_credential
  self.parent = self
  self
end

#to_hHash

This method takes all of the attributes of the Metasploit::Framework::Credential and spits them out in a hash compatible with the create_credential calls.

Returns:

  • (Hash)

    a hash compatible with #create_credential


100
101
102
103
104
105
106
107
108
# File 'lib/metasploit/framework/credential.rb', line 100

def to_h
  {
      private_data: private,
      private_type: private_type,
      username: public,
      realm_key: realm_key,
      realm_value: realm
  }
end

#to_sObject


75
76
77
78
79
80
81
82
83
# File 'lib/metasploit/framework/credential.rb', line 75

def to_s
  if realm && realm_key == Metasploit::Model::Realm::Key::ACTIVE_DIRECTORY_DOMAIN
    "#{self.realm}\\#{self.public}:#{self.private}"
  elsif self.private
    "#{self.public}:#{self.private}#{at_realm}"
  else
    self.public
  end
end