metasploit-model 0.27.3-java → 0.27.4-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/app/models/metasploit/model/association/reflection.rb +0 -3
- data/app/models/metasploit/model/module/ancestor/spec/template.rb +0 -3
- data/app/models/metasploit/model/module/class/spec/template.rb +0 -4
- data/app/models/metasploit/model/module/instance/spec/template.rb +0 -4
- data/app/models/metasploit/model/search/group/base.rb +0 -3
- data/app/models/metasploit/model/search/group/intersection.rb +0 -3
- data/app/models/metasploit/model/search/group/union.rb +0 -3
- data/app/models/metasploit/model/search/operation/association.rb +0 -2
- data/app/models/metasploit/model/search/operation/base.rb +0 -3
- data/app/models/metasploit/model/search/operation/boolean.rb +0 -2
- data/app/models/metasploit/model/search/operation/date.rb +0 -2
- data/app/models/metasploit/model/search/operation/group/base.rb +0 -2
- data/app/models/metasploit/model/search/operation/group/intersection.rb +0 -2
- data/app/models/metasploit/model/search/operation/group/union.rb +0 -2
- data/app/models/metasploit/model/search/operation/integer.rb +1 -5
- data/app/models/metasploit/model/search/operation/null.rb +0 -2
- data/app/models/metasploit/model/search/operation/set.rb +5 -2
- data/app/models/metasploit/model/search/operation/set/integer.rb +1 -3
- data/app/models/metasploit/model/search/operation/set/string.rb +1 -3
- data/app/models/metasploit/model/search/operation/string.rb +1 -5
- data/app/models/metasploit/model/search/operator/association.rb +0 -2
- data/app/models/metasploit/model/search/operator/attribute.rb +0 -2
- data/app/models/metasploit/model/search/operator/base.rb +0 -4
- data/app/models/metasploit/model/search/operator/delegation.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/app.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/author.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/authority.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/platform.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/ref.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/text.rb +0 -2
- data/app/models/metasploit/model/search/operator/group/base.rb +0 -2
- data/app/models/metasploit/model/search/operator/group/intersection.rb +0 -2
- data/app/models/metasploit/model/search/operator/group/union.rb +0 -2
- data/app/models/metasploit/model/search/operator/null.rb +0 -2
- data/app/models/metasploit/model/search/operator/single.rb +0 -2
- data/app/models/metasploit/model/search/query.rb +0 -3
- data/app/models/metasploit/model/spec/template.rb +0 -3
- data/app/models/metasploit/model/visitation/visitor.rb +0 -3
- data/lib/metasploit/model.rb +14 -8
- data/lib/metasploit/model/architecture.rb +320 -326
- data/lib/metasploit/model/association.rb +43 -46
- data/lib/metasploit/model/association/error.rb +29 -33
- data/lib/metasploit/model/association/tree.rb +119 -125
- data/lib/metasploit/model/author.rb +45 -51
- data/lib/metasploit/model/authority.rb +139 -146
- data/lib/metasploit/model/authority/bid.rb +0 -2
- data/lib/metasploit/model/authority/cve.rb +0 -2
- data/lib/metasploit/model/authority/msb.rb +0 -2
- data/lib/metasploit/model/authority/osvdb.rb +0 -2
- data/lib/metasploit/model/authority/pmasa.rb +0 -2
- data/lib/metasploit/model/authority/secunia.rb +0 -2
- data/lib/metasploit/model/authority/us_cert_vu.rb +0 -2
- data/lib/metasploit/model/authority/waraxe.rb +0 -2
- data/lib/metasploit/model/authority/zdi.rb +0 -2
- data/lib/metasploit/model/base.rb +0 -2
- data/lib/metasploit/model/derivation.rb +95 -99
- data/lib/metasploit/model/derivation/full_name.rb +16 -22
- data/lib/metasploit/model/email_address.rb +122 -128
- data/lib/metasploit/model/engine.rb +26 -21
- data/lib/metasploit/model/error.rb +3 -7
- data/lib/metasploit/model/file.rb +0 -2
- data/lib/metasploit/model/invalid.rb +11 -17
- data/lib/metasploit/model/login.rb +0 -3
- data/lib/metasploit/model/login/status.rb +0 -2
- data/lib/metasploit/model/module.rb +19 -23
- data/lib/metasploit/model/module/action.rb +50 -58
- data/lib/metasploit/model/module/ancestor.rb +456 -465
- data/lib/metasploit/model/module/ancestor/spec.rb +3 -2
- data/lib/metasploit/model/module/architecture.rb +27 -35
- data/lib/metasploit/model/module/author.rb +38 -47
- data/lib/metasploit/model/module/class.rb +358 -366
- data/lib/metasploit/model/module/class/spec.rb +3 -2
- data/lib/metasploit/model/module/handler.rb +28 -34
- data/lib/metasploit/model/module/instance.rb +586 -596
- data/lib/metasploit/model/module/instance/spec.rb +3 -2
- data/lib/metasploit/model/module/path.rb +157 -166
- data/lib/metasploit/model/module/platform.rb +25 -33
- data/lib/metasploit/model/module/rank.rb +71 -79
- data/lib/metasploit/model/module/reference.rb +25 -33
- data/lib/metasploit/model/module/stance.rb +15 -21
- data/lib/metasploit/model/module/target.rb +76 -84
- data/lib/metasploit/model/module/target/architecture.rb +27 -37
- data/lib/metasploit/model/module/target/platform.rb +27 -37
- data/lib/metasploit/model/module/type.rb +35 -41
- data/lib/metasploit/model/nilify_blanks.rb +39 -43
- data/lib/metasploit/model/platform.rb +231 -237
- data/lib/metasploit/model/real_pathname.rb +12 -16
- data/lib/metasploit/model/realm.rb +0 -2
- data/lib/metasploit/model/realm/key.rb +0 -2
- data/lib/metasploit/model/reference.rb +102 -108
- data/lib/metasploit/model/search.rb +94 -97
- data/lib/metasploit/model/search/association.rb +163 -169
- data/lib/metasploit/model/search/attribute.rb +131 -139
- data/lib/metasploit/model/search/group.rb +5 -2
- data/lib/metasploit/model/search/operation.rb +32 -29
- data/lib/metasploit/model/search/operation/group.rb +5 -2
- data/lib/metasploit/model/search/operation/value.rb +7 -0
- data/lib/metasploit/model/search/operation/{integer/value.rb → value/integer.rb} +1 -1
- data/lib/metasploit/model/search/operation/{string/value.rb → value/string.rb} +1 -1
- data/lib/metasploit/model/search/operator.rb +65 -65
- data/lib/metasploit/model/search/operator/deprecated.rb +8 -2
- data/lib/metasploit/model/search/operator/group.rb +5 -2
- data/lib/metasploit/model/search/operator/help.rb +71 -79
- data/lib/metasploit/model/search/with.rb +72 -78
- data/lib/metasploit/model/spec.rb +133 -136
- data/lib/metasploit/model/spec/error.rb +3 -9
- data/lib/metasploit/model/spec/i18n_exception_handler.rb +0 -2
- data/lib/metasploit/model/spec/pathname_collision.rb +19 -27
- data/lib/metasploit/model/spec/template/write.rb +0 -2
- data/lib/metasploit/model/spec/temporary_pathname.rb +47 -56
- data/lib/metasploit/model/translation.rb +0 -2
- data/lib/metasploit/model/version.rb +1 -1
- data/lib/metasploit/model/visitation.rb +7 -10
- data/lib/metasploit/model/visitation/visit.rb +79 -85
- data/metasploit-model.gemspec +1 -1
- data/spec/app/models/metasploit/model/search/operation/integer_spec.rb +1 -1
- data/spec/app/models/metasploit/model/search/operation/set/integer_spec.rb +1 -1
- data/spec/app/models/metasploit/model/search/operation/set/string_spec.rb +1 -1
- data/spec/app/models/metasploit/model/search/operation/string_spec.rb +1 -1
- data/spec/dummy/config/application.rb +1 -0
- data/spec/lib/metasploit/model/search/operation/{integer/value_spec.rb → value/integer_spec.rb} +2 -2
- data/spec/lib/metasploit/model/search/operation/{string/value_spec.rb → value/string_spec.rb} +2 -2
- data/spec/support/shared/examples/metasploit/model/search/operation/{integer/value.rb → value/integer.rb} +2 -2
- data/spec/support/shared/examples/metasploit/model/search/operation/{string/value.rb → value/string.rb} +2 -2
- metadata +16 -13
|
@@ -1,176 +1,170 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
#
|
|
93
|
-
module Association
|
|
94
|
-
extend ActiveSupport::Concern
|
|
1
|
+
# Use search operators registered on an associated class using
|
|
2
|
+
# {Metasploit::Model::Search::Attribute::ClassMethods#search_attribute},
|
|
3
|
+
# {Metasploit::Model::Search::With::ClassMethods#search_with}.
|
|
4
|
+
#
|
|
5
|
+
# Searchable associations are declared explicitly so that associations cycles can be avoided and the search
|
|
6
|
+
# interface can be tuned for clarity and complexity.
|
|
7
|
+
#
|
|
8
|
+
# # Testing
|
|
9
|
+
#
|
|
10
|
+
# {ClassMethods#search_association} calls can be tested with the 'search_association' shared example. First,
|
|
11
|
+
# ensure the shared examples from `metasploit-model` are required in your `spec_helper.rb`:
|
|
12
|
+
#
|
|
13
|
+
# # spec/spec_helper.rb
|
|
14
|
+
# support_glob = Metasploit::Model::Engine.root.join('spec', 'support', '**', '*.rb')
|
|
15
|
+
#
|
|
16
|
+
# Dir.glob(support_glob) do |path|
|
|
17
|
+
# require path
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
# In the spec for the `Class` that called `search_association`, use the 'search_association' shared example:
|
|
21
|
+
#
|
|
22
|
+
# # spec/app/models/my_class_spec.rb
|
|
23
|
+
# require 'spec_helper'
|
|
24
|
+
#
|
|
25
|
+
# describe MyClass do
|
|
26
|
+
# context 'search' do
|
|
27
|
+
# context 'associations' do
|
|
28
|
+
# it_should_be_like 'search_association', :association_name
|
|
29
|
+
# end
|
|
30
|
+
# end
|
|
31
|
+
# end
|
|
32
|
+
#
|
|
33
|
+
# @example Search near and far associations
|
|
34
|
+
# class Root
|
|
35
|
+
# include Metasploit::Model::Association
|
|
36
|
+
# include Metasploit::Model::Search
|
|
37
|
+
#
|
|
38
|
+
# #
|
|
39
|
+
# # Associations
|
|
40
|
+
# #
|
|
41
|
+
#
|
|
42
|
+
# association :children,
|
|
43
|
+
# class_name: 'Child'
|
|
44
|
+
#
|
|
45
|
+
# #
|
|
46
|
+
# # Search
|
|
47
|
+
# #
|
|
48
|
+
#
|
|
49
|
+
# search_association children: :grandchildren
|
|
50
|
+
# end
|
|
51
|
+
#
|
|
52
|
+
# class Child
|
|
53
|
+
# include Metasploit::Model::Association
|
|
54
|
+
# include Metasploit::Model::Search
|
|
55
|
+
#
|
|
56
|
+
# #
|
|
57
|
+
# # Associations
|
|
58
|
+
# #
|
|
59
|
+
#
|
|
60
|
+
# association :grandchildren,
|
|
61
|
+
# class_name: 'Grandchild'
|
|
62
|
+
#
|
|
63
|
+
# #
|
|
64
|
+
# # Search
|
|
65
|
+
# #
|
|
66
|
+
#
|
|
67
|
+
# search_attribute :name,
|
|
68
|
+
# type: :string
|
|
69
|
+
# end
|
|
70
|
+
#
|
|
71
|
+
# class Grandchild
|
|
72
|
+
# include Metasploit::Model::Search
|
|
73
|
+
#
|
|
74
|
+
# search_attribute :age,
|
|
75
|
+
# type: :integer
|
|
76
|
+
# end
|
|
77
|
+
#
|
|
78
|
+
# Root.search_operator_by_name.each_value
|
|
79
|
+
# # :'children.name'
|
|
80
|
+
# # :'children.grandchildren.age'
|
|
81
|
+
#
|
|
82
|
+
# Child.search_operator_by_name.each_value
|
|
83
|
+
# # :name
|
|
84
|
+
# # @note ``:'grandchildren.age'`` is not in `Child`'s operators because it didn't declare
|
|
85
|
+
# # `search_association :grandchildren`, only `Root` did.
|
|
86
|
+
#
|
|
87
|
+
# Grandchild.search_operator_name
|
|
88
|
+
# # :age
|
|
89
|
+
#
|
|
90
|
+
module Metasploit::Model::Search::Association
|
|
91
|
+
extend ActiveSupport::Concern
|
|
95
92
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
93
|
+
# Adds {#search_association} DSL to make {Metasploit::Model::Search::Operator::Association association search
|
|
94
|
+
# operators}.
|
|
95
|
+
module ClassMethods
|
|
96
|
+
# @note Use {#search_associations} to declare multiple associations or a tree of far associations as
|
|
97
|
+
# searchable.
|
|
98
|
+
#
|
|
99
|
+
# Registers association for search.
|
|
100
|
+
#
|
|
101
|
+
# @example a single searchable association
|
|
102
|
+
# search_association :children
|
|
103
|
+
#
|
|
104
|
+
# @param association [#to_sym] name of association to search.
|
|
105
|
+
# @return [void]
|
|
106
|
+
# @see #search_associations
|
|
107
|
+
def search_association(association)
|
|
108
|
+
search_association_tree[association.to_sym] ||= nil
|
|
109
|
+
end
|
|
113
110
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
111
|
+
# Registers a tree of near and far associations for search. When a tree is used, all intermediate association
|
|
112
|
+
# on the paths are used, so `search_association children: :grandchildren` makes both `children.granchildren`
|
|
113
|
+
# *and* `children` as search operator prefixes.
|
|
114
|
+
#
|
|
115
|
+
# @example a single search association
|
|
116
|
+
# search_associations :children
|
|
117
|
+
#
|
|
118
|
+
# @example multiple near associations
|
|
119
|
+
# search_associations :first,
|
|
120
|
+
# :second
|
|
121
|
+
#
|
|
122
|
+
# @example far association
|
|
123
|
+
# search_associations near: :far
|
|
124
|
+
#
|
|
125
|
+
# @example multiple far associations
|
|
126
|
+
# search_associations near: [
|
|
127
|
+
# :first_far,
|
|
128
|
+
# :second_far
|
|
129
|
+
# ]
|
|
130
|
+
#
|
|
131
|
+
# @example mix of near and far associations
|
|
132
|
+
# # Keep associations in order by near association names by mixing Symbols and Hash{Symbol => Object}
|
|
133
|
+
# search_associations :apple,
|
|
134
|
+
# {
|
|
135
|
+
# banana: :peel
|
|
136
|
+
# },
|
|
137
|
+
# :cucumber
|
|
138
|
+
#
|
|
139
|
+
#
|
|
140
|
+
# @param associations [Array<Array, Hash, Symbol>, Hash, Symbol]
|
|
141
|
+
# @return [void]
|
|
142
|
+
# @see search_association
|
|
143
|
+
def search_associations(*associations)
|
|
144
|
+
expanded_associations = Metasploit::Model::Association::Tree.expand(associations)
|
|
148
145
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
146
|
+
@search_association_tree = Metasploit::Model::Association::Tree.merge(
|
|
147
|
+
search_association_tree,
|
|
148
|
+
expanded_associations
|
|
149
|
+
)
|
|
150
|
+
end
|
|
154
151
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
152
|
+
# The association operators for the searchable associations declared with {#search_association} and
|
|
153
|
+
# {#search_associations}.
|
|
154
|
+
#
|
|
155
|
+
# @return (see Metasploit::Model::Association::Tree.operators)
|
|
156
|
+
def search_association_operators
|
|
157
|
+
@search_association_operators ||= Metasploit::Model::Association::Tree.operators(
|
|
158
|
+
search_association_tree,
|
|
159
|
+
class: self
|
|
160
|
+
)
|
|
161
|
+
end
|
|
165
162
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
end
|
|
163
|
+
# Tree of associations that are searchable.
|
|
164
|
+
#
|
|
165
|
+
# @return [Hash{Symbol => Hash,nil}]
|
|
166
|
+
def search_association_tree
|
|
167
|
+
@search_association_tree ||= {}
|
|
174
168
|
end
|
|
175
169
|
end
|
|
176
|
-
end
|
|
170
|
+
end
|
|
@@ -1,143 +1,135 @@
|
|
|
1
|
-
|
|
1
|
+
# Registers attributes that can be searched. Attributes must be declared to be searchable as a type from
|
|
2
|
+
# {Metasploit::Model::Search::Operator::Attribute::TYPES}. The type of the attribute is used to select a
|
|
3
|
+
# type-specific {Metasploit::Model::Search::Operation}, which will validate the
|
|
4
|
+
# {Metasploit::Model::Search::Operation::Base#value} is of the valid type.
|
|
5
|
+
#
|
|
6
|
+
# # Set attributes
|
|
7
|
+
#
|
|
8
|
+
# Search attributes declared as having an integer set or string set type integer or string set require a
|
|
9
|
+
# `<attribute>_set` method to be defined on the `Class`, which returns the set of allowed values for the search
|
|
10
|
+
# attribute's operation. This method will be called, indirectly by
|
|
11
|
+
# {Metasploit::Model::Search::Operation::Set::Integer}'s and {Metasploit::Model::Search::Operation::Set::String}'s
|
|
12
|
+
# validations.
|
|
13
|
+
#
|
|
14
|
+
# # Help
|
|
15
|
+
#
|
|
16
|
+
# The help for each operator is uses the `I18n` system, so the help for an attribute operator on a given class can
|
|
17
|
+
# added to `config/locales/<lang>.yml`. The scope of the lookup, under the language key is the `Class`'s
|
|
18
|
+
# `i18n_scope`, which is `metasploit.model` if the `Class` includes {Metasploit::Model::Translation} or
|
|
19
|
+
# `active_record` for `ActiveRecord::Base` subclasses. Under the `i18n_scope`, any `Module#ancestor`'s
|
|
20
|
+
# `model_name.i18n_key` can be used to look up the help for an attribute's operator. This allows for super
|
|
21
|
+
# classes or mixins to define the search operator help for subclasses.
|
|
22
|
+
#
|
|
23
|
+
# # config/locales/<lang>.yml
|
|
24
|
+
# <lang>:
|
|
25
|
+
# <Class#i18n_scope>:
|
|
26
|
+
# ancestors:
|
|
27
|
+
# <ancestor.model_name.i18n_key>:
|
|
28
|
+
# search:
|
|
29
|
+
# operator:
|
|
30
|
+
# names:
|
|
31
|
+
# <attribute>:
|
|
32
|
+
# help: "The attribute on the class"
|
|
33
|
+
#
|
|
34
|
+
# # Testing
|
|
35
|
+
#
|
|
36
|
+
# {ClassMethods#search_attribute} calls can be tested with the 'search_attribute' shared example. First, ensure
|
|
37
|
+
# the shared examples from `metasploit-model` are required in your `spec_helper.rb`:
|
|
38
|
+
#
|
|
39
|
+
# # spec/spec_helper.rb
|
|
40
|
+
# support_glob = Metasploit::Model::Engine.root.join('spec', 'support', '**', '*.rb')
|
|
41
|
+
#
|
|
42
|
+
# Dir.glob(support_glob) do |path|
|
|
43
|
+
# require path
|
|
44
|
+
# end
|
|
45
|
+
#
|
|
46
|
+
# In the spec for the `Class` that called `search_attribute`, use the 'search_attribute' shared example by
|
|
47
|
+
# passing that arguments passed to {ClassMethods#search_attribute}.
|
|
48
|
+
#
|
|
49
|
+
# # spec/app/models/my_class_spec.rb
|
|
50
|
+
# require 'spec_helper'
|
|
51
|
+
#
|
|
52
|
+
# describe MyClass do
|
|
53
|
+
# context 'search' do
|
|
54
|
+
# context 'attributes' do
|
|
55
|
+
# it_should_behave_like 'search_attribute',
|
|
56
|
+
# type: {
|
|
57
|
+
# set: :string
|
|
58
|
+
# }
|
|
59
|
+
# end
|
|
60
|
+
# end
|
|
61
|
+
# end
|
|
62
|
+
#
|
|
63
|
+
# @example search an attribute for `true` or `false`
|
|
64
|
+
# search_attribute :flag,
|
|
65
|
+
# type: :boolean
|
|
66
|
+
#
|
|
67
|
+
# @example search an attribute for an integer
|
|
68
|
+
# search_attribute :age,
|
|
69
|
+
# type: :integer
|
|
70
|
+
#
|
|
71
|
+
# @example search an attribute for a restricted set of integers
|
|
72
|
+
# #
|
|
73
|
+
# # Search
|
|
74
|
+
# #
|
|
75
|
+
#
|
|
76
|
+
# search_attribute :bits,
|
|
77
|
+
# set: :integer
|
|
78
|
+
#
|
|
79
|
+
# #
|
|
80
|
+
# # Class Methods
|
|
81
|
+
# #
|
|
82
|
+
#
|
|
83
|
+
# # Return set of allowed values for {#bits} search.
|
|
84
|
+
# #
|
|
85
|
+
# # @return [Set<Integer>]
|
|
86
|
+
# def self.bits_set
|
|
87
|
+
# @bits_set ||= Set.new([32, 64])
|
|
88
|
+
# end
|
|
89
|
+
#
|
|
90
|
+
# @example search an attribute for a restricted set of strings
|
|
91
|
+
# #
|
|
92
|
+
# # Search
|
|
93
|
+
# #
|
|
94
|
+
#
|
|
95
|
+
# search_attribute :endianness,
|
|
96
|
+
# set: :string
|
|
97
|
+
#
|
|
98
|
+
# #
|
|
99
|
+
# # Class Methods
|
|
100
|
+
# #
|
|
101
|
+
#
|
|
102
|
+
# # Return set of allowed values for {#endianness} search.
|
|
103
|
+
# #
|
|
104
|
+
# # @return [Set<String>]
|
|
105
|
+
# def self.endianness_set
|
|
106
|
+
# @endianness_set ||= Set.new(['big', 'litte'])
|
|
107
|
+
# end
|
|
108
|
+
#
|
|
109
|
+
# @example search an attribute by substring (case-insensitve LIKE)
|
|
110
|
+
# search_attribute :description,
|
|
111
|
+
# type: :string
|
|
112
|
+
module Metasploit::Model::Search::Attribute
|
|
113
|
+
extend ActiveSupport::Concern
|
|
2
114
|
|
|
3
|
-
|
|
4
|
-
module Model
|
|
5
|
-
module Search
|
|
6
|
-
# Registers attributes that can be searched. Attributes must be declared to be searchable as a type from
|
|
7
|
-
# {Metasploit::Model::Search::Operator::Attribute::TYPES}. The type of the attribute is used to select a
|
|
8
|
-
# type-specific {Metasploit::Model::Search::Operation}, which will validate the
|
|
9
|
-
# {Metasploit::Model::Search::Operation::Base#value} is of the valid type.
|
|
10
|
-
#
|
|
11
|
-
# # Set attributes
|
|
12
|
-
#
|
|
13
|
-
# Search attributes declared as having an integer set or string set type integer or string set require a
|
|
14
|
-
# `<attribute>_set` method to be defined on the `Class`, which returns the set of allowed values for the search
|
|
15
|
-
# attribute's operation. This method will be called, indirectly by
|
|
16
|
-
# {Metasploit::Model::Search::Operation::Set::Integer}'s and {Metasploit::Model::Search::Operation::Set::String}'s
|
|
17
|
-
# validations.
|
|
18
|
-
#
|
|
19
|
-
# # Help
|
|
20
|
-
#
|
|
21
|
-
# The help for each operator is uses the `I18n` system, so the help for an attribute operator on a given class can
|
|
22
|
-
# added to `config/locales/<lang>.yml`. The scope of the lookup, under the language key is the `Class`'s
|
|
23
|
-
# `i18n_scope`, which is `metasploit.model` if the `Class` includes {Metasploit::Model::Translation} or
|
|
24
|
-
# `active_record` for `ActiveRecord::Base` subclasses. Under the `i18n_scope`, any `Module#ancestor`'s
|
|
25
|
-
# `model_name.i18n_key` can be used to look up the help for an attribute's operator. This allows for super
|
|
26
|
-
# classes or mixins to define the search operator help for subclasses.
|
|
27
|
-
#
|
|
28
|
-
# # config/locales/<lang>.yml
|
|
29
|
-
# <lang>:
|
|
30
|
-
# <Class#i18n_scope>:
|
|
31
|
-
# ancestors:
|
|
32
|
-
# <ancestor.model_name.i18n_key>:
|
|
33
|
-
# search:
|
|
34
|
-
# operator:
|
|
35
|
-
# names:
|
|
36
|
-
# <attribute>:
|
|
37
|
-
# help: "The attribute on the class"
|
|
38
|
-
#
|
|
39
|
-
# # Testing
|
|
40
|
-
#
|
|
41
|
-
# {ClassMethods#search_attribute} calls can be tested with the 'search_attribute' shared example. First, ensure
|
|
42
|
-
# the shared examples from `metasploit-model` are required in your `spec_helper.rb`:
|
|
43
|
-
#
|
|
44
|
-
# # spec/spec_helper.rb
|
|
45
|
-
# support_glob = Metasploit::Model::Engine.root.join('spec', 'support', '**', '*.rb')
|
|
46
|
-
#
|
|
47
|
-
# Dir.glob(support_glob) do |path|
|
|
48
|
-
# require path
|
|
49
|
-
# end
|
|
50
|
-
#
|
|
51
|
-
# In the spec for the `Class` that called `search_attribute`, use the 'search_attribute' shared example by
|
|
52
|
-
# passing that arguments passed to {ClassMethods#search_attribute}.
|
|
53
|
-
#
|
|
54
|
-
# # spec/app/models/my_class_spec.rb
|
|
55
|
-
# require 'spec_helper'
|
|
56
|
-
#
|
|
57
|
-
# describe MyClass do
|
|
58
|
-
# context 'search' do
|
|
59
|
-
# context 'attributes' do
|
|
60
|
-
# it_should_behave_like 'search_attribute',
|
|
61
|
-
# type: {
|
|
62
|
-
# set: :string
|
|
63
|
-
# }
|
|
64
|
-
# end
|
|
65
|
-
# end
|
|
66
|
-
# end
|
|
67
|
-
#
|
|
68
|
-
# @example search an attribute for `true` or `false`
|
|
69
|
-
# search_attribute :flag,
|
|
70
|
-
# type: :boolean
|
|
71
|
-
#
|
|
72
|
-
# @example search an attribute for an integer
|
|
73
|
-
# search_attribute :age,
|
|
74
|
-
# type: :integer
|
|
75
|
-
#
|
|
76
|
-
# @example search an attribute for a restricted set of integers
|
|
77
|
-
# #
|
|
78
|
-
# # Search
|
|
79
|
-
# #
|
|
80
|
-
#
|
|
81
|
-
# search_attribute :bits,
|
|
82
|
-
# set: :integer
|
|
83
|
-
#
|
|
84
|
-
# #
|
|
85
|
-
# # Class Methods
|
|
86
|
-
# #
|
|
87
|
-
#
|
|
88
|
-
# # Return set of allowed values for {#bits} search.
|
|
89
|
-
# #
|
|
90
|
-
# # @return [Set<Integer>]
|
|
91
|
-
# def self.bits_set
|
|
92
|
-
# @bits_set ||= Set.new([32, 64])
|
|
93
|
-
# end
|
|
94
|
-
#
|
|
95
|
-
# @example search an attribute for a restricted set of strings
|
|
96
|
-
# #
|
|
97
|
-
# # Search
|
|
98
|
-
# #
|
|
99
|
-
#
|
|
100
|
-
# search_attribute :endianness,
|
|
101
|
-
# set: :string
|
|
102
|
-
#
|
|
103
|
-
# #
|
|
104
|
-
# # Class Methods
|
|
105
|
-
# #
|
|
106
|
-
#
|
|
107
|
-
# # Return set of allowed values for {#endianness} search.
|
|
108
|
-
# #
|
|
109
|
-
# # @return [Set<String>]
|
|
110
|
-
# def self.endianness_set
|
|
111
|
-
# @endianness_set ||= Set.new(['big', 'litte'])
|
|
112
|
-
# end
|
|
113
|
-
#
|
|
114
|
-
# @example search an attribute by substring (case-insensitve LIKE)
|
|
115
|
-
# search_attribute :description,
|
|
116
|
-
# type: :string
|
|
117
|
-
module Attribute
|
|
118
|
-
extend ActiveSupport::Concern
|
|
115
|
+
include Metasploit::Model::Search::With
|
|
119
116
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
:attribute => attribute,
|
|
137
|
-
:type => options[:type]
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
end
|
|
117
|
+
# Adds {#search_attribute} DSL to make {Metasploit::Model::Search::Operator::Attribute attribute search
|
|
118
|
+
# operators}.
|
|
119
|
+
module ClassMethods
|
|
120
|
+
# {include:Metasploit::Model::Search::Attribute}
|
|
121
|
+
#
|
|
122
|
+
# @param attribute [#to_sym] name of attribute to search.
|
|
123
|
+
# @param options [Hash{Symbol => String}]
|
|
124
|
+
# @option options [Symbol] :type The type of the attribute. Used to determine how to parse the search values
|
|
125
|
+
# and which modifiers are supported.
|
|
126
|
+
# @return (see Metasploit::Model::Search::With::ClassMethods#search_with)
|
|
127
|
+
# @raise [Metasploit::Model::Invalid] unless attribute is present
|
|
128
|
+
# @raise [Metasploit::Model::Invalid] unless :type is present
|
|
129
|
+
def search_attribute(attribute, options={})
|
|
130
|
+
search_with Metasploit::Model::Search::Operator::Attribute,
|
|
131
|
+
:attribute => attribute,
|
|
132
|
+
:type => options[:type]
|
|
141
133
|
end
|
|
142
134
|
end
|
|
143
|
-
end
|
|
135
|
+
end
|