metasploit-model 0.28.0 → 0.29.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +3 -1
- data/config/locales/en.yml +0 -171
- data/lib/metasploit/model.rb +0 -2
- data/lib/metasploit/model/spec.rb +0 -130
- data/lib/metasploit/model/version.rb +1 -1
- data/spec/support/shared/examples/metasploit/model/search/operator/help.rb +4 -6
- data/spec/support/shared/examples/metasploit/model/translation.rb +1 -1
- data/spec/support/shared/examples/search_association.rb +1 -1
- data/spec/support/shared/examples/search_with.rb +4 -2
- metadata +3 -349
- data/app/models/metasploit/model/module/ancestor/spec/template.rb +0 -125
- data/app/models/metasploit/model/module/class/spec/template.rb +0 -92
- data/app/models/metasploit/model/module/instance/spec/template.rb +0 -97
- data/app/models/metasploit/model/spec/template.rb +0 -277
- data/app/validators/derivation_validator.rb +0 -17
- data/app/validators/dynamic_length_validator.rb +0 -45
- data/lib/metasploit/model/architecture.rb +0 -342
- data/lib/metasploit/model/author.rb +0 -54
- data/lib/metasploit/model/authority.rb +0 -141
- data/lib/metasploit/model/authority/bid.rb +0 -10
- data/lib/metasploit/model/authority/cve.rb +0 -10
- data/lib/metasploit/model/authority/msb.rb +0 -10
- data/lib/metasploit/model/authority/osvdb.rb +0 -10
- data/lib/metasploit/model/authority/pmasa.rb +0 -10
- data/lib/metasploit/model/authority/secunia.rb +0 -10
- data/lib/metasploit/model/authority/us_cert_vu.rb +0 -10
- data/lib/metasploit/model/authority/waraxe.rb +0 -31
- data/lib/metasploit/model/authority/zdi.rb +0 -10
- data/lib/metasploit/model/derivation.rb +0 -109
- data/lib/metasploit/model/derivation/full_name.rb +0 -19
- data/lib/metasploit/model/email_address.rb +0 -124
- data/lib/metasploit/model/module.rb +0 -20
- data/lib/metasploit/model/module/action.rb +0 -52
- data/lib/metasploit/model/module/ancestor.rb +0 -491
- data/lib/metasploit/model/module/ancestor/spec.rb +0 -6
- data/lib/metasploit/model/module/architecture.rb +0 -34
- data/lib/metasploit/model/module/author.rb +0 -40
- data/lib/metasploit/model/module/class.rb +0 -403
- data/lib/metasploit/model/module/class/spec.rb +0 -6
- data/lib/metasploit/model/module/handler.rb +0 -29
- data/lib/metasploit/model/module/instance.rb +0 -622
- data/lib/metasploit/model/module/instance/spec.rb +0 -6
- data/lib/metasploit/model/module/path.rb +0 -159
- data/lib/metasploit/model/module/platform.rb +0 -32
- data/lib/metasploit/model/module/rank.rb +0 -85
- data/lib/metasploit/model/module/reference.rb +0 -32
- data/lib/metasploit/model/module/stance.rb +0 -16
- data/lib/metasploit/model/module/target.rb +0 -78
- data/lib/metasploit/model/module/target/architecture.rb +0 -34
- data/lib/metasploit/model/module/target/platform.rb +0 -34
- data/lib/metasploit/model/module/type.rb +0 -38
- data/lib/metasploit/model/platform.rb +0 -246
- data/lib/metasploit/model/real_pathname.rb +0 -16
- data/lib/metasploit/model/reference.rb +0 -104
- data/spec/app/models/metasploit/model/module/ancestor/spec/template_spec.rb +0 -174
- data/spec/app/models/metasploit/model/module/class/spec/template_spec.rb +0 -222
- data/spec/app/models/metasploit/model/module/instance/spec/template_spec.rb +0 -201
- data/spec/app/models/metasploit/model/search/operator/deprecated/app_spec.rb +0 -62
- data/spec/app/models/metasploit/model/search/operator/deprecated/author_spec.rb +0 -197
- data/spec/app/models/metasploit/model/search/operator/deprecated/authority_spec.rb +0 -135
- data/spec/app/models/metasploit/model/search/operator/deprecated/platform_spec.rb +0 -124
- data/spec/app/models/metasploit/model/search/operator/deprecated/ref_spec.rb +0 -387
- data/spec/app/models/metasploit/model/search/operator/deprecated/text_spec.rb +0 -399
- data/spec/app/models/metasploit/model/spec/template_spec.rb +0 -23
- data/spec/app/validators/derivation_validator_spec.rb +0 -92
- data/spec/app/validators/dynamic_length_validator_spec.rb +0 -293
- data/spec/dummy/app/models/dummy/architecture.rb +0 -92
- data/spec/dummy/app/models/dummy/author.rb +0 -15
- data/spec/dummy/app/models/dummy/authority.rb +0 -130
- data/spec/dummy/app/models/dummy/email_address.rb +0 -27
- data/spec/dummy/app/models/dummy/module/action.rb +0 -25
- data/spec/dummy/app/models/dummy/module/ancestor.rb +0 -67
- data/spec/dummy/app/models/dummy/module/architecture.rb +0 -19
- data/spec/dummy/app/models/dummy/module/author.rb +0 -28
- data/spec/dummy/app/models/dummy/module/class.rb +0 -69
- data/spec/dummy/app/models/dummy/module/instance.rb +0 -209
- data/spec/dummy/app/models/dummy/module/path.rb +0 -64
- data/spec/dummy/app/models/dummy/module/platform.rb +0 -19
- data/spec/dummy/app/models/dummy/module/rank.rb +0 -44
- data/spec/dummy/app/models/dummy/module/reference.rb +0 -19
- data/spec/dummy/app/models/dummy/module/target.rb +0 -62
- data/spec/dummy/app/models/dummy/module/target/architecture.rb +0 -19
- data/spec/dummy/app/models/dummy/module/target/platform.rb +0 -19
- data/spec/dummy/app/models/dummy/platform.rb +0 -58
- data/spec/dummy/app/models/dummy/reference.rb +0 -31
- data/spec/dummy/spec/factories/dummy/architectures.rb +0 -13
- data/spec/dummy/spec/factories/dummy/authorities.rb +0 -32
- data/spec/dummy/spec/factories/dummy/authors.rb +0 -8
- data/spec/dummy/spec/factories/dummy/email_addresses.rb +0 -8
- data/spec/dummy/spec/factories/dummy/module/actions.rb +0 -13
- data/spec/dummy/spec/factories/dummy/module/ancestors.rb +0 -45
- data/spec/dummy/spec/factories/dummy/module/architectures.rb +0 -35
- data/spec/dummy/spec/factories/dummy/module/authors.rb +0 -10
- data/spec/dummy/spec/factories/dummy/module/classes.rb +0 -40
- data/spec/dummy/spec/factories/dummy/module/instances.rb +0 -86
- data/spec/dummy/spec/factories/dummy/module/paths.rb +0 -16
- data/spec/dummy/spec/factories/dummy/module/platforms.rb +0 -35
- data/spec/dummy/spec/factories/dummy/module/ranks.rb +0 -14
- data/spec/dummy/spec/factories/dummy/module/references.rb +0 -17
- data/spec/dummy/spec/factories/dummy/module/target/architectures.rb +0 -40
- data/spec/dummy/spec/factories/dummy/module/target/platforms.rb +0 -41
- data/spec/dummy/spec/factories/dummy/module/targets.rb +0 -46
- data/spec/dummy/spec/factories/dummy/platforms.rb +0 -3
- data/spec/dummy/spec/factories/dummy/references.rb +0 -26
- data/spec/factories/metasploit/model/architectures.rb +0 -6
- data/spec/factories/metasploit/model/authorities.rb +0 -28
- data/spec/factories/metasploit/model/authors.rb +0 -9
- data/spec/factories/metasploit/model/email_addresses.rb +0 -14
- data/spec/factories/metasploit/model/module/actions.rb +0 -9
- data/spec/factories/metasploit/model/module/ancestors.rb +0 -180
- data/spec/factories/metasploit/model/module/architectures.rb +0 -15
- data/spec/factories/metasploit/model/module/classes.rb +0 -47
- data/spec/factories/metasploit/model/module/handlers.rb +0 -3
- data/spec/factories/metasploit/model/module/instances.rb +0 -83
- data/spec/factories/metasploit/model/module/paths.rb +0 -51
- data/spec/factories/metasploit/model/module/platforms.rb +0 -15
- data/spec/factories/metasploit/model/module/ranks.rb +0 -9
- data/spec/factories/metasploit/model/module/references.rb +0 -11
- data/spec/factories/metasploit/model/module/stances.rb +0 -3
- data/spec/factories/metasploit/model/module/targets.rb +0 -22
- data/spec/factories/metasploit/model/module/types.rb +0 -5
- data/spec/factories/metasploit/model/references.rb +0 -88
- data/spec/lib/metasploit/model/architecture_spec.rb +0 -52
- data/spec/lib/metasploit/model/author_spec.rb +0 -6
- data/spec/lib/metasploit/model/authority/bid_spec.rb +0 -17
- data/spec/lib/metasploit/model/authority/cve_spec.rb +0 -17
- data/spec/lib/metasploit/model/authority/msb_spec.rb +0 -17
- data/spec/lib/metasploit/model/authority/osvdb_spec.rb +0 -17
- data/spec/lib/metasploit/model/authority/pmasa_spec.rb +0 -17
- data/spec/lib/metasploit/model/authority/secunia_spec.rb +0 -17
- data/spec/lib/metasploit/model/authority/us_cert_vu_spec.rb +0 -17
- data/spec/lib/metasploit/model/authority/waraxe_spec.rb +0 -51
- data/spec/lib/metasploit/model/authority/zdi_spec.rb +0 -21
- data/spec/lib/metasploit/model/authority_spec.rb +0 -10
- data/spec/lib/metasploit/model/derivation/full_name_spec.rb +0 -75
- data/spec/lib/metasploit/model/derivation_spec.rb +0 -217
- data/spec/lib/metasploit/model/email_address_spec.rb +0 -19
- data/spec/lib/metasploit/model/module/action_spec.rb +0 -6
- data/spec/lib/metasploit/model/module/ancestor_spec.rb +0 -6
- data/spec/lib/metasploit/model/module/architecture_spec.rb +0 -9
- data/spec/lib/metasploit/model/module/author_spec.rb +0 -6
- data/spec/lib/metasploit/model/module/class_spec.rb +0 -19
- data/spec/lib/metasploit/model/module/handler_spec.rb +0 -61
- data/spec/lib/metasploit/model/module/instance_spec.rb +0 -183
- data/spec/lib/metasploit/model/module/path_spec.rb +0 -6
- data/spec/lib/metasploit/model/module/platform_spec.rb +0 -9
- data/spec/lib/metasploit/model/module/rank_spec.rb +0 -29
- data/spec/lib/metasploit/model/module/reference_spec.rb +0 -9
- data/spec/lib/metasploit/model/module/stance_spec.rb +0 -30
- data/spec/lib/metasploit/model/module/target/architecture_spec.rb +0 -9
- data/spec/lib/metasploit/model/module/target/platform_spec.rb +0 -9
- data/spec/lib/metasploit/model/module/target_spec.rb +0 -9
- data/spec/lib/metasploit/model/module/type_spec.rb +0 -125
- data/spec/lib/metasploit/model/platform_spec.rb +0 -100
- data/spec/lib/metasploit/model/reference_spec.rb +0 -21
- data/spec/support/shared/contexts/metasploit/model/module/ancestor/contents/metasploit_module.rb +0 -12
- data/spec/support/shared/contexts/metasploit/model/module/ancestor/factory/contents.rb +0 -10
- data/spec/support/shared/contexts/metasploit/model/module/ancestor/factory/contents/metasploit_module.rb +0 -15
- data/spec/support/shared/examples/derives.rb +0 -115
- data/spec/support/shared/examples/metasploit/model/architecture.rb +0 -425
- data/spec/support/shared/examples/metasploit/model/architecture/seed.rb +0 -25
- data/spec/support/shared/examples/metasploit/model/author.rb +0 -27
- data/spec/support/shared/examples/metasploit/model/authority.rb +0 -124
- data/spec/support/shared/examples/metasploit/model/authority/seed.rb +0 -49
- data/spec/support/shared/examples/metasploit/model/email_address.rb +0 -220
- data/spec/support/shared/examples/metasploit/model/module/action.rb +0 -26
- data/spec/support/shared/examples/metasploit/model/module/ancestor.rb +0 -2004
- data/spec/support/shared/examples/metasploit/model/module/ancestor/payload_factory.rb +0 -63
- data/spec/support/shared/examples/metasploit/model/module/architecture.rb +0 -36
- data/spec/support/shared/examples/metasploit/model/module/author.rb +0 -29
- data/spec/support/shared/examples/metasploit/model/module/class.rb +0 -1514
- data/spec/support/shared/examples/metasploit/model/module/handler.rb +0 -21
- data/spec/support/shared/examples/metasploit/model/module/instance.rb +0 -1384
- data/spec/support/shared/examples/metasploit/model/module/instance/class_methods.rb +0 -537
- data/spec/support/shared/examples/metasploit/model/module/instance/is_not_stanced_with_module_type.rb +0 -22
- data/spec/support/shared/examples/metasploit/model/module/instance/is_stanced_with_module_type.rb +0 -38
- data/spec/support/shared/examples/metasploit/model/module/instance/validates/dynamic_length_of.rb +0 -131
- data/spec/support/shared/examples/metasploit/model/module/path.rb +0 -493
- data/spec/support/shared/examples/metasploit/model/module/platform.rb +0 -36
- data/spec/support/shared/examples/metasploit/model/module/rank.rb +0 -92
- data/spec/support/shared/examples/metasploit/model/module/reference.rb +0 -16
- data/spec/support/shared/examples/metasploit/model/module/target.rb +0 -29
- data/spec/support/shared/examples/metasploit/model/module/target/architecture.rb +0 -56
- data/spec/support/shared/examples/metasploit/model/module/target/platform.rb +0 -56
- data/spec/support/shared/examples/metasploit/model/platform.rb +0 -213
- data/spec/support/shared/examples/metasploit/model/real_pathname.rb +0 -29
- data/spec/support/shared/examples/metasploit/model/reference.rb +0 -410
- data/spec/support/shared/examples/search/query/metasploit/model/search/operator/deprecated/app.rb +0 -44
- data/spec/support/shared/examples/search/query/metasploit/model/search/operator/deprecated/authority.rb +0 -72
- data/spec/support/templates/metasploit/model/module/ancestors/_attributes.rb.erb +0 -9
- data/spec/support/templates/metasploit/model/module/ancestors/_methods.rb.erb +0 -8
- data/spec/support/templates/metasploit/model/module/ancestors/_validations.rb.erb +0 -6
- data/spec/support/templates/metasploit/model/module/ancestors/base.rb.erb +0 -3
- data/spec/support/templates/metasploit/model/module/ancestors/module_types/_auxiliary.rb.erb +0 -1
- data/spec/support/templates/metasploit/model/module/ancestors/module_types/_encoder.rb.erb +0 -1
- data/spec/support/templates/metasploit/model/module/ancestors/module_types/_exploit.rb.erb +0 -1
- data/spec/support/templates/metasploit/model/module/ancestors/module_types/_non_payload.rb.erb +0 -5
- data/spec/support/templates/metasploit/model/module/ancestors/module_types/_nop.rb.erb +0 -1
- data/spec/support/templates/metasploit/model/module/ancestors/module_types/_payload.rb.erb +0 -4
- data/spec/support/templates/metasploit/model/module/ancestors/module_types/_post.rb.erb +0 -1
- data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_handled.rb.erb +0 -20
- data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_single.rb.erb +0 -1
- data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_stage.rb.erb +0 -0
- data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_stager.rb.erb +0 -1
- data/spec/support/templates/metasploit/model/module/classes/_methods.rb.erb +0 -9
@@ -1,20 +0,0 @@
|
|
1
|
-
# Namespace that maps to `Mdm::Module` and `Metasploit::Framework::Module` and contains constants and mixins to
|
2
|
-
# DRY the implementation of the in-memory and in-database models in those namespaces.
|
3
|
-
module Metasploit::Model::Module
|
4
|
-
extend ActiveSupport::Autoload
|
5
|
-
|
6
|
-
autoload :Action
|
7
|
-
autoload :Ancestor
|
8
|
-
autoload :Architecture
|
9
|
-
autoload :Author
|
10
|
-
autoload :Class
|
11
|
-
autoload :Handler
|
12
|
-
autoload :Instance
|
13
|
-
autoload :Path
|
14
|
-
autoload :Platform
|
15
|
-
autoload :Rank
|
16
|
-
autoload :Reference
|
17
|
-
autoload :Stance
|
18
|
-
autoload :Target
|
19
|
-
autoload :Type
|
20
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# Code shared between `Mdm::Module::Action` and `Metasploit::Framework::Module::Action`.
|
2
|
-
module Metasploit::Model::Module::Action
|
3
|
-
extend ActiveModel::Naming
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
include Metasploit::Model::Translation
|
7
|
-
|
8
|
-
included do
|
9
|
-
include ActiveModel::MassAssignmentSecurity
|
10
|
-
include ActiveModel::Validations
|
11
|
-
include Metasploit::Model::Search
|
12
|
-
|
13
|
-
#
|
14
|
-
# Mass Assignment Security
|
15
|
-
#
|
16
|
-
|
17
|
-
attr_accessible :name
|
18
|
-
|
19
|
-
#
|
20
|
-
# Search Attributes
|
21
|
-
#
|
22
|
-
|
23
|
-
search_attribute :name, :type => :string
|
24
|
-
|
25
|
-
#
|
26
|
-
# Validations
|
27
|
-
#
|
28
|
-
|
29
|
-
validates :module_instance,
|
30
|
-
:presence => true
|
31
|
-
validates :name,
|
32
|
-
:presence => true
|
33
|
-
end
|
34
|
-
|
35
|
-
#
|
36
|
-
# Associations
|
37
|
-
#
|
38
|
-
|
39
|
-
# @!attribute [rw] module_instance
|
40
|
-
# Module that has this action.
|
41
|
-
#
|
42
|
-
# @return [Metasploit::Model::Module::Instance]
|
43
|
-
|
44
|
-
#
|
45
|
-
# Attributes
|
46
|
-
#
|
47
|
-
|
48
|
-
# @!attribute [rw] name
|
49
|
-
# The name of this action.
|
50
|
-
#
|
51
|
-
# @return [String]
|
52
|
-
end
|
@@ -1,491 +0,0 @@
|
|
1
|
-
# Code shared between `Mdm::Module::Ancestor` and `Metasploit::Framework::Module::Ancestor`.
|
2
|
-
module Metasploit::Model::Module::Ancestor
|
3
|
-
extend ActiveModel::Naming
|
4
|
-
extend ActiveSupport::Autoload
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
include Metasploit::Model::Translation
|
8
|
-
|
9
|
-
autoload :Spec
|
10
|
-
|
11
|
-
#
|
12
|
-
# CONSTANTS
|
13
|
-
#
|
14
|
-
|
15
|
-
# The directory for a given {#module_type} is a not always the pluralization of #module_type, so this maps the
|
16
|
-
# #module_type to the type directory that is used to generate the #real_path from the #module_type and
|
17
|
-
# #reference_name.
|
18
|
-
DIRECTORY_BY_MODULE_TYPE = {
|
19
|
-
Metasploit::Model::Module::Type::AUX => Metasploit::Model::Module::Type::AUX,
|
20
|
-
Metasploit::Model::Module::Type::ENCODER => Metasploit::Model::Module::Type::ENCODER.pluralize,
|
21
|
-
Metasploit::Model::Module::Type::EXPLOIT => Metasploit::Model::Module::Type::EXPLOIT.pluralize,
|
22
|
-
Metasploit::Model::Module::Type::NOP => Metasploit::Model::Module::Type::NOP.pluralize,
|
23
|
-
Metasploit::Model::Module::Type::PAYLOAD => Metasploit::Model::Module::Type::PAYLOAD.pluralize,
|
24
|
-
Metasploit::Model::Module::Type::POST => Metasploit::Model::Module::Type::POST
|
25
|
-
}
|
26
|
-
|
27
|
-
# File extension used for metasploit modules.
|
28
|
-
EXTENSION = '.rb'
|
29
|
-
|
30
|
-
# The {#payload_type payload types} that require {#handler_type}.
|
31
|
-
HANDLED_TYPES = [
|
32
|
-
'single',
|
33
|
-
'stager'
|
34
|
-
]
|
35
|
-
|
36
|
-
# Maps directory to {#module_type} for converting a {#real_path} into a {#module_type} and {#reference_name}
|
37
|
-
MODULE_TYPE_BY_DIRECTORY = DIRECTORY_BY_MODULE_TYPE.invert
|
38
|
-
|
39
|
-
# Valid values for {#payload_type} if {#payload?} is `true`.
|
40
|
-
PAYLOAD_TYPES = [
|
41
|
-
'single',
|
42
|
-
'stage',
|
43
|
-
'stager'
|
44
|
-
]
|
45
|
-
|
46
|
-
# Regexp to keep '\' out of reference names
|
47
|
-
REFERENCE_NAME_REGEXP = /\A[\-0-9A-Z_a-z]+(?:\/[\-0-9A-Z_a-z]+)*\Z/
|
48
|
-
|
49
|
-
# Separator used to join names in {#reference_name}. It is always '/', even on Windows, where '\' is a valid
|
50
|
-
# file separator.
|
51
|
-
REFERENCE_NAME_SEPARATOR = '/'
|
52
|
-
|
53
|
-
# Regular expression matching a full SHA-1 hex digest.
|
54
|
-
SHA1_HEX_DIGEST_REGEXP = /\A[0-9a-z]{40}\Z/
|
55
|
-
|
56
|
-
included do
|
57
|
-
include ActiveModel::MassAssignmentSecurity
|
58
|
-
include ActiveModel::Validations
|
59
|
-
include ActiveModel::Validations::Callbacks
|
60
|
-
include Metasploit::Model::Derivation
|
61
|
-
include Metasploit::Model::Derivation::FullName
|
62
|
-
include Metasploit::Model::RealPathname
|
63
|
-
|
64
|
-
#
|
65
|
-
# Derivations
|
66
|
-
#
|
67
|
-
|
68
|
-
#
|
69
|
-
# Module Cache Construction derivation of {#module_type} and {#reference_name} from {#real_path} and
|
70
|
-
# {Metasploit::Model::Module::Path#real_path}.
|
71
|
-
#
|
72
|
-
|
73
|
-
derives :module_type, :validate => false
|
74
|
-
derives :reference_name, :validate => false
|
75
|
-
|
76
|
-
#
|
77
|
-
# Normal derivation from setting {#module_type} and {#reference_name}
|
78
|
-
#
|
79
|
-
|
80
|
-
derives :full_name, :validate => true
|
81
|
-
derives :payload_type, :validate => true
|
82
|
-
derives :real_path, :validate => true
|
83
|
-
|
84
|
-
# Don't validate attributes that require accessing file system to derive value
|
85
|
-
derives :real_path_modified_at, :validate => false
|
86
|
-
derives :real_path_sha1_hex_digest, :validate => false
|
87
|
-
|
88
|
-
#
|
89
|
-
# Mass Assignment Security
|
90
|
-
#
|
91
|
-
|
92
|
-
# full_name is NOT accessible since it's derived and must match {#derived_full_name} so there's no reason for a
|
93
|
-
# user to set it.
|
94
|
-
# handler_type is accessible because it's needed to derive {Metasploit::Model::Module::Class#reference_name}.
|
95
|
-
attr_accessible :handler_type
|
96
|
-
# module_type is accessible because it's needed to derive {#full_name} and {#real_path}.
|
97
|
-
attr_accessible :module_type
|
98
|
-
# payload_type is NOT accessible since it's derived and must match {#derived_payload_type}.
|
99
|
-
# reference_name is accessible because it's needed to derive {#full_name} and {#real_path}.
|
100
|
-
attr_accessible :reference_name
|
101
|
-
# real_path is accessible since {#module_type} and {#reference_name} can be derived from real_path.
|
102
|
-
attr_accessible :real_path
|
103
|
-
# real_path_modified_at is NOT accessible since it's derived
|
104
|
-
# real_path_sha1_hex_digest is NOT accessible since it's derived
|
105
|
-
|
106
|
-
#
|
107
|
-
# Validations
|
108
|
-
#
|
109
|
-
|
110
|
-
validates :handler_type,
|
111
|
-
:unless => :loading_context?,
|
112
|
-
:nil => {
|
113
|
-
:unless => :handled?
|
114
|
-
},
|
115
|
-
:presence => {
|
116
|
-
:if => :handled?
|
117
|
-
}
|
118
|
-
validates :module_type,
|
119
|
-
:inclusion => {
|
120
|
-
:in => Metasploit::Model::Module::Type::ALL
|
121
|
-
}
|
122
|
-
validates :parent_path,
|
123
|
-
:presence => true
|
124
|
-
validates :payload_type,
|
125
|
-
:inclusion => {
|
126
|
-
:if => :payload?,
|
127
|
-
:in => PAYLOAD_TYPES
|
128
|
-
},
|
129
|
-
:nil => {
|
130
|
-
:unless => :payload?
|
131
|
-
}
|
132
|
-
validates :real_path_modified_at,
|
133
|
-
:presence => true
|
134
|
-
validates :real_path_sha1_hex_digest,
|
135
|
-
:format => {
|
136
|
-
:with => SHA1_HEX_DIGEST_REGEXP
|
137
|
-
}
|
138
|
-
validates :reference_name,
|
139
|
-
:format => {
|
140
|
-
:with => REFERENCE_NAME_REGEXP
|
141
|
-
}
|
142
|
-
end
|
143
|
-
|
144
|
-
# Defines class methods added to classes that include {Metasploit::Model::Module::Ancestor}.
|
145
|
-
module ClassMethods
|
146
|
-
# Returns whether {#handler_type} is required or must be `nil` for the given payload_type.
|
147
|
-
#
|
148
|
-
# @param options [Hash{Symbol => String,nil}]
|
149
|
-
# @option options [String, nil] module_type (nil) `nil` or an element of
|
150
|
-
# `Metasploit::Model::Module::Ancestor::MODULE_TYPES`.
|
151
|
-
# @option options [String, nil] payload_type (nil) `nil` or an element of {PAYLOAD_TYPES}.
|
152
|
-
# @return [true] if {#handler_type} must be present.
|
153
|
-
# @return [false] if {#handler_type} must be `nil`.
|
154
|
-
def handled?(options={})
|
155
|
-
options.assert_valid_keys(:module_type, :payload_type)
|
156
|
-
|
157
|
-
handled = false
|
158
|
-
module_type = options[:module_type]
|
159
|
-
payload_type = options[:payload_type]
|
160
|
-
|
161
|
-
if module_type == 'payload' and HANDLED_TYPES.include? payload_type
|
162
|
-
handled = true
|
163
|
-
end
|
164
|
-
|
165
|
-
handled
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
#
|
170
|
-
# Associations
|
171
|
-
#
|
172
|
-
|
173
|
-
# @!attribute [rw] parent_path
|
174
|
-
# Path under which this ancestor exists on-disk.
|
175
|
-
#
|
176
|
-
# @return [Metasploit::Model::Module::Path]
|
177
|
-
|
178
|
-
#
|
179
|
-
# Attributes
|
180
|
-
#
|
181
|
-
|
182
|
-
# @!attribute [rw] full_name
|
183
|
-
# The full name of the module. The full name is `"#{module_type}/#{reference_name}"`.
|
184
|
-
#
|
185
|
-
# @return [String]
|
186
|
-
|
187
|
-
# @!attribute [rw] handler_type
|
188
|
-
# The handler type (in the case of singles) or (in the case of stagers) the handler type alias. Handler type is
|
189
|
-
# appended to the end of the single's or stage's {#reference_name} to get the
|
190
|
-
# {Metasploit::Model::Module::Class#reference_name}.
|
191
|
-
#
|
192
|
-
# @return [String] if {Metasploit::Model::Module::Ancestor#handled?} is `true`.
|
193
|
-
# @return [nil] if {Metasploit::Model::Module::Ancestor#handled?} is `false`.
|
194
|
-
|
195
|
-
# @!attribute [rw] module_type
|
196
|
-
# The type of the module. This would be called #type, but #type is reserved for ActiveRecord's single table
|
197
|
-
# inheritance.
|
198
|
-
#
|
199
|
-
# @return [String] key in {Metasploit::Model::Module::Ancestor::DIRECTORY_BY_MODULE_TYPE}.
|
200
|
-
|
201
|
-
# @!attribute [rw] payload_type
|
202
|
-
# For payload modules, the type of payload, either 'single', 'stage', or 'stager'.
|
203
|
-
#
|
204
|
-
# @return ['single', 'stage', 'stager'] if `Metasploit::Model::Module::Ancestor#payload?` is `true`.
|
205
|
-
# @return [nil] if `Metasploit::Model::Module::Ancestor#payload?` is `false`
|
206
|
-
# @see Metasploit::Model::Module::Ancestor::PAYLOAD_TYPES
|
207
|
-
|
208
|
-
# @!attribute [rw] real_path
|
209
|
-
# The real (absolute) path to module file on-disk.
|
210
|
-
#
|
211
|
-
# @return [String]
|
212
|
-
|
213
|
-
# @!attribute [rw] real_path_modified_at
|
214
|
-
# The modification time of the module {#real_path file on-disk}.
|
215
|
-
#
|
216
|
-
# @return [DateTime]
|
217
|
-
|
218
|
-
# @!attribute [rw] real_path_sha1_hex_digest
|
219
|
-
# The SHA1 hexadecimal digest of contents of the file at {#real_path}. Stored as a string because postgres does not
|
220
|
-
# have support for a 160 bit numerical type and the hexdigest format is more recognizable when using SQL directly.
|
221
|
-
#
|
222
|
-
# @see Digest::SHA1#hexdigest
|
223
|
-
# @return [String]
|
224
|
-
|
225
|
-
# @!attribute [rw] reference_name
|
226
|
-
# The reference name of the module. The name of the module under its {#module_type type}.
|
227
|
-
#
|
228
|
-
# @return [String]
|
229
|
-
|
230
|
-
#
|
231
|
-
# Instance Methods
|
232
|
-
#
|
233
|
-
|
234
|
-
# The contents of {#real_path}.
|
235
|
-
#
|
236
|
-
# @return [String] contents of file at {#real_path}.
|
237
|
-
# @return [nil] if {#real_path} is `nil`.
|
238
|
-
# @return [nil] if {#real_path} does not exist on-disk.
|
239
|
-
def contents
|
240
|
-
contents = nil
|
241
|
-
|
242
|
-
if real_path
|
243
|
-
# rescue around both File calls since file could be deleted before size or after size and before read
|
244
|
-
begin
|
245
|
-
size = File.size(real_path)
|
246
|
-
# Specify full size of file for faster read on Windows (less chance of context switching mid-read).
|
247
|
-
# Open in binary mode in Windows to handle non-text content embedded in file.
|
248
|
-
contents = File.read(real_path, size, 0, mode: 'rb')
|
249
|
-
rescue Errno::ENOENT
|
250
|
-
contents = nil
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
contents
|
255
|
-
end
|
256
|
-
|
257
|
-
# Derives {#module_type} from {#real_path} and {Metasploit::Model::Module::Path#real_path}.
|
258
|
-
#
|
259
|
-
# @return [String]
|
260
|
-
# @return [nil] if {#real_path} is `nil`
|
261
|
-
# @return [nil] if {#relative_file_names} does not start with a module type directory.
|
262
|
-
def derived_module_type
|
263
|
-
module_type_directory = relative_file_names.first
|
264
|
-
derived = MODULE_TYPE_BY_DIRECTORY[module_type_directory]
|
265
|
-
|
266
|
-
derived
|
267
|
-
end
|
268
|
-
|
269
|
-
# Derives {#payload_type} from {#reference_name}.
|
270
|
-
#
|
271
|
-
# @return [String]
|
272
|
-
# @return [nil] if {#payload_type_directory} is `nil`
|
273
|
-
def derived_payload_type
|
274
|
-
derived = nil
|
275
|
-
directory = payload_type_directory
|
276
|
-
|
277
|
-
if directory
|
278
|
-
derived = directory.singularize
|
279
|
-
end
|
280
|
-
|
281
|
-
derived
|
282
|
-
end
|
283
|
-
|
284
|
-
# Derives {#real_path} by combining {Metasploit::Model::Module::Path#real_path parent_path.real_path},
|
285
|
-
# {#module_type_directory}, and {#reference_path} in the same way the module loader does in
|
286
|
-
# metasploit-framework.
|
287
|
-
#
|
288
|
-
# @return [String] the real path to the file holding the ruby Module or ruby Class represented by this ancestor.
|
289
|
-
# @return [nil] if {#parent_path} is `nil`.
|
290
|
-
# @return [nil] if {Metasploit::Model::Module::Path#real_path parent_path.real_path} is `nil`.
|
291
|
-
# @return [nil] if {#module_type_directory} is `nil`.
|
292
|
-
# @return [nil] if {#reference_name} is `nil`.
|
293
|
-
def derived_real_path
|
294
|
-
derived_real_path = nil
|
295
|
-
|
296
|
-
if parent_path and parent_path.real_path and module_type_directory and reference_path
|
297
|
-
derived_real_path = File.join(
|
298
|
-
parent_path.real_path,
|
299
|
-
module_type_directory,
|
300
|
-
reference_path
|
301
|
-
)
|
302
|
-
end
|
303
|
-
|
304
|
-
derived_real_path
|
305
|
-
end
|
306
|
-
|
307
|
-
# Derives {#real_path_modified_at} by getting the modification time of the file on-disk.
|
308
|
-
#
|
309
|
-
# @return [Time] modification time of {#real_path} if {#real_path} exists on disk and modification time can be
|
310
|
-
# queried by user.
|
311
|
-
# @return [nil] if {#real_path} does not exist or user cannot query the file's modification time.
|
312
|
-
def derived_real_path_modified_at
|
313
|
-
real_path_string = real_path.to_s
|
314
|
-
|
315
|
-
begin
|
316
|
-
mtime = File.mtime(real_path_string)
|
317
|
-
rescue Errno::ENOENT
|
318
|
-
nil
|
319
|
-
else
|
320
|
-
mtime.utc
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
# Derives {#real_path_sha1_hex_digest} by running the contents of {#real_path} through Digest::SHA1.hexdigest.
|
325
|
-
#
|
326
|
-
# @return [String] 40 character SHA1 hex digest if {#real_path} can be read.
|
327
|
-
# @return [nil] if {#real_path} cannot be read.
|
328
|
-
def derived_real_path_sha1_hex_digest
|
329
|
-
begin
|
330
|
-
sha1 = Digest::SHA1.file(real_path.to_s)
|
331
|
-
rescue Errno::ENOENT
|
332
|
-
hex_digest = nil
|
333
|
-
else
|
334
|
-
hex_digest = sha1.hexdigest
|
335
|
-
end
|
336
|
-
|
337
|
-
hex_digest
|
338
|
-
end
|
339
|
-
|
340
|
-
# Derives {#reference_name} from {#real_path} and {Metasploit::Model::Module::Path#real_path}.
|
341
|
-
#
|
342
|
-
# @return [String]
|
343
|
-
# @return [nil] if {#real_path} is `nil`.
|
344
|
-
def derived_reference_name
|
345
|
-
derived = nil
|
346
|
-
reference_name_file_names = relative_file_names.drop(1)
|
347
|
-
reference_name_base_name = reference_name_file_names[-1]
|
348
|
-
|
349
|
-
if reference_name_base_name
|
350
|
-
if File.extname(reference_name_base_name) == EXTENSION
|
351
|
-
reference_name_file_names[-1] = File.basename(reference_name_base_name, EXTENSION)
|
352
|
-
derived = reference_name_file_names.join(REFERENCE_NAME_SEPARATOR)
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
derived
|
357
|
-
end
|
358
|
-
|
359
|
-
# Returns whether {#handler_type} is required or must be `nil`.
|
360
|
-
#
|
361
|
-
# @return (see handled?)
|
362
|
-
# @see handled?
|
363
|
-
def handled?
|
364
|
-
self.class.handled?(
|
365
|
-
:module_type => module_type,
|
366
|
-
:payload_type => payload_type
|
367
|
-
)
|
368
|
-
end
|
369
|
-
|
370
|
-
# The directory for {#module_type} under {Metasploit::Model::Module::Path parent_path.real_path}.
|
371
|
-
#
|
372
|
-
# @return [String]
|
373
|
-
# @see Metasploit::Model::Module::Ancestor::DIRECTORY_BY_MODULE_TYPE
|
374
|
-
def module_type_directory
|
375
|
-
Metasploit::Model::Module::Ancestor::DIRECTORY_BY_MODULE_TYPE[module_type]
|
376
|
-
end
|
377
|
-
|
378
|
-
# Return whether this forms part of a payload (either a single, stage, or stager).
|
379
|
-
#
|
380
|
-
# @return [true] if {#module_type} == 'payload'
|
381
|
-
# @return [false] if {#module_type} != 'payload'
|
382
|
-
def payload?
|
383
|
-
if module_type == Metasploit::Model::Module::Type::PAYLOAD
|
384
|
-
true
|
385
|
-
else
|
386
|
-
false
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
# The name used to forming the {Metasploit::Model::Module::Class#reference_name} for payloads.
|
391
|
-
#
|
392
|
-
# @return [String] The {#reference_name} without the {#payload_type_directory} if {#payload_type} is `'single'`
|
393
|
-
# or `'stage'`
|
394
|
-
# @return [String] The {#handler_type} if {#payload_type} is `'stager'`
|
395
|
-
# @return [nil] if {#module_type} is not `'payload'`
|
396
|
-
def payload_name
|
397
|
-
payload_name = nil
|
398
|
-
|
399
|
-
if module_type == Metasploit::Model::Module::Type::PAYLOAD
|
400
|
-
case payload_type
|
401
|
-
when 'single', 'stage'
|
402
|
-
if reference_name && payload_type_directory
|
403
|
-
escaped_payload_type_directory = Regexp.escape(payload_type_directory)
|
404
|
-
payload_type_directory_regexp = /^#{escaped_payload_type_directory}\//
|
405
|
-
payload_name = reference_name.gsub(payload_type_directory_regexp, '')
|
406
|
-
end
|
407
|
-
when 'stager'
|
408
|
-
payload_name = handler_type
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
payload_name
|
413
|
-
end
|
414
|
-
|
415
|
-
# The directory for {#payload_type} under {#module_type_directory} in {#real_path}.
|
416
|
-
#
|
417
|
-
# @return [String] first directory in reference_name
|
418
|
-
# @return [nil] if {#payload?} is `false`.
|
419
|
-
# @return [nil] if {#reference_name} is `nil`.
|
420
|
-
def payload_type_directory
|
421
|
-
directory = nil
|
422
|
-
|
423
|
-
if payload? and reference_name
|
424
|
-
head, _tail = reference_name.split(REFERENCE_NAME_SEPARATOR, 2)
|
425
|
-
directory = head
|
426
|
-
end
|
427
|
-
|
428
|
-
directory
|
429
|
-
end
|
430
|
-
|
431
|
-
# File names on {#relative_pathname}.
|
432
|
-
#
|
433
|
-
# @return [Enumerator<String>]
|
434
|
-
def relative_file_names
|
435
|
-
relative_pathname = self.relative_pathname
|
436
|
-
|
437
|
-
if relative_pathname
|
438
|
-
relative_pathname.each_filename
|
439
|
-
else
|
440
|
-
# empty enumerator
|
441
|
-
Enumerator.new { }
|
442
|
-
end
|
443
|
-
end
|
444
|
-
|
445
|
-
# {#real_path} relative to {Metasploit::Model::Module::Path#real_path}
|
446
|
-
#
|
447
|
-
# @return [Pathname]
|
448
|
-
def relative_pathname
|
449
|
-
relative_pathname = nil
|
450
|
-
real_pathname = self.real_pathname
|
451
|
-
|
452
|
-
if real_pathname
|
453
|
-
parent_path = self.parent_path
|
454
|
-
|
455
|
-
if parent_path
|
456
|
-
parent_path_real_pathname = parent_path.real_pathname
|
457
|
-
|
458
|
-
if parent_path_real_pathname
|
459
|
-
relative_pathname = real_pathname.relative_path_from parent_path_real_pathname
|
460
|
-
end
|
461
|
-
end
|
462
|
-
end
|
463
|
-
|
464
|
-
relative_pathname
|
465
|
-
end
|
466
|
-
|
467
|
-
# The path relative to the {#module_type_directory} under the {Metasploit::Model::Module::Path
|
468
|
-
# parent_path.real_path}, including the file {EXTENSION extension}.
|
469
|
-
#
|
470
|
-
# @return [String] {#reference_name} + {EXTENSION}
|
471
|
-
# @return [nil] if {#reference_name} is `nil`.
|
472
|
-
def reference_path
|
473
|
-
path = nil
|
474
|
-
|
475
|
-
if reference_name
|
476
|
-
path = "#{reference_name}#{EXTENSION}"
|
477
|
-
end
|
478
|
-
|
479
|
-
path
|
480
|
-
end
|
481
|
-
|
482
|
-
private
|
483
|
-
|
484
|
-
# Whether this ancestor is being validated for loading.
|
485
|
-
#
|
486
|
-
# @return [true] if `#validation_context` is `:loading`
|
487
|
-
# @return [false] otherwise
|
488
|
-
def loading_context?
|
489
|
-
validation_context == :loading
|
490
|
-
end
|
491
|
-
end
|