Module: Metasploit::Model::Module::Instance
- Extended by:
- ActiveModel::Naming, ActiveSupport::Autoload, ActiveSupport::Concern, ClassMethods
- Includes:
- Translation
- Defined in:
- lib/metasploit/model/module/instance.rb
Overview
Code shared between Mdm::Module::Instance and Metasploit::Framework::Module::Instance.
Defined Under Namespace
Modules: ClassMethods, Spec
Constant Summary collapse
- DYNAMIC_LENGTH_VALIDATION_OPTIONS_BY_MODULE_TYPE_BY_ATTRIBUTE =
#dynamic_length_validation_options by #module_type by attribute.
{ actions: { Metasploit::Model::Module::Type::AUX => { minimum: 0 }, Metasploit::Model::Module::Type::ENCODER => { is: 0 }, Metasploit::Model::Module::Type::EXPLOIT => { is: 0 }, Metasploit::Model::Module::Type::NOP => { is: 0 }, Metasploit::Model::Module::Type::PAYLOAD => { is: 0 }, Metasploit::Model::Module::Type::POST => { minimum: 0 } }, module_architectures: { Metasploit::Model::Module::Type::AUX => { is: 0 }, Metasploit::Model::Module::Type::ENCODER => { minimum: 1 }, Metasploit::Model::Module::Type::EXPLOIT => { minimum: 1 }, Metasploit::Model::Module::Type::NOP => { minimum: 1 }, Metasploit::Model::Module::Type::PAYLOAD => { minimum: 1 }, Metasploit::Model::Module::Type::POST => { minimum: 1 } }, module_platforms: { Metasploit::Model::Module::Type::AUX => { is: 0 }, Metasploit::Model::Module::Type::ENCODER => { is: 0 }, Metasploit::Model::Module::Type::EXPLOIT => { minimum: 1 }, Metasploit::Model::Module::Type::NOP => { is: 0 }, Metasploit::Model::Module::Type::PAYLOAD => { minimum: 1 }, Metasploit::Model::Module::Type::POST => { minimum: 1 } }, module_references: { Metasploit::Model::Module::Type::AUX => { minimum: 0 }, Metasploit::Model::Module::Type::ENCODER => { is: 0 }, Metasploit::Model::Module::Type::EXPLOIT => { minimum: 1 }, Metasploit::Model::Module::Type::NOP => { is: 0 }, Metasploit::Model::Module::Type::PAYLOAD => { is: 0 }, Metasploit::Model::Module::Type::POST => { minimum: 0 } }, targets: { Metasploit::Model::Module::Type::AUX => { is: 0 }, Metasploit::Model::Module::Type::ENCODER => { is: 0 }, Metasploit::Model::Module::Type::EXPLOIT => { minimum: 1 }, Metasploit::Model::Module::Type::NOP => { is: 0 }, Metasploit::Model::Module::Type::PAYLOAD => { is: 0 }, Metasploit::Model::Module::Type::POST => { is: 0 } } }
- MINIMUM_MODULE_AUTHORS_LENGTH =
Minimum length of #module_authors.
1- PRIVILEGES =
#privileged is Boolean so, valid values are just
trueandfalse, but since both the validation and factory need an array of valid values, this constant exists. [ false, true ]
- STANCED_MODULE_TYPES =
[ Metasploit::Model::Module::Type::AUX, Metasploit::Model::Module::Type::EXPLOIT ]
Instance Attribute Summary collapse
-
#actions ⇒ Array<Metasploit::Model::Module::Action>
Auxiliary actions to perform when this running this module.
-
#architectures ⇒ Array<Metasploit::Model::Architecture>
readonly
The architectures supported by this module.
-
#authors ⇒ Array<Metasploit::Model::Author>
readonly
The names of the authors of this module.
-
#default_action ⇒ Metasploit::Model::Module::Action
The default action in #actions.
-
#default_target ⇒ Metasploit::Model::Module::Target
The default target in #targets.
-
#description ⇒ String
A long, paragraph description of what the module does.
-
#disclosed_on ⇒ Date?
The date the vulnerability exploited by this module was disclosed to the public.
-
#email_addresses ⇒ Array<Metasploit::Model::EmailAddress>
readonly
The email addresses of the authors of this module.
-
#license ⇒ String
The name of the software license for the module's code.
-
#module_architectures ⇒ Array<Metasploit::Model::Module::Architecture>
Joins this with #architectures.
-
#module_authors ⇒ Array<Metasploit::Model::Module::Author>
Joins this with #authors and #email_addresses to model the name and email address used for an author entry in the module metadata.
-
#module_class ⇒ Metasploit::Model::Module::Class
Class-derived metadata to go along with the instance-derived metadata in this model.
-
#module_platforms ⇒ Array<Metasploit::Model::Module::Platform>
Joins this with #platforms.
-
#name ⇒ String
The human readable name of the module.
-
#platforms ⇒ Array<Metasploit::Model::Module::Platform>
readonly
Platforms supported by this module.
-
#privileged ⇒ Boolean
Whether this module requires privileged access to run.
-
#references ⇒ Array<Metasploit::Model::Reference>
readonly
External references to the exploit or proof-of-concept (PoC) code in this module.
-
#stance ⇒ 'active', ...
Whether the module is active or passive.
-
#targets ⇒ Array<Metasploit::Model::Module::Target>
Names of targets with different configurations that can be exploited by this module.
-
#vulnerable_hosts ⇒ Array<Metasploit::Model::Host>
readonly
Hosts vulnerable to this module.
-
#vulnerable_services ⇒ Array<Metasploit::Model::Service>
readonly
Services vulnerable to this module.
-
#vulns ⇒ Array<Metasploit::Model::Vuln>
readonly
Vulnerabilities with same reference as this module.
Class Method Summary collapse
-
.module_types_that_allow(attribute) ⇒ Array<String>
Values of #module_type (members of Type::ALL), which have an exact length (
:is) or maximum length (:maximum) greater than 0 for the givenattribute.
Instance Method Summary collapse
-
#allows?(attribute) ⇒ false, true
Whether the given
attributeis allowed to have elements. -
#architectures_from_targets ⇒ void
private
Validates that the #module_architectures architectures match the #targets target_architectures architectures.
-
#dynamic_length_validation_options(attribute) ⇒ {}, Hash{Symbol => Integer}
The dynamic length valdiations, such as
:isand:minimumfor the given attribute for the current #module_type. -
#human_architecture_set(architecture_set) ⇒ String
private
Converts a SetMetasploit::Model::Architecture to a human readable representation including the Architecture#abbreviation.
-
#human_platform_set(platform_set) ⇒ String
private
Converts a SetMetasploit::Model::Platform to a human-readable representation including the Platform#fully_qualified_name.
-
#human_set(strings) ⇒ String
private
Converts strings to a human-readable set notation.
-
#module_type ⇒ Object
The Class#module_type of the #module_class.
-
#platforms_from_targets ⇒ void
private
Validates that #module_platforms platforms match the #targets target_platforms platforms.
-
#stanced? ⇒ false, true
Whether #module_type requires #stance to be set or to be
nil.
Instance Attribute Details
#actions ⇒ Array<Metasploit::Model::Module::Action>
Auxiliary actions to perform when this running this module.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 259
|
#architectures ⇒ Array<Metasploit::Model::Architecture> (readonly)
The architectures supported by this module.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 300
|
#authors ⇒ Array<Metasploit::Model::Author> (readonly)
The names of the authors of this module.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 305
|
#default_action ⇒ Metasploit::Model::Module::Action
The default action in #actions.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 264
|
#default_target ⇒ Metasploit::Model::Module::Target
The default target in #targets.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 269
|
#description ⇒ String
A long, paragraph description of what the module does.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 344
|
#disclosed_on ⇒ Date?
The date the vulnerability exploited by this module was disclosed to the public.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 349
|
#email_addresses ⇒ Array<Metasploit::Model::EmailAddress> (readonly)
The email addresses of the authors of this module.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 310
|
#license ⇒ String
The name of the software license for the module's code.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 354
|
#module_architectures ⇒ Array<Metasploit::Model::Module::Architecture>
Joins this with #architectures.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 274
|
#module_authors ⇒ Array<Metasploit::Model::Module::Author>
Joins this with #authors and #email_addresses to model the name and email address used for an author entry in the module metadata.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 279
|
#module_class ⇒ Metasploit::Model::Module::Class
Class-derived metadata to go along with the instance-derived metadata in this model.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 285
|
#module_platforms ⇒ Array<Metasploit::Model::Module::Platform>
Joins this with #platforms.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 290
|
#name ⇒ String
The human readable name of the module. It is unrelated to Class#full_name or Class#reference_name and is better thought of as a short summary of the #description.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 359
|
#platforms ⇒ Array<Metasploit::Model::Module::Platform> (readonly)
Platforms supported by this module.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 315
|
#privileged ⇒ Boolean
Whether this module requires privileged access to run.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 366
|
#references ⇒ Array<Metasploit::Model::Reference> (readonly)
External references to the exploit or proof-of-concept (PoC) code in this module.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 320
|
#stance ⇒ 'active', ...
Whether the module is active or passive. nil if the #module_type is not #stanced?.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 371
|
#targets ⇒ Array<Metasploit::Model::Module::Target>
Names of targets with different configurations that can be exploited by this module.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 295
|
#vulnerable_hosts ⇒ Array<Metasploit::Model::Host> (readonly)
Hosts vulnerable to this module.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 330
|
#vulnerable_services ⇒ Array<Metasploit::Model::Service> (readonly)
Services vulnerable to this module.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 335
|
#vulns ⇒ Array<Metasploit::Model::Vuln> (readonly)
Vulnerabilities with same reference as this module.
|
|
# File 'lib/metasploit/model/module/instance.rb', line 325
|
Class Method Details
.module_types_that_allow(attribute) ⇒ Array<String>
Values of #module_type (members of Type::ALL), which have an exact length
(:is) or maximum length (:maximum) greater than 0 for the given attribute.
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
# File 'lib/metasploit/model/module/instance.rb', line 453 def self.module_types_that_allow(attribute) = DYNAMIC_LENGTH_VALIDATION_OPTIONS_BY_MODULE_TYPE_BY_ATTRIBUTE.fetch(attribute) .each_with_object([]) { |(module_type, ), module_types| is = [:is] if is if is > 0 module_types << module_type end else maximum = [:maximum] if maximum if maximum > 0 module_types << module_type end else module_types << module_type end end } end |
Instance Method Details
#allows?(attribute) ⇒ false, true
Whether the given attribute is allowed to have elements.
488 489 490 491 492 493 494 495 496 497 |
# File 'lib/metasploit/model/module/instance.rb', line 488 def allows?(attribute) if Metasploit::Model::Module::Type::ALL.include? module_type self.class.allows?( attribute: attribute, module_type: module_type ) else false end end |
#architectures_from_targets ⇒ void (private)
This method returns an undefined value.
Validates that the #module_architectures architectures match the #targets target_architectures architectures.
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
# File 'lib/metasploit/model/module/instance.rb', line 540 def architectures_from_targets actual_architecture_set = Set.new module_architectures.map(&:architecture) expected_architecture_set = Set.new targets.each do |module_target| module_target.target_architectures.each do |target_architecture| expected_architecture_set.add target_architecture.architecture end end extra_architecture_set = actual_architecture_set - expected_architecture_set unless extra_architecture_set.empty? human_extra_architectures = human_architecture_set(extra_architecture_set) errors.add(:architectures, :extra, extra: human_extra_architectures) end missing_architecture_set = expected_architecture_set - actual_architecture_set unless missing_architecture_set.empty? human_missing_architectures = human_architecture_set(missing_architecture_set) errors.add(:architectures, :missing, missing: human_missing_architectures) end end |
#dynamic_length_validation_options(attribute) ⇒ {}, Hash{Symbol => Integer}
The dynamic length valdiations, such as :is and :minimum for the given attribute for the current
#module_type.
505 506 507 508 509 510 511 512 513 514 |
# File 'lib/metasploit/model/module/instance.rb', line 505 def (attribute) if Metasploit::Model::Module::Type::ALL.include? module_type self.class.( module_type: module_type, attribute: attribute ) else {} end end |
#human_architecture_set(architecture_set) ⇒ String (private)
Converts a SetMetasploit::Model::Architecture to a human readable representation including the Architecture#abbreviation.
571 572 573 574 575 |
# File 'lib/metasploit/model/module/instance.rb', line 571 def human_architecture_set(architecture_set) abbreviations = architecture_set.map(&:abbreviation) human_set(abbreviations) end |
#human_platform_set(platform_set) ⇒ String (private)
Converts a SetMetasploit::Model::Platform to a human-readable representation including the Platform#fully_qualified_name.
581 582 583 584 585 |
# File 'lib/metasploit/model/module/instance.rb', line 581 def human_platform_set(platform_set) fully_qualified_names = platform_set.map(&:fully_qualified_name) human_set(fully_qualified_names) end |
#human_set(strings) ⇒ String (private)
Converts strings to a human-readable set notation.
590 591 592 593 594 595 |
# File 'lib/metasploit/model/module/instance.rb', line 590 def human_set(strings) sorted = strings.sort comma_separated = sorted.join(', ') "{#{comma_separated}}" end |
#module_type ⇒ Object
The Class#module_type of the #module_class.
520 521 522 |
# File 'lib/metasploit/model/module/instance.rb', line 520 delegate :module_type, allow_nil: true, to: :module_class |
#platforms_from_targets ⇒ void (private)
This method returns an undefined value.
Validates that #module_platforms platforms match the #targets target_platforms platforms.
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 |
# File 'lib/metasploit/model/module/instance.rb', line 602 def platforms_from_targets actual_platform_set = Set.new module_platforms.map(&:platform) expected_platform_set = Set.new targets.each do |module_target| module_target.target_platforms.each do |target_platform| expected_platform_set.add target_platform.platform end end extra_platform_set = actual_platform_set - expected_platform_set unless extra_platform_set.empty? human_extra_platforms = human_platform_set(extra_platform_set) errors.add(:platforms, :extra, extra: human_extra_platforms) end missing_platform_set = expected_platform_set - actual_platform_set unless missing_platform_set.empty? human_missing_platforms = human_platform_set(missing_platform_set) errors.add(:platforms, :missing, missing: human_missing_platforms) end end |
#stanced? ⇒ false, true
Whether #module_type requires #stance to be set or to be nil.
528 529 530 |
# File 'lib/metasploit/model/module/instance.rb', line 528 def stanced? self.class.stanced?(module_type) end |