Skip to content

Commit

Permalink
Merge branch 'master' into bug/MSP-10828/creation-taskid
Browse files Browse the repository at this point in the history
Version conflict bump

Conflicts:
	lib/metasploit/credential/version.rb
  • Loading branch information
trosen-r7 committed Jul 23, 2014
2 parents a3a94a3 + a76af0a commit 8566612
Show file tree
Hide file tree
Showing 6 changed files with 304 additions and 11 deletions.
17 changes: 17 additions & 0 deletions app/models/metasploit/credential/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# A core credential must always have an {#origin}, but only needs 1 of {#private}, {#public}, or {#realm} set.
class Metasploit::Credential::Core < ActiveRecord::Base
include Metasploit::Model::Search

#
# Associations
#
Expand Down Expand Up @@ -256,6 +258,21 @@ class Metasploit::Credential::Core < ActiveRecord::Base
includes(:realm)
}

#
#
# Search
#
#

#
# Search Associations
#

search_association :logins
search_association :private
search_association :public
search_association :realm

#
# Class Methods
#
Expand Down
16 changes: 8 additions & 8 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ en:
missing_manifest: "This Metasploit credentials zip export appears to be missing its CSV manifest"
activerecord:
ancestors:
metasploit/credential/realm:
search:
operator:
names:
key:
help: "The type of realm, such as Active Directory Domain or PostgreSQL Database."
value:
help: "The name of the realm, such as the domain name or the database name."
metasploit/credential/login:
search:
operator:
Expand All @@ -37,6 +29,14 @@ en:
help: "The level of access granted to the service by core credential, such as 'root' or 'Administrator'."
status:
help: "The status of this login: 'Denied Access', 'Disabled', 'Incorrect', 'Locked Out', 'No Auth Required', 'Successful', 'Unable to Connect', or 'Untried'"
metasploit/credential/realm:
search:
operator:
names:
key:
help: "The type of realm, such as Active Directory Domain or PostgreSQL Database."
value:
help: "The name of the realm, such as the domain name or the database name."
models:
metasploit/credential/ntlm_hash: "NTLM hash"
metasploit/credential/ssh_key: "SSH key"
Expand Down
3 changes: 1 addition & 2 deletions lib/metasploit/credential/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ module Version
# The minor version number, scoped to the {MAJOR} version number.
MINOR = 7
# The patch number, scoped to the {MINOR} version number.
PATCH = 8
PRERELEASE = "creation-taskid"
PATCH = 11

# The full version string, including the {MAJOR}, {MINOR}, {PATCH}, and optionally, the {PRERELEASE} in the
# {http://semver.org/spec/v2.0.0.html semantic versioning v2.0.0} format.
Expand Down
2 changes: 1 addition & 1 deletion metasploit-credential.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |s|
# patching inverse association in Mdm models.
s.add_runtime_dependency 'metasploit-concern', '~> 0.1.0'
# Various Metasploit::Credential records have associations to Mdm records
s.add_runtime_dependency 'metasploit_data_models', '>= 0.18.0.pre.compatibility','< 0.19'
s.add_runtime_dependency 'metasploit_data_models', '~> 0.19'
# Metasploit::Model::Search
s.add_runtime_dependency 'metasploit-model','>= 0.25.6'
# Metasploit::Credential::NTLMHash helper methods
Expand Down
13 changes: 13 additions & 0 deletions spec/models/metasploit/credential/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,19 @@

end

context 'search' do
let(:base_class) {
described_class
}

context 'associations' do
it_should_behave_like 'search_association', :logins
it_should_behave_like 'search_association', :private
it_should_behave_like 'search_association', :public
it_should_behave_like 'search_association', :realm
end
end

context 'factories' do
context 'metasploit_credential_core' do
subject(:metasploit_credential_core) do
Expand Down
264 changes: 264 additions & 0 deletions spec/models/metasploit_data_models/search/visitor/relation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,270 @@
}

context 'MetasploitDataModels::Search::Visitor::Relation#query Metasploit::Model::Search::Query#klass' do
context 'with Metasploit::Credential::Core' do
include_context 'Mdm::Workspace'

#
# Shared Examples
#

shared_examples 'Metasploit::Credential::Private' do |options={}|
options.assert_valid_keys(:name, :factory)

subclass_factory = options.fetch(:factory)
subclass_name = options.fetch(:name)

context subclass_name do
let(:private_factory) {
subclass_factory
}

it_should_behave_like 'MetasploitDataModels::Search::Visitor::Relation#visit matching record',
association: :private,
attribute: :data

context 'with all operators' do
let(:formatted) {
%Q{
logins.access_level:"#{matching_login_access_level}"
logins.status:"#{matching_login_status}"
private.data:"#{matching_private_data}"
public.username:"#{matching_public_username}"
realm.key:"#{matching_realm_key}"
realm.value:"#{matching_realm_value}"
}
}

it 'finds only matching record' do
expect(visit).to match_array([matching_record])
end
end
end
end

#
# lets
#

let(:klass) {
Metasploit::Credential::Core
}

let(:matching_login_access_level) {
'Administrator'
}

let(:matching_login_status) {
Metasploit::Model::Login::Status::LOCKED_OUT
}

let(:matching_private) {
FactoryGirl.create(
private_factory,
matching_private_attributes
)
}

let(:matching_private_attributes) {
{}
}

let(:matching_private_data) {
matching_private.data
}

let(:matching_public) {
FactoryGirl.create(
:metasploit_credential_public,
username: matching_public_username
)
}

let(:matching_public_username) {
'root'
}

let(:matching_realm) {
FactoryGirl.create(
:metasploit_credential_realm,
key: matching_realm_key,
value: matching_realm_value
)
}

let(:matching_realm_key) {
Metasploit::Model::Realm::Key::POSTGRESQL_DATABASE
}

let(:matching_realm_value) {
'postgres'
}

let(:non_matching_login_access_level) {
'normal'
}

let(:non_matching_login_status) {
Metasploit::Model::Login::Status::SUCCESSFUL
}

let(:non_matching_private) {
FactoryGirl.create(
private_factory,
non_matching_private_attributes
)
}

let(:non_matching_private_attributes) {
{}
}

let(:non_matching_public) {
FactoryGirl.create(
:metasploit_credential_public,
username: non_matching_public_username
)
}

let(:non_matching_public_username) {
'guest'
}

let(:non_matching_realm) {
FactoryGirl.create(
:metasploit_credential_realm,
key: non_matching_realm_key,
value: non_matching_realm_value
)
}

let(:non_matching_realm_key) {
Metasploit::Model::Realm::Key::ACTIVE_DIRECTORY_DOMAIN
}

let(:non_matching_realm_value) {
'DOMAIN'
}

let(:private_factory) {
[
:metasploit_credential_nonreplayable_hash,
:metasploit_credential_ntlm_hash,
:metasploit_credential_password,
:metasploit_credential_ssh_key
].sample
}

#
# let!s
#

let!(:matching_login) {
FactoryGirl.create(
:metasploit_credential_login,
access_level: matching_login_access_level,
core: matching_record,
status: matching_login_status
)
}

let!(:matching_record) {
FactoryGirl.create(
:metasploit_credential_core,
private: matching_private,
public: matching_public,
realm: matching_realm
)
}

let!(:non_matching_login) {
FactoryGirl.create(
:metasploit_credential_login,
access_level: non_matching_login_access_level,
core: non_matching_record,
status: non_matching_login_status
)
}

let!(:non_matching_record) {
FactoryGirl.create(
:metasploit_credential_core,
private: non_matching_private,
public: non_matching_public,
realm: non_matching_realm
)
}

it_should_behave_like 'MetasploitDataModels::Search::Visitor::Relation#visit matching record',
association: :logins,
attribute: :access_level

it_should_behave_like 'MetasploitDataModels::Search::Visitor::Relation#visit matching record',
association: :logins,
attribute: :status

it_should_behave_like 'MetasploitDataModels::Search::Visitor::Relation#visit matching record',
association: :public,
attribute: :username

it_should_behave_like 'MetasploitDataModels::Search::Visitor::Relation#visit matching record',
association: :realm,
attribute: :key

it_should_behave_like 'MetasploitDataModels::Search::Visitor::Relation#visit matching record',
association: :realm,
attribute: :value

context 'wth Metasploit::Credential::PasswordHash' do

#
# lets
#

let(:matching_private_attributes) {
{
password_data: '123456789'
}
}

let(:non_matching_private_attributes) {
{
password_data: 'password'
}
}

it_should_behave_like 'Metasploit::Credential::Private',
factory: :metasploit_credential_nonreplayable_hash,
name: 'Metasploit::Credential::NonreplayableHash'


it_should_behave_like 'Metasploit::Credential::Private',
factory: :metasploit_credential_ntlm_hash,
name: 'Metasploit::Credential::NTLMHash'
end

it_should_behave_like 'Metasploit::Credential::Private',
factory: :metasploit_credential_password,
name: 'Metasploit::Credential::Password' do
let(:matching_attributes) {
{
data: '123456789'
}
}

let(:non_matching_attributes) {
{
# needs to not be a substring alias of matching_attributes[:password_data]
data: 'password'
}
}
end

it_should_behave_like 'Metasploit::Credential::Private',
factory: :metasploit_credential_ssh_key,
name: 'Metasploit::Credental::SSHKey'
end

context 'with Metasploit::Credential::Login' do
include_context 'Mdm::Workspace'

Expand Down

0 comments on commit 8566612

Please sign in to comment.