metasploit-model 0.27.3 → 0.27.4

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