Class: Metasploit::Framework::PrivateCredentialCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/metasploit/framework/credential_collection.rb

Direct Known Subclasses

CredentialCollection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ PrivateCredentialCollection

Returns a new instance of PrivateCredentialCollection.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :blank_passwords (Boolean)
  • :pass_file (String)
  • :password (String)

    See #password

  • :prepended_creds (Array<Credential>) — default: []
  • :user_as_pass (Boolean)

    See #user_as_pass

  • :user_file (String)

    See #user_file

  • :username (String)

    See #username

  • :userpass_file (String)

    See #userpass_file


46
47
48
49
50
51
52
# File 'lib/metasploit/framework/credential_collection.rb', line 46

def initialize(opts = {})
  opts.each do |attribute, value|
    public_send("#{attribute}=", value)
  end
  self.prepended_creds     ||= []
  self.additional_privates ||= []
end

Instance Attribute Details

#additional_privatesArray<String>

Additional private values that should be tried

Returns:

  • (Array<String>)

9
10
11
# File 'lib/metasploit/framework/credential_collection.rb', line 9

def additional_privates
  @additional_privates
end

#blank_passwordsBoolean

Whether each username should be tried with a blank password

Returns:

  • (Boolean)

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

def blank_passwords
  @blank_passwords
end

#pass_fileString

Path to a file containing passwords, one per line

Returns:

  • (String)

19
20
21
# File 'lib/metasploit/framework/credential_collection.rb', line 19

def pass_file
  @pass_file
end

#passwordString

The password that should be tried

Returns:

  • (String)

24
25
26
# File 'lib/metasploit/framework/credential_collection.rb', line 24

def password
  @password
end

#prepended_credsArray<Credential>

List of credentials to be tried before any others

Returns:

See Also:


31
32
33
# File 'lib/metasploit/framework/credential_collection.rb', line 31

def prepended_creds
  @prepended_creds
end

#realmString

The authentication realm associated with this password

Returns:

  • (String)

36
37
38
# File 'lib/metasploit/framework/credential_collection.rb', line 36

def realm
  @realm
end

Instance Method Details

#add_private(private_str = '') ⇒ void

This method returns an undefined value.

Adds a string as an additional private credential to be combined in the collection.

Parameters:

  • private_str (String) (defaults to: '')

    The string to use as a private credential


59
60
61
# File 'lib/metasploit/framework/credential_collection.rb', line 59

def add_private(private_str='')
  additional_privates << private_str
end

#each {|credential| ... } ⇒ void

This method returns an undefined value.

Combines all the provided credential sources into a stream of Credential objects, yielding them one at a time

Yield Parameters:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/metasploit/framework/credential_collection.rb', line 78

def each
  if pass_file.present?
    pass_fd = File.open(pass_file, 'r:binary')
  end

  prepended_creds.each { |c| yield c }

  if password.present?
    yield Metasploit::Framework::Credential.new(private: password, realm: realm, private_type: private_type(password))
  end
  if blank_passwords
    yield Metasploit::Framework::Credential.new(private: "", realm: realm, private_type: :password)
  end
  if pass_fd
    pass_fd.each_line do |pass_from_file|
      pass_from_file.chomp!
      yield Metasploit::Framework::Credential.new(private: pass_from_file, realm: realm, private_type: private_type(pass_from_file))
    end
  end
  additional_privates.each do |add_private|
    yield Metasploit::Framework::Credential.new(private: add_private, realm: realm, private_type: private_type(add_private))
  end

ensure
  pass_fd.close if pass_fd && !pass_fd.closed?
end

#empty?Boolean

Returns true when #each will have no results to iterate

Returns:

  • (Boolean)

108
109
110
# File 'lib/metasploit/framework/credential_collection.rb', line 108

def empty?
  prepended_creds.empty? && !has_privates?
end

#has_privates?Boolean

Returns true when there are any private values set

Returns:

  • (Boolean)

115
116
117
# File 'lib/metasploit/framework/credential_collection.rb', line 115

def has_privates?
  password.present? || pass_file.present? || !additional_privates.empty? || blank_passwords
end

#prepend_cred(cred) ⇒ self

Add credentials that will be yielded by #each

Parameters:

Returns:

  • (self)

See Also:


68
69
70
71
# File 'lib/metasploit/framework/credential_collection.rb', line 68

def prepend_cred(cred)
  prepended_creds.unshift cred
  self
end

#private_type(private) ⇒ Symbol (protected)

Analyze a private value to determine its type by checking it against a known list of regular expressions

Parameters:

  • private (String)

    The string to analyze

Returns:

  • (Symbol)

125
126
127
128
129
130
131
132
133
# File 'lib/metasploit/framework/credential_collection.rb', line 125

def private_type(private)
  if private =~ /[0-9a-f]{32}:[0-9a-f]{32}/
    :ntlm_hash
  elsif private =~ /^md5([a-f0-9]{32})$/
    :postgres_md5
  else
    :password
  end
end