Class: Metasploit::Framework::CredentialCollection
- Inherits:
-
PrivateCredentialCollection
- Object
- PrivateCredentialCollection
- Metasploit::Framework::CredentialCollection
- Defined in:
- lib/metasploit/framework/credential_collection.rb
Instance Attribute Summary collapse
-
#additional_publics ⇒ Array<String>
Additional public values that should be tried.
-
#user_as_pass ⇒ Boolean
Whether each username should be tried as a password for that user.
-
#user_file ⇒ String
Path to a file containing usernames, one per line.
-
#username ⇒ String
The username that should be tried.
-
#userpass_file ⇒ String
Path to a file containing usernames and passwords separated by a space, one pair per line.
Attributes inherited from PrivateCredentialCollection
#additional_privates, #blank_passwords, #filter, #pass_file, #password, #prepended_creds, #realm
Instance Method Summary collapse
-
#add_public(public_str = '') ⇒ void
Adds a string as an additional public credential to be combined in the collection.
-
#each_unfiltered {|credential| ... } ⇒ void
Combines all the provided credential sources into a stream of Credential objects, yielding them one at a time.
-
#empty? ⇒ Boolean
Returns true when #each will have no results to iterate.
-
#has_privates? ⇒ Boolean
Returns true when there are any private values set.
-
#has_users? ⇒ Boolean
Returns true when there are any user values set.
-
#initialize(opts = {}) ⇒ CredentialCollection
constructor
A new instance of CredentialCollection.
Methods inherited from PrivateCredentialCollection
#add_private, #each_filtered, #filtered?, #prepend_cred, #private_type
Constructor Details
#initialize(opts = {}) ⇒ CredentialCollection
Returns a new instance of CredentialCollection.
195 196 197 198 |
# File 'lib/metasploit/framework/credential_collection.rb', line 195 def initialize(opts = {}) super self.additional_publics ||= [] end |
Instance Attribute Details
#additional_publics ⇒ Array<String>
Additional public values that should be tried
164 165 166 |
# File 'lib/metasploit/framework/credential_collection.rb', line 164 def additional_publics @additional_publics end |
#user_as_pass ⇒ Boolean
Whether each username should be tried as a password for that user
169 170 171 |
# File 'lib/metasploit/framework/credential_collection.rb', line 169 def user_as_pass @user_as_pass end |
#user_file ⇒ String
Path to a file containing usernames, one per line
174 175 176 |
# File 'lib/metasploit/framework/credential_collection.rb', line 174 def user_file @user_file end |
#username ⇒ String
The username that should be tried
179 180 181 |
# File 'lib/metasploit/framework/credential_collection.rb', line 179 def username @username end |
#userpass_file ⇒ String
Path to a file containing usernames and passwords separated by a space, one pair per line
185 186 187 |
# File 'lib/metasploit/framework/credential_collection.rb', line 185 def userpass_file @userpass_file end |
Instance Method Details
#add_public(public_str = '') ⇒ void
This method returns an undefined value.
Adds a string as an additional public credential to be combined in the collection.
205 206 207 |
# File 'lib/metasploit/framework/credential_collection.rb', line 205 def add_public(public_str='') additional_publics << public_str end |
#each_unfiltered {|credential| ... } ⇒ void
This method returns an undefined value.
Combines all the provided credential sources into a stream of Metasploit::Framework::Credential objects, yielding them one at a time
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/metasploit/framework/credential_collection.rb', line 214 def each_unfiltered if pass_file.present? pass_fd = File.open(pass_file, 'r:binary') end prepended_creds.each { |c| yield c } if username.present? if password.present? yield Metasploit::Framework::Credential.new(public: username, private: password, realm: realm, private_type: private_type(password)) end if user_as_pass yield Metasploit::Framework::Credential.new(public: username, private: username, realm: realm, private_type: :password) end if blank_passwords yield Metasploit::Framework::Credential.new(public: username, 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(public: username, 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(public: username, private: add_private, realm: realm, private_type: private_type(add_private)) end end if user_file.present? File.open(user_file, 'r:binary') do |user_fd| user_fd.each_line do |user_from_file| user_from_file.chomp! if password.present? yield Metasploit::Framework::Credential.new(public: user_from_file, private: password, realm: realm, private_type: private_type(password) ) end if user_as_pass yield Metasploit::Framework::Credential.new(public: user_from_file, private: user_from_file, realm: realm, private_type: :password) end if blank_passwords yield Metasploit::Framework::Credential.new(public: user_from_file, 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(public: user_from_file, private: pass_from_file, realm: realm, private_type: private_type(pass_from_file)) end pass_fd.seek(0) end additional_privates.each do |add_private| yield Metasploit::Framework::Credential.new(public: user_from_file, private: add_private, realm: realm, private_type: private_type(add_private)) end end end end if userpass_file.present? File.open(userpass_file, 'r:binary') do |userpass_fd| userpass_fd.each_line do |line| user, pass = line.split(" ", 2) if pass.blank? pass = '' else pass.chomp! end yield Metasploit::Framework::Credential.new(public: user, private: pass, realm: realm) end end end additional_publics.each do |add_public| if password.present? yield Metasploit::Framework::Credential.new(public: add_public, private: password, realm: realm, private_type: private_type(password) ) end if user_as_pass yield Metasploit::Framework::Credential.new(public: add_public, private: user_from_file, realm: realm, private_type: :password) end if blank_passwords yield Metasploit::Framework::Credential.new(public: add_public, 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(public: add_public, private: pass_from_file, realm: realm, private_type: private_type(pass_from_file)) end pass_fd.seek(0) end additional_privates.each do |add_private| yield Metasploit::Framework::Credential.new(public: add_public, private: add_private, realm: realm, private_type: private_type(add_private)) end end ensure pass_fd.close if pass_fd && !pass_fd.closed? end |
#empty? ⇒ Boolean
Returns true when #each will have no results to iterate
312 313 314 |
# File 'lib/metasploit/framework/credential_collection.rb', line 312 def empty? prepended_creds.empty? && !has_users? || (has_users? && !has_privates?) end |
#has_privates? ⇒ Boolean
Returns true when there are any private values set
326 327 328 |
# File 'lib/metasploit/framework/credential_collection.rb', line 326 def has_privates? super || userpass_file.present? || user_as_pass end |
#has_users? ⇒ Boolean
Returns true when there are any user values set
319 320 321 |
# File 'lib/metasploit/framework/credential_collection.rb', line 319 def has_users? username.present? || user_file.present? || userpass_file.present? || !additional_publics.empty? end |