metasploit-model 0.27.3-java → 0.27.4-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/app/models/metasploit/model/association/reflection.rb +0 -3
- data/app/models/metasploit/model/module/ancestor/spec/template.rb +0 -3
- data/app/models/metasploit/model/module/class/spec/template.rb +0 -4
- data/app/models/metasploit/model/module/instance/spec/template.rb +0 -4
- data/app/models/metasploit/model/search/group/base.rb +0 -3
- data/app/models/metasploit/model/search/group/intersection.rb +0 -3
- data/app/models/metasploit/model/search/group/union.rb +0 -3
- data/app/models/metasploit/model/search/operation/association.rb +0 -2
- data/app/models/metasploit/model/search/operation/base.rb +0 -3
- data/app/models/metasploit/model/search/operation/boolean.rb +0 -2
- data/app/models/metasploit/model/search/operation/date.rb +0 -2
- data/app/models/metasploit/model/search/operation/group/base.rb +0 -2
- data/app/models/metasploit/model/search/operation/group/intersection.rb +0 -2
- data/app/models/metasploit/model/search/operation/group/union.rb +0 -2
- data/app/models/metasploit/model/search/operation/integer.rb +1 -5
- data/app/models/metasploit/model/search/operation/null.rb +0 -2
- data/app/models/metasploit/model/search/operation/set.rb +5 -2
- data/app/models/metasploit/model/search/operation/set/integer.rb +1 -3
- data/app/models/metasploit/model/search/operation/set/string.rb +1 -3
- data/app/models/metasploit/model/search/operation/string.rb +1 -5
- data/app/models/metasploit/model/search/operator/association.rb +0 -2
- data/app/models/metasploit/model/search/operator/attribute.rb +0 -2
- data/app/models/metasploit/model/search/operator/base.rb +0 -4
- data/app/models/metasploit/model/search/operator/delegation.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/app.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/author.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/authority.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/platform.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/ref.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/text.rb +0 -2
- data/app/models/metasploit/model/search/operator/group/base.rb +0 -2
- data/app/models/metasploit/model/search/operator/group/intersection.rb +0 -2
- data/app/models/metasploit/model/search/operator/group/union.rb +0 -2
- data/app/models/metasploit/model/search/operator/null.rb +0 -2
- data/app/models/metasploit/model/search/operator/single.rb +0 -2
- data/app/models/metasploit/model/search/query.rb +0 -3
- data/app/models/metasploit/model/spec/template.rb +0 -3
- data/app/models/metasploit/model/visitation/visitor.rb +0 -3
- data/lib/metasploit/model.rb +14 -8
- data/lib/metasploit/model/architecture.rb +320 -326
- data/lib/metasploit/model/association.rb +43 -46
- data/lib/metasploit/model/association/error.rb +29 -33
- data/lib/metasploit/model/association/tree.rb +119 -125
- data/lib/metasploit/model/author.rb +45 -51
- data/lib/metasploit/model/authority.rb +139 -146
- data/lib/metasploit/model/authority/bid.rb +0 -2
- data/lib/metasploit/model/authority/cve.rb +0 -2
- data/lib/metasploit/model/authority/msb.rb +0 -2
- data/lib/metasploit/model/authority/osvdb.rb +0 -2
- data/lib/metasploit/model/authority/pmasa.rb +0 -2
- data/lib/metasploit/model/authority/secunia.rb +0 -2
- data/lib/metasploit/model/authority/us_cert_vu.rb +0 -2
- data/lib/metasploit/model/authority/waraxe.rb +0 -2
- data/lib/metasploit/model/authority/zdi.rb +0 -2
- data/lib/metasploit/model/base.rb +0 -2
- data/lib/metasploit/model/derivation.rb +95 -99
- data/lib/metasploit/model/derivation/full_name.rb +16 -22
- data/lib/metasploit/model/email_address.rb +122 -128
- data/lib/metasploit/model/engine.rb +26 -21
- data/lib/metasploit/model/error.rb +3 -7
- data/lib/metasploit/model/file.rb +0 -2
- data/lib/metasploit/model/invalid.rb +11 -17
- data/lib/metasploit/model/login.rb +0 -3
- data/lib/metasploit/model/login/status.rb +0 -2
- data/lib/metasploit/model/module.rb +19 -23
- data/lib/metasploit/model/module/action.rb +50 -58
- data/lib/metasploit/model/module/ancestor.rb +456 -465
- data/lib/metasploit/model/module/ancestor/spec.rb +3 -2
- data/lib/metasploit/model/module/architecture.rb +27 -35
- data/lib/metasploit/model/module/author.rb +38 -47
- data/lib/metasploit/model/module/class.rb +358 -366
- data/lib/metasploit/model/module/class/spec.rb +3 -2
- data/lib/metasploit/model/module/handler.rb +28 -34
- data/lib/metasploit/model/module/instance.rb +586 -596
- data/lib/metasploit/model/module/instance/spec.rb +3 -2
- data/lib/metasploit/model/module/path.rb +157 -166
- data/lib/metasploit/model/module/platform.rb +25 -33
- data/lib/metasploit/model/module/rank.rb +71 -79
- data/lib/metasploit/model/module/reference.rb +25 -33
- data/lib/metasploit/model/module/stance.rb +15 -21
- data/lib/metasploit/model/module/target.rb +76 -84
- data/lib/metasploit/model/module/target/architecture.rb +27 -37
- data/lib/metasploit/model/module/target/platform.rb +27 -37
- data/lib/metasploit/model/module/type.rb +35 -41
- data/lib/metasploit/model/nilify_blanks.rb +39 -43
- data/lib/metasploit/model/platform.rb +231 -237
- data/lib/metasploit/model/real_pathname.rb +12 -16
- data/lib/metasploit/model/realm.rb +0 -2
- data/lib/metasploit/model/realm/key.rb +0 -2
- data/lib/metasploit/model/reference.rb +102 -108
- data/lib/metasploit/model/search.rb +94 -97
- data/lib/metasploit/model/search/association.rb +163 -169
- data/lib/metasploit/model/search/attribute.rb +131 -139
- data/lib/metasploit/model/search/group.rb +5 -2
- data/lib/metasploit/model/search/operation.rb +32 -29
- data/lib/metasploit/model/search/operation/group.rb +5 -2
- data/lib/metasploit/model/search/operation/value.rb +7 -0
- data/lib/metasploit/model/search/operation/{integer/value.rb → value/integer.rb} +1 -1
- data/lib/metasploit/model/search/operation/{string/value.rb → value/string.rb} +1 -1
- data/lib/metasploit/model/search/operator.rb +65 -65
- data/lib/metasploit/model/search/operator/deprecated.rb +8 -2
- data/lib/metasploit/model/search/operator/group.rb +5 -2
- data/lib/metasploit/model/search/operator/help.rb +71 -79
- data/lib/metasploit/model/search/with.rb +72 -78
- data/lib/metasploit/model/spec.rb +133 -136
- data/lib/metasploit/model/spec/error.rb +3 -9
- data/lib/metasploit/model/spec/i18n_exception_handler.rb +0 -2
- data/lib/metasploit/model/spec/pathname_collision.rb +19 -27
- data/lib/metasploit/model/spec/template/write.rb +0 -2
- data/lib/metasploit/model/spec/temporary_pathname.rb +47 -56
- data/lib/metasploit/model/translation.rb +0 -2
- data/lib/metasploit/model/version.rb +1 -1
- data/lib/metasploit/model/visitation.rb +7 -10
- data/lib/metasploit/model/visitation/visit.rb +79 -85
- data/metasploit-model.gemspec +1 -1
- data/spec/app/models/metasploit/model/search/operation/integer_spec.rb +1 -1
- data/spec/app/models/metasploit/model/search/operation/set/integer_spec.rb +1 -1
- data/spec/app/models/metasploit/model/search/operation/set/string_spec.rb +1 -1
- data/spec/app/models/metasploit/model/search/operation/string_spec.rb +1 -1
- data/spec/dummy/config/application.rb +1 -0
- data/spec/lib/metasploit/model/search/operation/{integer/value_spec.rb → value/integer_spec.rb} +2 -2
- data/spec/lib/metasploit/model/search/operation/{string/value_spec.rb → value/string_spec.rb} +2 -2
- data/spec/support/shared/examples/metasploit/model/search/operation/{integer/value.rb → value/integer.rb} +2 -2
- data/spec/support/shared/examples/metasploit/model/search/operation/{string/value.rb → value/string.rb} +2 -2
- metadata +16 -13
@@ -1,42 +1,34 @@
|
|
1
|
-
|
1
|
+
# Model that joins {Metasploit::Model::Architecture} and {Metasploit::Model::Module::Instance}.
|
2
|
+
module Metasploit::Model::Module::Architecture
|
3
|
+
extend ActiveModel::Naming
|
4
|
+
extend ActiveSupport::Concern
|
2
5
|
|
3
|
-
|
4
|
-
module Model
|
5
|
-
module Module
|
6
|
-
# Model that joins {Metasploit::Model::Architecture} and {Metasploit::Model::Module::Instance}.
|
7
|
-
module Architecture
|
8
|
-
extend ActiveModel::Naming
|
9
|
-
extend ActiveSupport::Concern
|
6
|
+
include Metasploit::Model::Translation
|
10
7
|
|
11
|
-
|
8
|
+
included do
|
9
|
+
include ActiveModel::Validations
|
12
10
|
|
13
|
-
|
14
|
-
|
11
|
+
#
|
12
|
+
# Validations
|
13
|
+
#
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
:presence => true
|
22
|
-
validates :module_instance,
|
23
|
-
:presence => true
|
24
|
-
end
|
15
|
+
validates :architecture,
|
16
|
+
:presence => true
|
17
|
+
validates :module_instance,
|
18
|
+
:presence => true
|
19
|
+
end
|
25
20
|
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
#
|
22
|
+
# Attributes
|
23
|
+
#
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
# @!attribute [rw] architecture
|
26
|
+
# The architecture supported by the {#module_instance}.
|
27
|
+
#
|
28
|
+
# @return [Metasploit::Model::Architecture]
|
34
29
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
30
|
+
# @!attribute [rw] module_instance
|
31
|
+
# The module instance that supports {#architecture}.
|
32
|
+
#
|
33
|
+
# @return [Metasploit::Model::Module::Instance]
|
34
|
+
end
|
@@ -1,49 +1,40 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
validates :author,
|
21
|
-
:presence => true
|
22
|
-
validates :module_instance,
|
23
|
-
:presence => true
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
# Associations
|
28
|
-
#
|
29
|
-
|
30
|
-
# @!attribute [rw] author
|
31
|
-
# Author who wrote the {#module_instance module}.
|
32
|
-
#
|
33
|
-
# @return [Metasploit::Model::Author]
|
34
|
-
|
35
|
-
# @!attribute [rw] email_address
|
36
|
-
# Email address {#author} used when writing {#module_instance module}.
|
37
|
-
#
|
38
|
-
# @return [Metasploit::Model::EmailAddress] if {#author} gave an email address.
|
39
|
-
# @return [nil] if {#author} only gave a name.
|
40
|
-
|
41
|
-
# @!attribute [rw] module_instance
|
42
|
-
# Module written by {#author}.
|
43
|
-
#
|
44
|
-
# @return [Metasploit::Model::Module::Instance]
|
45
|
-
end
|
46
|
-
end
|
1
|
+
# Code shared between `Mdm::Module::Author` and `Metasploit::Framework::Module::Author`.
|
2
|
+
module Metasploit::Model::Module::Author
|
3
|
+
extend ActiveModel::Naming
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
include Metasploit::Model::Translation
|
7
|
+
|
8
|
+
included do
|
9
|
+
include ActiveModel::Validations
|
10
|
+
|
11
|
+
#
|
12
|
+
# Validations
|
13
|
+
#
|
14
|
+
|
15
|
+
validates :author,
|
16
|
+
:presence => true
|
17
|
+
validates :module_instance,
|
18
|
+
:presence => true
|
47
19
|
end
|
48
|
-
end
|
49
20
|
|
21
|
+
#
|
22
|
+
# Associations
|
23
|
+
#
|
24
|
+
|
25
|
+
# @!attribute [rw] author
|
26
|
+
# Author who wrote the {#module_instance module}.
|
27
|
+
#
|
28
|
+
# @return [Metasploit::Model::Author]
|
29
|
+
|
30
|
+
# @!attribute [rw] email_address
|
31
|
+
# Email address {#author} used when writing {#module_instance module}.
|
32
|
+
#
|
33
|
+
# @return [Metasploit::Model::EmailAddress] if {#author} gave an email address.
|
34
|
+
# @return [nil] if {#author} only gave a name.
|
35
|
+
|
36
|
+
# @!attribute [rw] module_instance
|
37
|
+
# Module written by {#author}.
|
38
|
+
#
|
39
|
+
# @return [Metasploit::Model::Module::Instance]
|
40
|
+
end
|
@@ -1,411 +1,403 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
validates :rank,
|
80
|
-
:presence => true
|
81
|
-
validates :reference_name,
|
82
|
-
:presence => true
|
83
|
-
end
|
1
|
+
# Code shared between `Mdm::Module::Class` and `Metasploit::Framework::Module::Class`.
|
2
|
+
module Metasploit::Model::Module::Class
|
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
|
+
# Valid values for {#payload_type} when {#payload?} is `true`.
|
16
|
+
PAYLOAD_TYPES = [
|
17
|
+
'single',
|
18
|
+
'staged'
|
19
|
+
]
|
20
|
+
|
21
|
+
# The {Metasploit::Model::Module::Ancestor#payload_type} when {#payload_type} is 'staged'.
|
22
|
+
STAGED_ANCESTOR_PAYLOAD_TYPES = [
|
23
|
+
'stage',
|
24
|
+
'stager'
|
25
|
+
]
|
26
|
+
|
27
|
+
included do
|
28
|
+
include ActiveModel::Validations
|
29
|
+
include Metasploit::Model::Derivation
|
30
|
+
include Metasploit::Model::Derivation::FullName
|
31
|
+
include Metasploit::Model::Search
|
32
|
+
|
33
|
+
#
|
34
|
+
# Derivations
|
35
|
+
#
|
36
|
+
|
37
|
+
derives :module_type, :validate => true
|
38
|
+
derives :payload_type, :validate => true
|
39
|
+
# reference_name depends on module_type and conditionally depends on payload_type if module_type is 'payload'
|
40
|
+
derives :reference_name, :validate => true
|
41
|
+
|
42
|
+
# full_name depends on module_type and reference_name
|
43
|
+
derives :full_name, :validate => true
|
44
|
+
|
45
|
+
#
|
46
|
+
# Search Attributes
|
47
|
+
#
|
48
|
+
|
49
|
+
search_attribute :full_name, :type => :string
|
50
|
+
search_attribute :module_type, :type => :string
|
51
|
+
search_attribute :payload_type, :type => :string
|
52
|
+
search_attribute :reference_name, :type => :string
|
53
|
+
|
54
|
+
#
|
55
|
+
# Validations
|
56
|
+
#
|
57
|
+
|
58
|
+
validate :ancestors_size
|
59
|
+
validate :ancestor_payload_types
|
60
|
+
validate :ancestor_module_types
|
61
|
+
|
62
|
+
validates :module_type,
|
63
|
+
:inclusion => {
|
64
|
+
:in => Metasploit::Model::Module::Type::ALL
|
65
|
+
}
|
66
|
+
validates :payload_type,
|
67
|
+
:inclusion => {
|
68
|
+
:if => :payload?,
|
69
|
+
:in => PAYLOAD_TYPES
|
70
|
+
},
|
71
|
+
:nil => {
|
72
|
+
:unless => :payload?
|
73
|
+
}
|
74
|
+
validates :rank,
|
75
|
+
:presence => true
|
76
|
+
validates :reference_name,
|
77
|
+
:presence => true
|
78
|
+
end
|
84
79
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
80
|
+
#
|
81
|
+
# Associations
|
82
|
+
#
|
83
|
+
|
84
|
+
# @!attribute [rw] rank
|
85
|
+
# The reliability of the module and likelyhood that the module won't knock over the service or host being
|
86
|
+
# exploited. Bigger values is better.
|
87
|
+
#
|
88
|
+
# @return [Metasploit::Model::Module::Rank]
|
89
|
+
|
90
|
+
# @!attribute [r] ancestors
|
91
|
+
# The Class or Modules that were loaded to make this module Class.
|
92
|
+
#
|
93
|
+
# @return [Array<Metasploit::Model::Module::Ancestor>]
|
94
|
+
|
95
|
+
#
|
96
|
+
# Attributes
|
97
|
+
#
|
98
|
+
|
99
|
+
# @!attribute [rw] full_name
|
100
|
+
# The full name (type + reference) for the Class<Msf::Module>. This is merely a denormalized cache of
|
101
|
+
# `"#{{#module_type}}/#{{#reference_name}}"` as full_name is used in numerous queries and reports.
|
102
|
+
#
|
103
|
+
# @return [String]
|
104
|
+
|
105
|
+
# @!attribute [rw] module_type
|
106
|
+
# A denormalized cache of the {Metasploit::Model::Module::Class#module_type ancestors' module_types}, which
|
107
|
+
# must all be the same. This cache exists so that queries for modules of a given type don't need include the
|
108
|
+
# {#ancestors}.
|
109
|
+
#
|
110
|
+
# @return [String]
|
111
|
+
|
112
|
+
# @!attribute [rw] payload_type
|
113
|
+
# For payload modules, the {PAYLOAD_TYPES type} of payload, either 'single' or 'staged'.
|
114
|
+
#
|
115
|
+
# @return [String] if {#payload?} is `true`.
|
116
|
+
# @return [nil] if {#payload?} is `false`
|
117
|
+
|
118
|
+
# @!attribute [rw] reference_name
|
119
|
+
# The reference name for the Class<Msf::Module>. For non-payloads, this will just be
|
120
|
+
# {Metasploit::Model::Module::Ancestor#reference_name} for the only element in {#ancestors}. For payloads
|
121
|
+
# composed of a stage and stager, the reference name will be derived from the
|
122
|
+
# {Metasploit::Model::Module::Ancestor#reference_name} of each element {#ancestors} or an alias defined in
|
123
|
+
# those Modules.
|
124
|
+
#
|
125
|
+
# @return [String]
|
126
|
+
|
127
|
+
#
|
128
|
+
# Instance Methods
|
129
|
+
#
|
130
|
+
|
131
|
+
# Derives {#module_type} from the consensus of {#ancestors ancestors'}
|
132
|
+
# {Metasploit::Model::Module::Ancestor#module_type module_types}.
|
133
|
+
#
|
134
|
+
# @return [String] if all {#ancestors} have the same
|
135
|
+
# {Metasploit::Model::Module::Ancestor#module_type module_type}.
|
136
|
+
# @return [nil] if there are no {#ancestors}.
|
137
|
+
# @return [nil] if {#ancestors} do not have the same
|
138
|
+
# {Metasploit::Model::Module::Ancestor#module_type module_type}.
|
139
|
+
def derived_module_type
|
140
|
+
module_type_consensus = nil
|
141
|
+
module_type_set = Set.new
|
142
|
+
|
143
|
+
ancestors.each do |ancestor|
|
144
|
+
module_type_set.add ancestor.module_type
|
145
|
+
end
|
147
146
|
|
148
|
-
|
149
|
-
|
150
|
-
|
147
|
+
if module_type_set.length == 1
|
148
|
+
module_type_consensus = module_type_set.to_a.first
|
149
|
+
end
|
150
|
+
|
151
|
+
module_type_consensus
|
152
|
+
end
|
151
153
|
|
152
|
-
|
153
|
-
|
154
|
+
# Derives {#payload_type} based on {#ancestors ancestor's}
|
155
|
+
# {Metasploit::Model::Module::Ancestor#payload_type payload_type}.
|
156
|
+
#
|
157
|
+
# @return ['single'] if {#payload?} and single ancestor with
|
158
|
+
# {Metasploit::Model::Module::Ancestor#payload_type payload_tye} 'single'.
|
159
|
+
# @return ['staged'] if {#payload?} and one ancestor with
|
160
|
+
# {Metasploit::Model::Module::Ancestor#payload_type payload_type} 'stager' and another ancestor with
|
161
|
+
# {Metasploit::Model::Module::Ancestor#payload_type payload_type} 'stage'.
|
162
|
+
# @return [nil] otherwise
|
163
|
+
def derived_payload_type
|
164
|
+
derived = nil
|
165
|
+
|
166
|
+
if payload?
|
167
|
+
case ancestors.length
|
168
|
+
when 1
|
169
|
+
if ancestors.first.payload_type == 'single'
|
170
|
+
derived = 'single'
|
154
171
|
end
|
172
|
+
when 2
|
173
|
+
payload_type_set = Set.new
|
155
174
|
|
156
|
-
|
157
|
-
|
175
|
+
ancestors.each do |ancestor|
|
176
|
+
payload_type_set.add ancestor.payload_type
|
177
|
+
end
|
158
178
|
|
159
|
-
|
160
|
-
|
161
|
-
#
|
162
|
-
# @return ['single'] if {#payload?} and single ancestor with
|
163
|
-
# {Metasploit::Model::Module::Ancestor#payload_type payload_tye} 'single'.
|
164
|
-
# @return ['staged'] if {#payload?} and one ancestor with
|
165
|
-
# {Metasploit::Model::Module::Ancestor#payload_type payload_type} 'stager' and another ancestor with
|
166
|
-
# {Metasploit::Model::Module::Ancestor#payload_type payload_type} 'stage'.
|
167
|
-
# @return [nil] otherwise
|
168
|
-
def derived_payload_type
|
169
|
-
derived = nil
|
170
|
-
|
171
|
-
if payload?
|
172
|
-
case ancestors.length
|
173
|
-
when 1
|
174
|
-
if ancestors.first.payload_type == 'single'
|
175
|
-
derived = 'single'
|
176
|
-
end
|
177
|
-
when 2
|
178
|
-
payload_type_set = Set.new
|
179
|
-
|
180
|
-
ancestors.each do |ancestor|
|
181
|
-
payload_type_set.add ancestor.payload_type
|
182
|
-
end
|
183
|
-
|
184
|
-
if payload_type_set.include? 'stager' and payload_type_set.include? 'stage'
|
185
|
-
derived = 'staged'
|
186
|
-
end
|
187
|
-
end
|
179
|
+
if payload_type_set.include? 'stager' and payload_type_set.include? 'stage'
|
180
|
+
derived = 'staged'
|
188
181
|
end
|
182
|
+
end
|
183
|
+
end
|
189
184
|
|
190
|
-
|
191
|
-
|
185
|
+
derived
|
186
|
+
end
|
192
187
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
188
|
+
# Derives {#reference_name} from {#ancestors}.
|
189
|
+
#
|
190
|
+
# @return [String] '<single_ancestor.reference_name>/<single_ancestor.handler_type>' if {#payload_type} is
|
191
|
+
# 'single'.
|
192
|
+
# @return [String] '<stage_ancestor.reference_name>/<stager_ancestor.handler_type>' if {#payload_type} is
|
193
|
+
# 'staged'.
|
194
|
+
# @return [String] '<ancestor.reference_name>' if not {#payload?}.
|
195
|
+
# @return [nil] otherwise
|
196
|
+
def derived_reference_name
|
197
|
+
derived = nil
|
198
|
+
|
199
|
+
if payload?
|
200
|
+
case payload_type
|
201
|
+
when 'single'
|
202
|
+
derived = derived_single_payload_reference_name
|
203
|
+
when 'staged'
|
204
|
+
derived = derived_staged_payload_reference_name
|
205
|
+
end
|
206
|
+
else
|
207
|
+
if ancestors.length == 1
|
208
|
+
derived = ancestors.first.reference_name
|
209
|
+
end
|
210
|
+
end
|
216
211
|
|
217
|
-
|
218
|
-
|
212
|
+
derived
|
213
|
+
end
|
219
214
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
215
|
+
# Returns whether this represents a Class<Msf::Payload>.
|
216
|
+
#
|
217
|
+
# @return [true] if {#module_type} == 'payload'
|
218
|
+
# @return [false] if {#module_type} != 'payload'
|
219
|
+
def payload?
|
220
|
+
if module_type == 'payload'
|
221
|
+
true
|
222
|
+
else
|
223
|
+
false
|
224
|
+
end
|
225
|
+
end
|
231
226
|
|
232
|
-
|
227
|
+
private
|
233
228
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
229
|
+
# Validates that {#ancestors} all have the same {Metasploit::Model::Module::Ancestor#module_type} as
|
230
|
+
# {#module_type}.
|
231
|
+
#
|
232
|
+
# @return [void]
|
233
|
+
def ancestor_module_types
|
234
|
+
ancestor_module_type_set = Set.new
|
240
235
|
|
241
|
-
|
242
|
-
|
243
|
-
|
236
|
+
ancestors.each do |ancestor|
|
237
|
+
if module_type and ancestor.module_type != module_type
|
238
|
+
errors[:ancestors] << "can contain ancestors only with same module_type (#{module_type}); " \
|
244
239
|
"#{ancestor.full_name} cannot be an ancestor due to its module_type " \
|
245
240
|
"(#{ancestor.module_type})"
|
246
|
-
|
241
|
+
end
|
247
242
|
|
248
|
-
|
249
|
-
|
243
|
+
ancestor_module_type_set.add ancestor.module_type
|
244
|
+
end
|
250
245
|
|
251
|
-
|
252
|
-
|
253
|
-
|
246
|
+
if ancestor_module_type_set.length > 1
|
247
|
+
ancestor_module_type_sentence = ancestor_module_type_set.sort.to_sentence
|
248
|
+
errors[:ancestors] << "can only contain ancestors with one module_type, " \
|
254
249
|
"but contains multiple module_types (#{ancestor_module_type_sentence})"
|
255
|
-
|
256
|
-
|
250
|
+
end
|
251
|
+
end
|
257
252
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
253
|
+
# Validates that {#ancestors} have correct {Metasploit::Model::Module::Ancestor#payload_type payload_types} for
|
254
|
+
# the {#module_type} and {#payload_type}.
|
255
|
+
#
|
256
|
+
# @return [void]
|
257
|
+
def ancestor_payload_types
|
258
|
+
if payload?
|
259
|
+
case payload_type
|
260
|
+
when 'single'
|
261
|
+
ancestors.each do |ancestor|
|
262
|
+
unless ancestor.payload_type == 'single'
|
263
|
+
errors[:ancestors] << "cannot have an ancestor (#{ancestor.full_name}) " \
|
269
264
|
"with payload_type (#{ancestor.payload_type}) " \
|
270
265
|
"for class payload_type (#{payload_type})"
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
266
|
+
end
|
267
|
+
end
|
268
|
+
when 'staged'
|
269
|
+
ancestors_by_payload_type = ancestors.group_by(&:payload_type)
|
275
270
|
|
276
|
-
|
277
|
-
|
278
|
-
|
271
|
+
STAGED_ANCESTOR_PAYLOAD_TYPES.each do |ancestor_payload_type|
|
272
|
+
staged_payload_type_count(ancestors_by_payload_type, ancestor_payload_type)
|
273
|
+
end
|
279
274
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
275
|
+
ancestors_by_payload_type.each do |ancestor_payload_type, ancestors|
|
276
|
+
unless STAGED_ANCESTOR_PAYLOAD_TYPES.include? ancestor_payload_type
|
277
|
+
full_names = ancestors.map(&:full_name)
|
278
|
+
full_name_sentence = full_names.to_sentence
|
284
279
|
|
285
|
-
|
280
|
+
errors[:ancestors] << "cannot have ancestors (#{full_name_sentence}) " \
|
286
281
|
"with payload_type (#{ancestor_payload_type}) " \
|
287
282
|
"for class payload_type (#{payload_type}); " \
|
288
283
|
"only one stage and one stager ancestor is allowed"
|
289
|
-
end
|
290
|
-
end
|
291
284
|
end
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
285
|
+
end
|
286
|
+
end
|
287
|
+
else
|
288
|
+
ancestors.each do |ancestor|
|
289
|
+
if ancestor.payload_type
|
290
|
+
errors[:ancestors] << "cannot have an ancestor (#{ancestor.full_name}) " \
|
296
291
|
"with a payload_type (#{ancestor.payload_type}) " \
|
297
292
|
"for class module_type (#{module_type})"
|
298
|
-
end
|
299
|
-
end
|
300
|
-
end
|
301
293
|
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
302
297
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
end
|
313
|
-
when 'staged'
|
314
|
-
unless ancestors.size == 2
|
315
|
-
errors[:ancestors] << 'must have exactly two ancestors (stager + stage) for staged payload module class'
|
316
|
-
end
|
317
|
-
# other (invalid) types are handled by validation on payload_type
|
318
|
-
end
|
319
|
-
else
|
320
|
-
unless ancestors.size == 1
|
321
|
-
errors[:ancestors] << 'must have exactly one ancestor as a non-payload module class'
|
322
|
-
end
|
298
|
+
# Validates that number of {#ancestors} is correct for the {#module_type}.
|
299
|
+
#
|
300
|
+
# @return [void]
|
301
|
+
def ancestors_size
|
302
|
+
if payload?
|
303
|
+
case payload_type
|
304
|
+
when 'single'
|
305
|
+
unless ancestors.size == 1
|
306
|
+
errors[:ancestors] << 'must have exactly one ancestor for single payload module class'
|
323
307
|
end
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
# {#derived_single_payload_reference_name}.
|
328
|
-
#
|
329
|
-
# Derives {#reference_name} for single payload.
|
330
|
-
#
|
331
|
-
# @return [String, nil] '<ancestor.payload_name>'
|
332
|
-
# @return [nil] unless exactly one {#ancestors ancestor}.
|
333
|
-
# @return [nil] unless ancestor's {Metasploit::Model::Module::Ancestor#payload_type} is `'single'`.
|
334
|
-
def derived_single_payload_reference_name
|
335
|
-
derived = nil
|
336
|
-
|
337
|
-
if ancestors.length == 1
|
338
|
-
ancestor = ancestors.first
|
339
|
-
|
340
|
-
if ancestor.payload_type == 'single'
|
341
|
-
derived = ancestor.payload_name
|
342
|
-
end
|
308
|
+
when 'staged'
|
309
|
+
unless ancestors.size == 2
|
310
|
+
errors[:ancestors] << 'must have exactly two ancestors (stager + stage) for staged payload module class'
|
343
311
|
end
|
312
|
+
# other (invalid) types are handled by validation on payload_type
|
313
|
+
end
|
314
|
+
else
|
315
|
+
unless ancestors.size == 1
|
316
|
+
errors[:ancestors] << 'must have exactly one ancestor as a non-payload module class'
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
344
320
|
|
345
|
-
|
346
|
-
|
321
|
+
# @note Caller should check that {#payload?} is `true` and {#payload_type} is 'single' before calling
|
322
|
+
# {#derived_single_payload_reference_name}.
|
323
|
+
#
|
324
|
+
# Derives {#reference_name} for single payload.
|
325
|
+
#
|
326
|
+
# @return [String, nil] '<ancestor.payload_name>'
|
327
|
+
# @return [nil] unless exactly one {#ancestors ancestor}.
|
328
|
+
# @return [nil] unless ancestor's {Metasploit::Model::Module::Ancestor#payload_type} is `'single'`.
|
329
|
+
def derived_single_payload_reference_name
|
330
|
+
derived = nil
|
331
|
+
|
332
|
+
if ancestors.length == 1
|
333
|
+
ancestor = ancestors.first
|
334
|
+
|
335
|
+
if ancestor.payload_type == 'single'
|
336
|
+
derived = ancestor.payload_name
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
derived
|
341
|
+
end
|
347
342
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
end
|
379
|
-
end
|
380
|
-
end
|
343
|
+
# @note Caller should check that {#payload?} is `true` and {#payload_type} is 'staged' before calling
|
344
|
+
# {#derived_staged_payload_reference_name}.
|
345
|
+
#
|
346
|
+
# Derives {#reference_name} for staged payload.
|
347
|
+
#
|
348
|
+
# @return [String] '<stage_ancestor.payload_name>/<stager_ancestor.payload_name>'
|
349
|
+
# @return [nil] unless exactly two {#ancestors ancestor}.
|
350
|
+
# @return [nil] unless {Metasploit::Model::Module::Ancestor#payload_type} is 'single'.
|
351
|
+
# @return [nil] if {Metasploit::Model::Module::Ancestor#payload_name} is `nil` for the stage.
|
352
|
+
# @return [nil] if {Metasploit::Model::Module::Ancestor#payload_name} is `nil` for the stager.
|
353
|
+
def derived_staged_payload_reference_name
|
354
|
+
derived = nil
|
355
|
+
|
356
|
+
if ancestors.length == 2
|
357
|
+
ancestors_by_payload_type = ancestors.group_by(&:payload_type)
|
358
|
+
stage_ancestors = ancestors_by_payload_type.fetch('stage', [])
|
359
|
+
|
360
|
+
# length can be 0..2
|
361
|
+
if stage_ancestors.length == 1
|
362
|
+
stage_ancestor = stage_ancestors.first
|
363
|
+
|
364
|
+
if stage_ancestor.payload_name
|
365
|
+
stager_ancestors = ancestors_by_payload_type.fetch('stager', [])
|
366
|
+
|
367
|
+
# length can be 0..1
|
368
|
+
if stager_ancestors.length == 1
|
369
|
+
stager_ancestor = stager_ancestors.first
|
370
|
+
|
371
|
+
if stager_ancestor.payload_name
|
372
|
+
derived = "#{stage_ancestor.payload_name}/#{stager_ancestor.payload_name}"
|
381
373
|
end
|
382
374
|
end
|
383
|
-
|
384
|
-
derived
|
385
375
|
end
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
derived
|
380
|
+
end
|
386
381
|
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
382
|
+
# Validates that only 1 ancestor with the given payload_type exists.
|
383
|
+
#
|
384
|
+
# @param ancestors_by_payload_type [Hash{String => Array<Metasploit::Model::Module::Ancestor>}] Maps
|
385
|
+
# {Metasploit::Model::Module::Ancestor#payload_type} to the Array of {Metasploit::Model::Module::Ancestor}
|
386
|
+
# with that {Metasploit::Model::Module::Ancestor#payload_type}.
|
387
|
+
# @param ancestor_payload_type [String] {Metasploit::Model::Module::Ancestor#payload_type}.
|
388
|
+
# @return [void]
|
389
|
+
def staged_payload_type_count(ancestors_by_payload_type, ancestor_payload_type)
|
390
|
+
payload_type_ancestors = ancestors_by_payload_type.fetch(ancestor_payload_type, [])
|
391
|
+
payload_type_ancestor_count = payload_type_ancestors.length
|
392
|
+
|
393
|
+
if payload_type_ancestor_count < 1
|
394
|
+
errors[:ancestors] << "needs exactly one ancestor with payload_type (#{ancestor_payload_type}), " \
|
400
395
|
"but there are none."
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
396
|
+
elsif payload_type_ancestor_count > 1
|
397
|
+
full_names = payload_type_ancestors.map(&:full_name).sort
|
398
|
+
full_name_sentence = full_names.to_sentence
|
399
|
+
errors[:ancestors] << "needs exactly one ancestor with payload_type (#{ancestor_payload_type}), " \
|
405
400
|
"but there are #{payload_type_ancestor_count} (#{full_name_sentence})"
|
406
|
-
end
|
407
|
-
end
|
408
|
-
end
|
409
401
|
end
|
410
402
|
end
|
411
|
-
end
|
403
|
+
end
|