mirror of
https://github.com/rapid7/metasploit-framework
synced 2024-10-02 07:40:19 +02:00
adding .to_credential
Metasploit::Framework::Credential and Metasploit::Credential::Core need to be consumable by the login scanners. the easiest way to do this was to create a shared to_credential method on both that return Metasploit::Framework::Credential MSP-9912
This commit is contained in:
parent
07d548caeb
commit
b5351eec2b
14
app/concerns/metasploit/credential/core/to_credential.rb
Normal file
14
app/concerns/metasploit/credential/core/to_credential.rb
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Adds associations to `Metasploit::Credential::Core` which are inverses of association on models under
|
||||||
|
# {BruteForce::Reuse}.
|
||||||
|
module Metasploit::Credential::Core::ToCredential
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
|
||||||
|
def to_credential
|
||||||
|
Metasploit::Framework::Credential.new(public: public.try(:username), private: private.try(:data), realm: realm.try(:value) )
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -62,6 +62,10 @@ module Metasploit
|
|||||||
other.public == self.public && other.private == self.private && other.realm == self.realm
|
other.public == self.public && other.private == self.private && other.realm == self.realm
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_credential
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def at_realm
|
def at_realm
|
||||||
|
@ -101,7 +101,8 @@ module Metasploit
|
|||||||
consecutive_error_count = 0
|
consecutive_error_count = 0
|
||||||
total_error_count = 0
|
total_error_count = 0
|
||||||
|
|
||||||
cred_details.each do |credential|
|
cred_details.each do |raw_credential|
|
||||||
|
credential = raw_credential.to_credential
|
||||||
result = attempt_login(credential)
|
result = attempt_login(credential)
|
||||||
result.freeze
|
result.freeze
|
||||||
|
|
||||||
|
@ -74,6 +74,19 @@ describe Metasploit::Framework::Credential do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe ".to_credential" do
|
||||||
|
let(:public) { "public" }
|
||||||
|
let(:private) { "private" }
|
||||||
|
let(:realm) { "realm" }
|
||||||
|
subject(:cred_detail) do
|
||||||
|
described_class.new(public: public, private: private, realm: realm)
|
||||||
|
end
|
||||||
|
it { should respond_to :to_credential }
|
||||||
|
it "should return self" do
|
||||||
|
cred_detail.to_credential.should eq(cred_detail)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#==" do
|
describe "#==" do
|
||||||
let(:public) { "public" }
|
let(:public) { "public" }
|
||||||
let(:private) { "private" }
|
let(:private) { "private" }
|
||||||
|
5
spec/models/metasploit/credential/core_spec.rb
Normal file
5
spec/models/metasploit/credential/core_spec.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Metasploit::Credential::Core do
|
||||||
|
it_should_behave_like 'Metasploit::Credential::Core::ToCredential'
|
||||||
|
end
|
@ -0,0 +1,21 @@
|
|||||||
|
require 'metasploit/framework/credential'
|
||||||
|
|
||||||
|
shared_examples_for 'Metasploit::Credential::Core::ToCredential' do
|
||||||
|
context "methods" do
|
||||||
|
context ".to_credential" do
|
||||||
|
|
||||||
|
subject(:crednetial_core) do
|
||||||
|
FactoryGirl.create(:metasploit_credential_core)
|
||||||
|
end
|
||||||
|
|
||||||
|
it { should respond_to :to_credential }
|
||||||
|
|
||||||
|
it "should return a Metasploit::Framework::Credential" do
|
||||||
|
expect {
|
||||||
|
to_credential
|
||||||
|
}.to be_a Metasploit::Framework::Credential
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user