diff --git a/Gemfile b/Gemfile index bbe3adcb..2b6382d0 100644 --- a/Gemfile +++ b/Gemfile @@ -10,6 +10,15 @@ gemspec # Metasploit::Credential::SSHKey validation and helper methods gem 'net-ssh' +# Patching inverse association in Mdm models. +gem 'metasploit-concern', github: 'crmaxx/metasploit-concern', branch: 'staging/rails-4.2' + +# Metasploit::Model::Search +gem 'metasploit-model', github: 'crmaxx/metasploit-model', branch: 'staging/rails-4.2' + +# Various Metasploit::Credential records have associations to Mdm records +gem 'metasploit_data_models', github: 'crmaxx/metasploit_data_models', branch: 'staging/rails-4.2' + group :development do # markdown formatting for yard gem 'kramdown', platforms: :jruby @@ -25,7 +34,7 @@ end group :development, :test do # Hash password for Metasploit::Credential::PasswordHash factories gem 'bcrypt' - # Uploads simplecov reports to coveralls.io + # Uploads simplecov reports to coveralls.io gem 'coveralls', require: false # supplies factories for producing model instance for specs # Version 4.1.0 or newer is needed to support generate calls without the 'FactoryGirl.' in factory definitions syntax. @@ -38,9 +47,9 @@ group :development, :test do # for testing database columns and indicies. gem 'shoulda-matchers' # code coverage of tests - gem 'simplecov', :require => false + gem 'simplecov', require: false # dummy app - gem 'rails', '>= 4.0.9', '< 4.1.0' + gem 'rails', '>= 4.2.1' # unit testing framework with rails integration gem 'rspec-rails', '~> 3.1' end diff --git a/app/concerns/mdm/session/metasploit_credential_origin_session.rb b/app/concerns/mdm/session/metasploit_credential_origin_session.rb index 43d539e2..433bbdf5 100644 --- a/app/concerns/mdm/session/metasploit_credential_origin_session.rb +++ b/app/concerns/mdm/session/metasploit_credential_origin_session.rb @@ -16,4 +16,4 @@ module Mdm::Session::MetasploitCredentialOriginSession dependent: :destroy, inverse_of: :session end -end \ No newline at end of file +end diff --git a/app/concerns/mdm/task/metasploit_credential_core.rb b/app/concerns/mdm/task/metasploit_credential_core.rb index 39664616..810c57e5 100644 --- a/app/concerns/mdm/task/metasploit_credential_core.rb +++ b/app/concerns/mdm/task/metasploit_credential_core.rb @@ -11,9 +11,9 @@ module Mdm::Task::MetasploitCredentialCore # The {Metasploit::Credential::Core credential origins} from this import task. # # @return [ActiveRecord::Relation] - has_and_belongs_to_many :credential_cores, + has_and_belongs_to_many :credential_cores, -> { uniq }, - class_name: "Metasploit::Credential::Core", + class_name: "Metasploit::Credential::Core", join_table: "credential_cores_tasks" end -end \ No newline at end of file +end diff --git a/app/concerns/mdm/task/metasploit_credential_login.rb b/app/concerns/mdm/task/metasploit_credential_login.rb index a624a32b..c5393b34 100644 --- a/app/concerns/mdm/task/metasploit_credential_login.rb +++ b/app/concerns/mdm/task/metasploit_credential_login.rb @@ -11,9 +11,9 @@ module Mdm::Task::MetasploitCredentialLogin # The {Metasploit::Credential::Core credential origins} from this import task. # # @return [ActiveRecord::Relation] - has_and_belongs_to_many :credential_logins, + has_and_belongs_to_many :credential_logins, -> { uniq }, - class_name: "Metasploit::Credential::Login", + class_name: "Metasploit::Credential::Login", join_table: "credential_logins_tasks" end -end \ No newline at end of file +end diff --git a/app/concerns/mdm/task/metasploit_credential_origin_import.rb b/app/concerns/mdm/task/metasploit_credential_origin_import.rb index a0989765..9e6247d4 100644 --- a/app/concerns/mdm/task/metasploit_credential_origin_import.rb +++ b/app/concerns/mdm/task/metasploit_credential_origin_import.rb @@ -16,4 +16,4 @@ module Mdm::Task::MetasploitCredentialOriginImport dependent: :destroy, inverse_of: :task end -end \ No newline at end of file +end diff --git a/app/concerns/mdm/user/metasploit_credential_origin_manual.rb b/app/concerns/mdm/user/metasploit_credential_origin_manual.rb index cc61dba4..8737811c 100644 --- a/app/concerns/mdm/user/metasploit_credential_origin_manual.rb +++ b/app/concerns/mdm/user/metasploit_credential_origin_manual.rb @@ -16,4 +16,4 @@ module Mdm::User::MetasploitCredentialOriginManual dependent: :destroy, inverse_of: :user end -end \ No newline at end of file +end diff --git a/app/concerns/mdm/workspace/metasploit_credential_core.rb b/app/concerns/mdm/workspace/metasploit_credential_core.rb index 48373313..9105681e 100644 --- a/app/concerns/mdm/workspace/metasploit_credential_core.rb +++ b/app/concerns/mdm/workspace/metasploit_credential_core.rb @@ -17,4 +17,4 @@ module Mdm::Workspace::MetasploitCredentialCore inverse_of: :workspace end -end \ No newline at end of file +end diff --git a/app/concerns/metasploit_data_models/search/visitor/where/metasploit_credential.rb b/app/concerns/metasploit_data_models/search/visitor/where/metasploit_credential.rb index 159e60ca..5c542856 100644 --- a/app/concerns/metasploit_data_models/search/visitor/where/metasploit_credential.rb +++ b/app/concerns/metasploit_data_models/search/visitor/where/metasploit_credential.rb @@ -10,4 +10,4 @@ module MetasploitDataModels::Search::Visitor::Where::MetasploitCredential attribute.eq(operation.value) end end -end \ No newline at end of file +end diff --git a/app/models/metasploit/credential/blank_password.rb b/app/models/metasploit/credential/blank_password.rb index c2ece1fa..67a6ea3f 100644 --- a/app/models/metasploit/credential/blank_password.rb +++ b/app/models/metasploit/credential/blank_password.rb @@ -10,8 +10,7 @@ class Metasploit::Credential::BlankPassword < Metasploit::Credential::Password # Validations # - validates :data, - uniqueness: true + validates :data, uniqueness: true # # Instance Methods @@ -25,4 +24,4 @@ def blank_data end Metasploit::Concern.run(self) -end \ No newline at end of file +end diff --git a/app/models/metasploit/credential/blank_username.rb b/app/models/metasploit/credential/blank_username.rb index eda056a9..00e309e5 100644 --- a/app/models/metasploit/credential/blank_username.rb +++ b/app/models/metasploit/credential/blank_username.rb @@ -10,8 +10,7 @@ class Metasploit::Credential::BlankUsername < Metasploit::Credential::Public # Validations # - validates :username, - uniqueness: true + validates :username, uniqueness: true # # Instance Methods @@ -25,4 +24,4 @@ def blank_username end Metasploit::Concern.run(self) -end \ No newline at end of file +end diff --git a/app/models/metasploit/credential/core.rb b/app/models/metasploit/credential/core.rb index ca10e687..2944f998 100644 --- a/app/models/metasploit/credential/core.rb +++ b/app/models/metasploit/credential/core.rb @@ -42,8 +42,7 @@ class Metasploit::Credential::Core < ActiveRecord::Base # @return [Metasploit::Credential::Origin::Session] if this core credential was gathered using a # {Metasploit::Credential::Origin::Session#post_reference_name post module} attached to a # {Metasploit::Credential::Origin::Session#session session}. - belongs_to :origin, - polymorphic: true + belongs_to :origin, polymorphic: true # @!attribute private # The {Metasploit::Credential::Private} either gathered from {#realm} or used to @@ -105,8 +104,7 @@ class Metasploit::Credential::Core < ActiveRecord::Base # validate :consistent_workspaces - validates :origin, - presence: true + validates :origin, presence: true # # Scopes @@ -130,7 +128,7 @@ class Metasploit::Credential::Core < ActiveRecord::Base # @param origin_class [ActiveRecord::Base] the Origin class to look up # @param table_alias [String] an alias for the JOINed table, defaults to the table name # @return [ActiveRecord::Relation] scoped to that origin - scope :origins, lambda { |origin_class, table_alias=nil| + scope :origins, lambda { |origin_class, table_alias = nil| core_table = Metasploit::Credential::Core.arel_table origin_table = origin_class.arel_table.alias(table_alias || origin_class.table_name) origin_joins = core_table.join(origin_table).on(origin_table[:id].eq(core_table[:origin_id]) @@ -214,41 +212,31 @@ class Metasploit::Credential::Core < ActiveRecord::Base # @scope Metasploit::Credential::Core # @param id [Integer] the workspace to look in # @return [ActiveRecord::Relation] scoped to the workspace - scope :workspace_id, ->(id) { - where(workspace_id: id) - } + scope :workspace_id, ->(id) { where(workspace_id: id) } # Eager loads {Metasploit::Credential::Login} objects associated to Cores # # @method with_logins # @return [ActiveRecord::Relation] - scope :with_logins, ->() { - includes(:logins) - } + scope :with_logins, -> { includes(:logins) } # Eager loads {Metasploit::Credential::Public} objects associated to Cores # # @method with_public # @return [ActiveRecord::Relation] - scope :with_public, ->() { - includes(:public) - } + scope :with_public, -> { includes(:public) } # Eager loads {Metasploit::Credential::Private} objects associated to Cores # # @method with_private # @return [ActiveRecord::Relation] - scope :with_private, ->() { - includes(:private) - } + scope :with_private, -> { includes(:private) } # Eager loads {Metasploit::Credential::Realm} objects associated to Cores # # @method with_realm # @return [ActiveRecord::Relation] - scope :with_realm, ->() { - includes(:realm) - } + scope :with_realm, -> { includes(:realm) } # # @@ -307,31 +295,31 @@ def self.cores_from_host_sql(host_id) # @return [void] def consistent_workspaces case origin - when Metasploit::Credential::Origin::Manual - user = origin.user - - # admins can access any workspace so there's no inconsistent workspace - unless user && - ( - user.admin || - # use database query when possible - ( - user.persisted? && - user.workspaces.exists?(self.workspace.id) - ) || - # otherwise fall back to in-memory query - user.workspaces.include?(self.workspace) - ) - errors.add(:workspace, :origin_user_workspaces) - end - when Metasploit::Credential::Origin::Service - unless self.workspace == origin.service.try(:host).try(:workspace) - errors.add(:workspace, :origin_service_host_workspace) - end - when Metasploit::Credential::Origin::Session - unless self.workspace == origin.session.try(:host).try(:workspace) - errors.add(:workspace, :origin_session_host_workspace) - end + when Metasploit::Credential::Origin::Manual + user = origin.user + + # admins can access any workspace so there's no inconsistent workspace + unless user && + ( + user.admin || + # use database query when possible + ( + user.persisted? && + user.workspaces.exists?(workspace.id) + ) || + # otherwise fall back to in-memory query + user.workspaces.include?(workspace) + ) + errors.add(:workspace, :origin_user_workspaces) + end + when Metasploit::Credential::Origin::Service + unless workspace == origin.service.try(:host).try(:workspace) + errors.add(:workspace, :origin_service_host_workspace) + end + when Metasploit::Credential::Origin::Session + unless workspace == origin.session.try(:host).try(:workspace) + errors.add(:workspace, :origin_session_host_workspace) + end end end diff --git a/app/models/metasploit/credential/login.rb b/app/models/metasploit/credential/login.rb index 2dd1e849..64b0ba7e 100644 --- a/app/models/metasploit/credential/login.rb +++ b/app/models/metasploit/credential/login.rb @@ -7,14 +7,14 @@ class Metasploit::Credential::Login < ActiveRecord::Base # # Associations # - + # @!attribute tasks # The `Mdm::Task`s using this to track what tasks interacted with a given core. # # @return [ActiveRecord::Relation] has_and_belongs_to_many :tasks, -> { uniq }, - class_name: "Mdm::Task", + class_name: "Mdm::Task", join_table: "credential_logins_tasks" # @!attribute core @@ -111,12 +111,8 @@ class Metasploit::Credential::Login < ActiveRecord::Base # Search Attributes # - search_attribute :access_level, - type: :string - search_attribute :status, - type: { - set: :string - } + search_attribute :access_level, type: :string + search_attribute :status, type: { set: :string } # # @@ -137,17 +133,10 @@ class Metasploit::Credential::Login < ActiveRecord::Base validates :core, presence: true - validates :core_id, - uniqueness: { - scope: :service_id - } + validates :core_id, uniqueness: { scope: :service_id } validates :service, presence: true - validates :status, - inclusion: { - in: Metasploit::Model::Login::Status::ALL - } - + validates :status, inclusion: { in: Metasploit::Model::Login::Status::ALL } # # Scopes @@ -185,7 +174,7 @@ def self.failed_logins_by_public(host_id) Metasploit::Credential::Public[:username] ] ).order(:last_attempted_at). - joins( + joins( Metasploit::Credential::Login.join_association(:core), Metasploit::Credential::Core.join_association(:public, Arel::Nodes::OuterJoin) ).where( @@ -198,13 +187,12 @@ def self.failed_logins_by_public(host_id) [ Metasploit::Model::Login::Status::DENIED_ACCESS, Metasploit::Model::Login::Status::DISABLED, - Metasploit::Model::Login::Status::INCORRECT, + Metasploit::Model::Login::Status::INCORRECT ] )) ).group_by(&:username) end - # The valid values for search {#status}. # # @return [Set] `Metasploit::Model::Login::Status::ALL` as a `Set`. @@ -224,9 +212,8 @@ def self.status_set # # @return [void] def blank_to_nil - if access_level.blank? - self.access_level = nil - end + return unless access_level.blank? + self.access_level = nil end # Validates that {#last_attempted_at} is `nil` when {#status} is {Metasploit:Credential::Login::Status::UNTRIED} and diff --git a/app/models/metasploit/credential/nonreplayable_hash.rb b/app/models/metasploit/credential/nonreplayable_hash.rb index b12ee99b..a6b0d882 100644 --- a/app/models/metasploit/credential/nonreplayable_hash.rb +++ b/app/models/metasploit/credential/nonreplayable_hash.rb @@ -2,7 +2,6 @@ # Contrast with {Metasploit::Credential::ReplayableHash}. {#data} is any password hash, such as those recovered from # `/etc/passwd` or `/etc/shadow`. class Metasploit::Credential::NonreplayableHash < Metasploit::Credential::PasswordHash - # # Constants # diff --git a/app/models/metasploit/credential/ntlm_hash.rb b/app/models/metasploit/credential/ntlm_hash.rb index e69dba59..703ea644 100644 --- a/app/models/metasploit/credential/ntlm_hash.rb +++ b/app/models/metasploit/credential/ntlm_hash.rb @@ -59,11 +59,9 @@ class Metasploit::Credential::NTLMHash < Metasploit::Credential::ReplayableHash # # @return (see #data) def self.data_from_password_data(password_data) - hex_digests = ['', 'nt_'].collect do |prefix| + ['', 'nt_'].collect do |prefix| send("#{prefix}lan_manager_hex_digest_from_password_data", password_data) - end - - hex_digests.join(':') + end.join(':') end # Converts a buffer containing `hash` bytes to a String containing the hex digest of that `hash`. @@ -104,11 +102,11 @@ def self.nt_lan_manager_hex_digest_from_password_data(password_data) # def blank_password? - self.data.include? "#{BLANK_LM_HASH}:#{BLANK_NT_HASH}" + data.include? "#{BLANK_LM_HASH}:#{BLANK_NT_HASH}" end def lm_hash_present? - !self.data.start_with? BLANK_LM_HASH + !data.start_with? BLANK_LM_HASH end private @@ -117,17 +115,15 @@ def lm_hash_present? # ({Metasploit::Credential::Private#type}, {#data}) catches collision in a case-insensitive manner without the need # to use case-insensitive comparisons. def normalize_data - if data - self.data = data.downcase - end + return unless data + self.data = data.downcase end # Validates that {#data} is in the NTLM data format of :. Both hex # digests are 32 lowercase hexadecimal characters. def data_format - unless DATA_REGEXP.match(data) - errors.add(:data, :format) - end + return if DATA_REGEXP.match(data) + errors.add(:data, :format) end public diff --git a/app/models/metasploit/credential/password_hash.rb b/app/models/metasploit/credential/password_hash.rb index 2fcd88af..a694c5ba 100644 --- a/app/models/metasploit/credential/password_hash.rb +++ b/app/models/metasploit/credential/password_hash.rb @@ -15,8 +15,7 @@ class Metasploit::Credential::PasswordHash < Metasploit::Credential::Private # Validations # - validates :data, - presence: true + validates :data, presence: true Metasploit::Concern.run(self) end diff --git a/app/models/metasploit/credential/postgres_md5.rb b/app/models/metasploit/credential/postgres_md5.rb index 64929e5a..ef475c24 100644 --- a/app/models/metasploit/credential/postgres_md5.rb +++ b/app/models/metasploit/credential/postgres_md5.rb @@ -27,19 +27,16 @@ class Metasploit::Credential::PostgresMD5 < Metasploit::Credential::ReplayableHa # ({Metasploit::Credential::Private#type}, {#data}) catches collision in a case-insensitive manner without the need # to use case-insensitive comparisons. def normalize_data - if data - self.data = data.downcase - end + return unless data + self.data = data.downcase end def data_format - unless DATA_REGEXP.match(data) - errors.add(:data, 'is not in Postgres MD5 Hash format') - end + return if DATA_REGEXP.match(data) + errors.add(:data, 'is not in Postgres MD5 Hash format') end public Metasploit::Concern.run(self) - -end \ No newline at end of file +end diff --git a/app/models/metasploit/credential/private.rb b/app/models/metasploit/credential/private.rb index f1cde800..94fdbfe0 100644 --- a/app/models/metasploit/credential/private.rb +++ b/app/models/metasploit/credential/private.rb @@ -68,12 +68,12 @@ class Metasploit::Credential::Private < ActiveRecord::Base # search_with Metasploit::Credential::Search::Operator::Type, - class_names: %w{ + class_names: %w( Metasploit::Credential::NonreplayableHash Metasploit::Credential::NTLMHash Metasploit::Credential::Password Metasploit::Credential::SSHKey - } + ) # # Validations @@ -81,9 +81,7 @@ class Metasploit::Credential::Private < ActiveRecord::Base validates :data, non_nil: true, - uniqueness: { - scope: :type - } + uniqueness: { scope: :type } # # Instance Methods diff --git a/app/models/metasploit/credential/public.rb b/app/models/metasploit/credential/public.rb index 8a476d1c..cb779039 100644 --- a/app/models/metasploit/credential/public.rb +++ b/app/models/metasploit/credential/public.rb @@ -53,10 +53,10 @@ class Metasploit::Credential::Public < ActiveRecord::Base # search_with Metasploit::Credential::Search::Operator::Type, - class_names: %w{ + class_names: %w( Metasploit::Credential::BlankUsername Metasploit::Credential::Username - } + ) # # Instance Methods diff --git a/app/models/metasploit/credential/realm.rb b/app/models/metasploit/credential/realm.rb index c6531a04..21ff0375 100644 --- a/app/models/metasploit/credential/realm.rb +++ b/app/models/metasploit/credential/realm.rb @@ -54,9 +54,7 @@ class Metasploit::Credential::Realm < ActiveRecord::Base # search_attribute :key, - type: { - set: :string - } + type: { set: :string } search_attribute :value, type: :string @@ -65,15 +63,11 @@ class Metasploit::Credential::Realm < ActiveRecord::Base # validates :key, - inclusion: { - in: Metasploit::Model::Realm::Key::ALL - }, + inclusion: { in: Metasploit::Model::Realm::Key::ALL }, presence: true validates :value, presence: true, - uniqueness: { - scope: :key - } + uniqueness: { scope: :key } # # Class Methods diff --git a/app/models/metasploit/credential/ssh_key.rb b/app/models/metasploit/credential/ssh_key.rb index 225f3c34..c30ed179 100644 --- a/app/models/metasploit/credential/ssh_key.rb +++ b/app/models/metasploit/credential/ssh_key.rb @@ -22,8 +22,7 @@ class Metasploit::Credential::SSHKey < Metasploit::Credential::Private # Attribute Validations # - validates :data, - presence: true + validates :data, presence: true # # Method Validations # @@ -42,12 +41,9 @@ class Metasploit::Credential::SSHKey < Metasploit::Credential::Private # @return [false] if {#data} does not contain `'ENCRYPTED'` or {#data} is `nil`. # @return [true] if {#data} contains `'ENCRYPTED'`. def encrypted? - if data - # see https://github.com/net-ssh/net-ssh/blob/1b5db680fee66e1d846d0396eb1a68d3fabdc3de/lib/net/ssh/key_factory.rb#L72 - data.match(/ENCRYPTED/) - else - false - end + return false unless data + # see https://github.com/net-ssh/net-ssh/blob/1b5db680fee66e1d846d0396eb1a68d3fabdc3de/lib/net/ssh/key_factory.rb#L72 + data.match(/ENCRYPTED/) end # Whether the key data in {#data} is a private key. Only private keys are supported as public keys cannot be used @@ -56,12 +52,9 @@ def encrypted? # @return [false] if {#data} does not contain `'-----BEGIN PRIVATE KEY-----'` or {#data} is `nil`. # @return [true] if {#data} contains `'-----BEGIN PRIVATE KEY-----'`. def private? - if data - # @see https://github.com/net-ssh/net-ssh/blob/1b5db680fee66e1d846d0396eb1a68d3fabdc3de/lib/net/ssh/key_factory.rb#L56-L69 - data.match(/-----BEGIN (.+) PRIVATE KEY-----/) - else - false - end + return false unless data + # @see https://github.com/net-ssh/net-ssh/blob/1b5db680fee66e1d846d0396eb1a68d3fabdc3de/lib/net/ssh/key_factory.rb#L56-L69 + data.match(/-----BEGIN (.+) PRIVATE KEY-----/) end # The {#data key data}'s fingerprint, suitable for displaying to the @@ -79,22 +72,20 @@ def to_s # @return [OpenSSL::PKey::PKey] # @raise [ArgumentError, OpenSSL::PKey::PKeyError] if {#data} cannot be loaded def openssl_pkey_pkey - if data - ask_passphrase = false - filename = "#{self.class}#data" - passphrase = nil + return unless data + ask_passphrase = false + filename = "#{self.class}#data" + passphrase = nil - Net::SSH::KeyFactory.load_data_private_key(data, passphrase, ask_passphrase, filename) - end + Net::SSH::KeyFactory.load_data_private_key(data, passphrase, ask_passphrase, filename) end # Validates that {#data} contains a private key and NOT a public key or some other non-key data. # # @return [void] def private - unless private? - errors.add(:data, :not_private) - end + return if private? + errors.add(:data, :not_private) end # Validates that {#data} can be read by Net::SSH and a `OpenSSL::PKey::PKey` created from {#data}. Any exception @@ -102,13 +93,10 @@ def private # # @return [void] def readable - if data - begin - openssl_pkey_pkey - rescue ArgumentError, OpenSSL::PKey::PKeyError => error - errors[:data] << "#{error.class} #{error}" - end - end + return unless data + openssl_pkey_pkey + rescue ArgumentError, OpenSSL::PKey::PKeyError => error + errors[:data] << "#{error.class} #{error}" end # Validates that the private key is not encrypted as unencrypting the private key with its password is not supported: @@ -116,9 +104,8 @@ def readable # # @return [void] def unencrypted - if encrypted? - errors.add(:data, :encrypted) - end + return unless encrypted? + errors.add(:data, :encrypted) end Metasploit::Concern.run(self) diff --git a/app/validators/non_nil_validator.rb b/app/validators/non_nil_validator.rb index fff69c12..da77a52e 100644 --- a/app/validators/non_nil_validator.rb +++ b/app/validators/non_nil_validator.rb @@ -13,8 +13,7 @@ class NonNilValidator < ActiveModel::EachValidator # @param value [Object, nil] the value of `attribute`. # @return [void] def validate_each(model, attribute, value) - if value.nil? - model.errors.add(attribute, :nil) - end + return unless value.nil? + model.errors.add(attribute, :nil) end -end \ No newline at end of file +end diff --git a/lib/metasploit/credential.rb b/lib/metasploit/credential.rb index ca4d1101..6115e1c0 100644 --- a/lib/metasploit/credential.rb +++ b/lib/metasploit/credential.rb @@ -1,4 +1,3 @@ - # # Gems # @@ -60,4 +59,3 @@ def self.table_name_prefix end end end - diff --git a/lib/metasploit/credential/importer/base.rb b/lib/metasploit/credential/importer/base.rb index 938ec302..b35f9bdc 100644 --- a/lib/metasploit/credential/importer/base.rb +++ b/lib/metasploit/credential/importer/base.rb @@ -13,8 +13,8 @@ module Metasploit::Credential::Importer::Base Metasploit::Credential::NTLMHash, Metasploit::Credential::Password, Metasploit::Credential::PostgresMD5, - Metasploit::Credential::SSHKey].map(&:name) - + Metasploit::Credential::SSHKey + ].map(&:name) # Whitelist of the {Metasploit::Credential::Private} subclass names allowed # in short-form CSV imports. @@ -22,7 +22,8 @@ module Metasploit::Credential::Importer::Base Metasploit::Credential::NonreplayableHash, Metasploit::Credential::NTLMHash, Metasploit::Credential::Password, - Metasploit::Credential::PostgresMD5].map(&:name) + Metasploit::Credential::PostgresMD5 + ].map(&:name) included do include ActiveModel::Validations @@ -56,13 +57,12 @@ module Metasploit::Credential::Importer::Base validates :input, presence: true end - # # Instance Methods # # @param attributes [Hash{Symbol => String,nil}] - def initialize(attributes={}) + def initialize(attributes = {}) attributes.each do |attribute, value| public_send("#{attribute}=", value) end diff --git a/lib/metasploit/credential/version.rb b/lib/metasploit/credential/version.rb index c539ef8b..e4d57dd1 100644 --- a/lib/metasploit/credential/version.rb +++ b/lib/metasploit/credential/version.rb @@ -14,6 +14,7 @@ module Version MINOR = 0 # The patch version number, scoped to the {MAJOR} and {MINOR} version numbers. PATCH = 0 + PRERELEASE = 'rails-4.2' # # Module Methods @@ -30,11 +31,7 @@ module Version # on any branch other than master. def self.full version = "#{MAJOR}.#{MINOR}.#{PATCH}" - - if defined? PRERELEASE - version = "#{version}-#{PRERELEASE}" - end - + version = "#{version}-#{PRERELEASE}" if defined? PRERELEASE version end diff --git a/metasploit-credential.gemspec b/metasploit-credential.gemspec index b64cab61..f3220dd2 100644 --- a/metasploit-credential.gemspec +++ b/metasploit-credential.gemspec @@ -22,13 +22,6 @@ Gem::Specification.new do |s| s.add_development_dependency 'metasploit-version', '~> 0.1.3' - # patching inverse association in Mdm models. - s.add_runtime_dependency 'metasploit-concern', '~> 1.0' - # Various Metasploit::Credential records have associations to Mdm records - s.add_runtime_dependency 'metasploit_data_models', '~> 1.0' - # Metasploit::Model::Search - s.add_runtime_dependency 'metasploit-model', '~> 1.0' - s.add_runtime_dependency 'railties' # Metasploit::Credential::NTLMHash helper methods s.add_runtime_dependency 'rubyntlm' diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb index 01c05fc9..6c28e278 100644 --- a/spec/dummy/config/environments/test.rb +++ b/spec/dummy/config/environments/test.rb @@ -13,10 +13,9 @@ config.eager_load = false # Configure static asset server for tests with Cache-Control for performance - config.serve_static_assets = true + config.serve_static_files = true config.static_cache_control = "public, max-age=3600" - # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false diff --git a/spec/dummy/db/structure.sql b/spec/dummy/db/structure.sql index 672f0426..4b031778 100644 --- a/spec/dummy/db/structure.sql +++ b/spec/dummy/db/structure.sql @@ -640,7 +640,7 @@ ALTER SEQUENCE macros_id_seq OWNED BY macros.id; CREATE TABLE metasploit_credential_cores ( id integer NOT NULL, origin_id integer NOT NULL, - origin_type character varying(255) NOT NULL, + origin_type character varying NOT NULL, private_id integer, public_id integer, realm_id integer, @@ -678,8 +678,8 @@ CREATE TABLE metasploit_credential_logins ( id integer NOT NULL, core_id integer NOT NULL, service_id integer NOT NULL, - access_level character varying(255), - status character varying(255) NOT NULL, + access_level character varying, + status character varying NOT NULL, last_attempted_at timestamp without time zone, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL @@ -869,11 +869,11 @@ ALTER SEQUENCE metasploit_credential_origin_sessions_id_seq OWNED BY metasploit_ CREATE TABLE metasploit_credential_privates ( id integer NOT NULL, - type character varying(255) NOT NULL, + type character varying NOT NULL, data text NOT NULL, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, - jtr_format character varying(255) + jtr_format character varying ); @@ -902,10 +902,10 @@ ALTER SEQUENCE metasploit_credential_privates_id_seq OWNED BY metasploit_credent CREATE TABLE metasploit_credential_publics ( id integer NOT NULL, - username character varying(255) NOT NULL, + username character varying NOT NULL, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, - type character varying(255) NOT NULL + type character varying NOT NULL ); @@ -934,8 +934,8 @@ ALTER SEQUENCE metasploit_credential_publics_id_seq OWNED BY metasploit_credenti CREATE TABLE metasploit_credential_realms ( id integer NOT NULL, - key character varying(255) NOT NULL, - value character varying(255) NOT NULL, + key character varying NOT NULL, + value character varying NOT NULL, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -4090,3 +4090,4 @@ INSERT INTO schema_migrations (version) VALUES ('7'); INSERT INTO schema_migrations (version) VALUES ('8'); INSERT INTO schema_migrations (version) VALUES ('9'); +