Credential Core creation now complete

bug/bundler_fix
David Maloney 2014-05-21 16:37:13 -05:00
parent 3ea99a9d43
commit 19e36cccb3
No known key found for this signature in database
GPG Key ID: DEDBA9DC3A913DB2
2 changed files with 79 additions and 1 deletions

View File

@ -13,10 +13,42 @@ module Auxiliary::Report
return nil unless framework.db.active
origin = create_credential_origin(opts)
core_opts = { workspace_id: opts.fetch(:workspace_id) }
if opts.has_key?(:realm_key) && opts.has_key?(:realm_value)
realm = create_credential_realm(opts)
core_opts[:realm] = create_credential_realm(opts)
end
if opts.has_key?(:private_type) && opts.has_key(:private_data)
core_opts[:private] = create_credential_private(opts)
end
if opts.has_key(:username)
core_opts[:public] = create_credential_public(opts)
end
end
# This method is responsible for creating {Metasploit::Credential::Core} objects.
#
# @param opts [Hash] The options hash to use
# @option opts [Metasploit::Credential::Origin] :origin The origin object to tie the core to
# @option opts [Metasploit::Credential::Public] :public The {Metasploit::Credential::Public} component
# @option opts [Metasploit::Credential::Private] :private The {Metasploit::Credential::Private} component
# @option opts [Fixnum] :workspace_id The ID of the {Mdm::Workspace} to tie the Core to
# @return [NilClass] if there is no active database connection
# @return [Metasploit::Credential::Core]
def create_credential_core(opts={})
return nil unless framework.db.active
origin = opts.fetch(:origin)
workspace_id = opts.fetch(:workspace_id)
core = Metasploit::Credential::Core.where(private_id: opts[:private].id, public_id: opts[:public].id, realm_id: opts[:realm].id, workspace_id: opts[:workspace_id]).first_or_create
if core.origin_id.nil?
core.origin = origin
end
core.save!
end
# This method is responsible for the creation of {Metasploit::Credential::Private} objects.
@ -52,6 +84,21 @@ module Auxiliary::Report
private_object.save!
end
# This method is responsible for the creation of {Metasploit::Credential::Public} objects.
#
# @param opts [Hash] The options hash to use
# @option opts [String] :username The username to use for the {Metasploit::Credential::Public}
# @raise [KeyError] if a required option is missing
# @return [NilClass] if there is no active database connection
# @return [Metasploit::Credential::Public]
def create_credential_public(opts={})
return nil unless framework.db.active
username = opts.fetch(:username)
public_object = Metasploit::Credential::Public.where(username: username).first_or_create
public_object.save!
end
# This method is responsible for creating the {Metasploit::Credential::Realm} objects
# that may be required.
#

View File

@ -394,4 +394,35 @@ describe Msf::Auxiliary::Report do
end
end
context '#create_credential_core' do
let(:origin) { FactoryGirl.create(:metasploit_credential_origin_service) }
let(:public) { FactoryGirl.create(:metasploit_credential_public)}
let(:private) { FactoryGirl.create(:metasploit_credential_password)}
let(:realm) { FactoryGirl.create(:metasploit_credential_realm)}
it 'raises a KeyError if any required option is missing' do
opts = {}
expect{ test_object.create_credential_core(opts)}.to raise_error KeyError
end
it 'returns nil if there is no active database connection' do
my_module = test_object
expect(my_module.framework.db).to receive(:active).and_return(false)
expect(my_module.create_credential_core).to be_nil
end
it 'creates a Metasploit::Credential::Core' do
opts = {
origin: origin,
public: public,
private: private,
realm: realm,
workspace_id: origin.service.host.workspace_id
}
expect{test_object.create_credential_core(opts)}.to change{Metasploit::Credential::Core.count}.by(1)
end
end
end