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.
Files changed (206) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +3 -1
  3. data/config/locales/en.yml +0 -171
  4. data/lib/metasploit/model.rb +0 -2
  5. data/lib/metasploit/model/spec.rb +0 -130
  6. data/lib/metasploit/model/version.rb +1 -1
  7. data/spec/support/shared/examples/metasploit/model/search/operator/help.rb +4 -6
  8. data/spec/support/shared/examples/metasploit/model/translation.rb +1 -1
  9. data/spec/support/shared/examples/search_association.rb +1 -1
  10. data/spec/support/shared/examples/search_with.rb +4 -2
  11. metadata +3 -349
  12. data/app/models/metasploit/model/module/ancestor/spec/template.rb +0 -125
  13. data/app/models/metasploit/model/module/class/spec/template.rb +0 -92
  14. data/app/models/metasploit/model/module/instance/spec/template.rb +0 -97
  15. data/app/models/metasploit/model/spec/template.rb +0 -277
  16. data/app/validators/derivation_validator.rb +0 -17
  17. data/app/validators/dynamic_length_validator.rb +0 -45
  18. data/lib/metasploit/model/architecture.rb +0 -342
  19. data/lib/metasploit/model/author.rb +0 -54
  20. data/lib/metasploit/model/authority.rb +0 -141
  21. data/lib/metasploit/model/authority/bid.rb +0 -10
  22. data/lib/metasploit/model/authority/cve.rb +0 -10
  23. data/lib/metasploit/model/authority/msb.rb +0 -10
  24. data/lib/metasploit/model/authority/osvdb.rb +0 -10
  25. data/lib/metasploit/model/authority/pmasa.rb +0 -10
  26. data/lib/metasploit/model/authority/secunia.rb +0 -10
  27. data/lib/metasploit/model/authority/us_cert_vu.rb +0 -10
  28. data/lib/metasploit/model/authority/waraxe.rb +0 -31
  29. data/lib/metasploit/model/authority/zdi.rb +0 -10
  30. data/lib/metasploit/model/derivation.rb +0 -109
  31. data/lib/metasploit/model/derivation/full_name.rb +0 -19
  32. data/lib/metasploit/model/email_address.rb +0 -124
  33. data/lib/metasploit/model/module.rb +0 -20
  34. data/lib/metasploit/model/module/action.rb +0 -52
  35. data/lib/metasploit/model/module/ancestor.rb +0 -491
  36. data/lib/metasploit/model/module/ancestor/spec.rb +0 -6
  37. data/lib/metasploit/model/module/architecture.rb +0 -34
  38. data/lib/metasploit/model/module/author.rb +0 -40
  39. data/lib/metasploit/model/module/class.rb +0 -403
  40. data/lib/metasploit/model/module/class/spec.rb +0 -6
  41. data/lib/metasploit/model/module/handler.rb +0 -29
  42. data/lib/metasploit/model/module/instance.rb +0 -622
  43. data/lib/metasploit/model/module/instance/spec.rb +0 -6
  44. data/lib/metasploit/model/module/path.rb +0 -159
  45. data/lib/metasploit/model/module/platform.rb +0 -32
  46. data/lib/metasploit/model/module/rank.rb +0 -85
  47. data/lib/metasploit/model/module/reference.rb +0 -32
  48. data/lib/metasploit/model/module/stance.rb +0 -16
  49. data/lib/metasploit/model/module/target.rb +0 -78
  50. data/lib/metasploit/model/module/target/architecture.rb +0 -34
  51. data/lib/metasploit/model/module/target/platform.rb +0 -34
  52. data/lib/metasploit/model/module/type.rb +0 -38
  53. data/lib/metasploit/model/platform.rb +0 -246
  54. data/lib/metasploit/model/real_pathname.rb +0 -16
  55. data/lib/metasploit/model/reference.rb +0 -104
  56. data/spec/app/models/metasploit/model/module/ancestor/spec/template_spec.rb +0 -174
  57. data/spec/app/models/metasploit/model/module/class/spec/template_spec.rb +0 -222
  58. data/spec/app/models/metasploit/model/module/instance/spec/template_spec.rb +0 -201
  59. data/spec/app/models/metasploit/model/search/operator/deprecated/app_spec.rb +0 -62
  60. data/spec/app/models/metasploit/model/search/operator/deprecated/author_spec.rb +0 -197
  61. data/spec/app/models/metasploit/model/search/operator/deprecated/authority_spec.rb +0 -135
  62. data/spec/app/models/metasploit/model/search/operator/deprecated/platform_spec.rb +0 -124
  63. data/spec/app/models/metasploit/model/search/operator/deprecated/ref_spec.rb +0 -387
  64. data/spec/app/models/metasploit/model/search/operator/deprecated/text_spec.rb +0 -399
  65. data/spec/app/models/metasploit/model/spec/template_spec.rb +0 -23
  66. data/spec/app/validators/derivation_validator_spec.rb +0 -92
  67. data/spec/app/validators/dynamic_length_validator_spec.rb +0 -293
  68. data/spec/dummy/app/models/dummy/architecture.rb +0 -92
  69. data/spec/dummy/app/models/dummy/author.rb +0 -15
  70. data/spec/dummy/app/models/dummy/authority.rb +0 -130
  71. data/spec/dummy/app/models/dummy/email_address.rb +0 -27
  72. data/spec/dummy/app/models/dummy/module/action.rb +0 -25
  73. data/spec/dummy/app/models/dummy/module/ancestor.rb +0 -67
  74. data/spec/dummy/app/models/dummy/module/architecture.rb +0 -19
  75. data/spec/dummy/app/models/dummy/module/author.rb +0 -28
  76. data/spec/dummy/app/models/dummy/module/class.rb +0 -69
  77. data/spec/dummy/app/models/dummy/module/instance.rb +0 -209
  78. data/spec/dummy/app/models/dummy/module/path.rb +0 -64
  79. data/spec/dummy/app/models/dummy/module/platform.rb +0 -19
  80. data/spec/dummy/app/models/dummy/module/rank.rb +0 -44
  81. data/spec/dummy/app/models/dummy/module/reference.rb +0 -19
  82. data/spec/dummy/app/models/dummy/module/target.rb +0 -62
  83. data/spec/dummy/app/models/dummy/module/target/architecture.rb +0 -19
  84. data/spec/dummy/app/models/dummy/module/target/platform.rb +0 -19
  85. data/spec/dummy/app/models/dummy/platform.rb +0 -58
  86. data/spec/dummy/app/models/dummy/reference.rb +0 -31
  87. data/spec/dummy/spec/factories/dummy/architectures.rb +0 -13
  88. data/spec/dummy/spec/factories/dummy/authorities.rb +0 -32
  89. data/spec/dummy/spec/factories/dummy/authors.rb +0 -8
  90. data/spec/dummy/spec/factories/dummy/email_addresses.rb +0 -8
  91. data/spec/dummy/spec/factories/dummy/module/actions.rb +0 -13
  92. data/spec/dummy/spec/factories/dummy/module/ancestors.rb +0 -45
  93. data/spec/dummy/spec/factories/dummy/module/architectures.rb +0 -35
  94. data/spec/dummy/spec/factories/dummy/module/authors.rb +0 -10
  95. data/spec/dummy/spec/factories/dummy/module/classes.rb +0 -40
  96. data/spec/dummy/spec/factories/dummy/module/instances.rb +0 -86
  97. data/spec/dummy/spec/factories/dummy/module/paths.rb +0 -16
  98. data/spec/dummy/spec/factories/dummy/module/platforms.rb +0 -35
  99. data/spec/dummy/spec/factories/dummy/module/ranks.rb +0 -14
  100. data/spec/dummy/spec/factories/dummy/module/references.rb +0 -17
  101. data/spec/dummy/spec/factories/dummy/module/target/architectures.rb +0 -40
  102. data/spec/dummy/spec/factories/dummy/module/target/platforms.rb +0 -41
  103. data/spec/dummy/spec/factories/dummy/module/targets.rb +0 -46
  104. data/spec/dummy/spec/factories/dummy/platforms.rb +0 -3
  105. data/spec/dummy/spec/factories/dummy/references.rb +0 -26
  106. data/spec/factories/metasploit/model/architectures.rb +0 -6
  107. data/spec/factories/metasploit/model/authorities.rb +0 -28
  108. data/spec/factories/metasploit/model/authors.rb +0 -9
  109. data/spec/factories/metasploit/model/email_addresses.rb +0 -14
  110. data/spec/factories/metasploit/model/module/actions.rb +0 -9
  111. data/spec/factories/metasploit/model/module/ancestors.rb +0 -180
  112. data/spec/factories/metasploit/model/module/architectures.rb +0 -15
  113. data/spec/factories/metasploit/model/module/classes.rb +0 -47
  114. data/spec/factories/metasploit/model/module/handlers.rb +0 -3
  115. data/spec/factories/metasploit/model/module/instances.rb +0 -83
  116. data/spec/factories/metasploit/model/module/paths.rb +0 -51
  117. data/spec/factories/metasploit/model/module/platforms.rb +0 -15
  118. data/spec/factories/metasploit/model/module/ranks.rb +0 -9
  119. data/spec/factories/metasploit/model/module/references.rb +0 -11
  120. data/spec/factories/metasploit/model/module/stances.rb +0 -3
  121. data/spec/factories/metasploit/model/module/targets.rb +0 -22
  122. data/spec/factories/metasploit/model/module/types.rb +0 -5
  123. data/spec/factories/metasploit/model/references.rb +0 -88
  124. data/spec/lib/metasploit/model/architecture_spec.rb +0 -52
  125. data/spec/lib/metasploit/model/author_spec.rb +0 -6
  126. data/spec/lib/metasploit/model/authority/bid_spec.rb +0 -17
  127. data/spec/lib/metasploit/model/authority/cve_spec.rb +0 -17
  128. data/spec/lib/metasploit/model/authority/msb_spec.rb +0 -17
  129. data/spec/lib/metasploit/model/authority/osvdb_spec.rb +0 -17
  130. data/spec/lib/metasploit/model/authority/pmasa_spec.rb +0 -17
  131. data/spec/lib/metasploit/model/authority/secunia_spec.rb +0 -17
  132. data/spec/lib/metasploit/model/authority/us_cert_vu_spec.rb +0 -17
  133. data/spec/lib/metasploit/model/authority/waraxe_spec.rb +0 -51
  134. data/spec/lib/metasploit/model/authority/zdi_spec.rb +0 -21
  135. data/spec/lib/metasploit/model/authority_spec.rb +0 -10
  136. data/spec/lib/metasploit/model/derivation/full_name_spec.rb +0 -75
  137. data/spec/lib/metasploit/model/derivation_spec.rb +0 -217
  138. data/spec/lib/metasploit/model/email_address_spec.rb +0 -19
  139. data/spec/lib/metasploit/model/module/action_spec.rb +0 -6
  140. data/spec/lib/metasploit/model/module/ancestor_spec.rb +0 -6
  141. data/spec/lib/metasploit/model/module/architecture_spec.rb +0 -9
  142. data/spec/lib/metasploit/model/module/author_spec.rb +0 -6
  143. data/spec/lib/metasploit/model/module/class_spec.rb +0 -19
  144. data/spec/lib/metasploit/model/module/handler_spec.rb +0 -61
  145. data/spec/lib/metasploit/model/module/instance_spec.rb +0 -183
  146. data/spec/lib/metasploit/model/module/path_spec.rb +0 -6
  147. data/spec/lib/metasploit/model/module/platform_spec.rb +0 -9
  148. data/spec/lib/metasploit/model/module/rank_spec.rb +0 -29
  149. data/spec/lib/metasploit/model/module/reference_spec.rb +0 -9
  150. data/spec/lib/metasploit/model/module/stance_spec.rb +0 -30
  151. data/spec/lib/metasploit/model/module/target/architecture_spec.rb +0 -9
  152. data/spec/lib/metasploit/model/module/target/platform_spec.rb +0 -9
  153. data/spec/lib/metasploit/model/module/target_spec.rb +0 -9
  154. data/spec/lib/metasploit/model/module/type_spec.rb +0 -125
  155. data/spec/lib/metasploit/model/platform_spec.rb +0 -100
  156. data/spec/lib/metasploit/model/reference_spec.rb +0 -21
  157. data/spec/support/shared/contexts/metasploit/model/module/ancestor/contents/metasploit_module.rb +0 -12
  158. data/spec/support/shared/contexts/metasploit/model/module/ancestor/factory/contents.rb +0 -10
  159. data/spec/support/shared/contexts/metasploit/model/module/ancestor/factory/contents/metasploit_module.rb +0 -15
  160. data/spec/support/shared/examples/derives.rb +0 -115
  161. data/spec/support/shared/examples/metasploit/model/architecture.rb +0 -425
  162. data/spec/support/shared/examples/metasploit/model/architecture/seed.rb +0 -25
  163. data/spec/support/shared/examples/metasploit/model/author.rb +0 -27
  164. data/spec/support/shared/examples/metasploit/model/authority.rb +0 -124
  165. data/spec/support/shared/examples/metasploit/model/authority/seed.rb +0 -49
  166. data/spec/support/shared/examples/metasploit/model/email_address.rb +0 -220
  167. data/spec/support/shared/examples/metasploit/model/module/action.rb +0 -26
  168. data/spec/support/shared/examples/metasploit/model/module/ancestor.rb +0 -2004
  169. data/spec/support/shared/examples/metasploit/model/module/ancestor/payload_factory.rb +0 -63
  170. data/spec/support/shared/examples/metasploit/model/module/architecture.rb +0 -36
  171. data/spec/support/shared/examples/metasploit/model/module/author.rb +0 -29
  172. data/spec/support/shared/examples/metasploit/model/module/class.rb +0 -1514
  173. data/spec/support/shared/examples/metasploit/model/module/handler.rb +0 -21
  174. data/spec/support/shared/examples/metasploit/model/module/instance.rb +0 -1384
  175. data/spec/support/shared/examples/metasploit/model/module/instance/class_methods.rb +0 -537
  176. data/spec/support/shared/examples/metasploit/model/module/instance/is_not_stanced_with_module_type.rb +0 -22
  177. data/spec/support/shared/examples/metasploit/model/module/instance/is_stanced_with_module_type.rb +0 -38
  178. data/spec/support/shared/examples/metasploit/model/module/instance/validates/dynamic_length_of.rb +0 -131
  179. data/spec/support/shared/examples/metasploit/model/module/path.rb +0 -493
  180. data/spec/support/shared/examples/metasploit/model/module/platform.rb +0 -36
  181. data/spec/support/shared/examples/metasploit/model/module/rank.rb +0 -92
  182. data/spec/support/shared/examples/metasploit/model/module/reference.rb +0 -16
  183. data/spec/support/shared/examples/metasploit/model/module/target.rb +0 -29
  184. data/spec/support/shared/examples/metasploit/model/module/target/architecture.rb +0 -56
  185. data/spec/support/shared/examples/metasploit/model/module/target/platform.rb +0 -56
  186. data/spec/support/shared/examples/metasploit/model/platform.rb +0 -213
  187. data/spec/support/shared/examples/metasploit/model/real_pathname.rb +0 -29
  188. data/spec/support/shared/examples/metasploit/model/reference.rb +0 -410
  189. data/spec/support/shared/examples/search/query/metasploit/model/search/operator/deprecated/app.rb +0 -44
  190. data/spec/support/shared/examples/search/query/metasploit/model/search/operator/deprecated/authority.rb +0 -72
  191. data/spec/support/templates/metasploit/model/module/ancestors/_attributes.rb.erb +0 -9
  192. data/spec/support/templates/metasploit/model/module/ancestors/_methods.rb.erb +0 -8
  193. data/spec/support/templates/metasploit/model/module/ancestors/_validations.rb.erb +0 -6
  194. data/spec/support/templates/metasploit/model/module/ancestors/base.rb.erb +0 -3
  195. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_auxiliary.rb.erb +0 -1
  196. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_encoder.rb.erb +0 -1
  197. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_exploit.rb.erb +0 -1
  198. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_non_payload.rb.erb +0 -5
  199. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_nop.rb.erb +0 -1
  200. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_payload.rb.erb +0 -4
  201. data/spec/support/templates/metasploit/model/module/ancestors/module_types/_post.rb.erb +0 -1
  202. data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_handled.rb.erb +0 -20
  203. data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_single.rb.erb +0 -1
  204. data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_stage.rb.erb +0 -0
  205. data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_stager.rb.erb +0 -1
  206. data/spec/support/templates/metasploit/model/module/classes/_methods.rb.erb +0 -9
@@ -1,6 +0,0 @@
1
- # Namespace for `Module`s that help with writing specs for {Metasploit::Model::Module::Ancestor}.
2
- module Metasploit::Model::Module::Ancestor::Spec
3
- extend ActiveSupport::Autoload
4
-
5
- autoload :Template
6
- end
@@ -1,34 +0,0 @@
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
5
-
6
- include Metasploit::Model::Translation
7
-
8
- included do
9
- include ActiveModel::Validations
10
-
11
- #
12
- # Validations
13
- #
14
-
15
- validates :architecture,
16
- :presence => true
17
- validates :module_instance,
18
- :presence => true
19
- end
20
-
21
- #
22
- # Attributes
23
- #
24
-
25
- # @!attribute [rw] architecture
26
- # The architecture supported by the {#module_instance}.
27
- #
28
- # @return [Metasploit::Model::Architecture]
29
-
30
- # @!attribute [rw] module_instance
31
- # The module instance that supports {#architecture}.
32
- #
33
- # @return [Metasploit::Model::Module::Instance]
34
- end
@@ -1,40 +0,0 @@
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
19
- end
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,403 +0,0 @@
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
79
-
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
146
-
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
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'
171
- end
172
- when 2
173
- payload_type_set = Set.new
174
-
175
- ancestors.each do |ancestor|
176
- payload_type_set.add ancestor.payload_type
177
- end
178
-
179
- if payload_type_set.include? 'stager' and payload_type_set.include? 'stage'
180
- derived = 'staged'
181
- end
182
- end
183
- end
184
-
185
- derived
186
- end
187
-
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
211
-
212
- derived
213
- end
214
-
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
226
-
227
- private
228
-
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
235
-
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}); " \
239
- "#{ancestor.full_name} cannot be an ancestor due to its module_type " \
240
- "(#{ancestor.module_type})"
241
- end
242
-
243
- ancestor_module_type_set.add ancestor.module_type
244
- end
245
-
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, " \
249
- "but contains multiple module_types (#{ancestor_module_type_sentence})"
250
- end
251
- end
252
-
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}) " \
264
- "with payload_type (#{ancestor.payload_type}) " \
265
- "for class payload_type (#{payload_type})"
266
- end
267
- end
268
- when 'staged'
269
- ancestors_by_payload_type = ancestors.group_by(&:payload_type)
270
-
271
- STAGED_ANCESTOR_PAYLOAD_TYPES.each do |ancestor_payload_type|
272
- staged_payload_type_count(ancestors_by_payload_type, ancestor_payload_type)
273
- end
274
-
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
279
-
280
- errors[:ancestors] << "cannot have ancestors (#{full_name_sentence}) " \
281
- "with payload_type (#{ancestor_payload_type}) " \
282
- "for class payload_type (#{payload_type}); " \
283
- "only one stage and one stager ancestor is allowed"
284
- end
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}) " \
291
- "with a payload_type (#{ancestor.payload_type}) " \
292
- "for class module_type (#{module_type})"
293
- end
294
- end
295
- end
296
- end
297
-
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'
307
- end
308
- when 'staged'
309
- unless ancestors.size == 2
310
- errors[:ancestors] << 'must have exactly two ancestors (stager + stage) for staged payload module class'
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
320
-
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
342
-
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}"
373
- end
374
- end
375
- end
376
- end
377
- end
378
-
379
- derived
380
- end
381
-
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}), " \
395
- "but there are none."
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}), " \
400
- "but there are #{payload_type_ancestor_count} (#{full_name_sentence})"
401
- end
402
- end
403
- end