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