Skip to content

Commit 57e3045

Browse files
committed
Fixes crash when searching modules by target
1 parent 36b13f5 commit 57e3045

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

lib/msf/core/modules/metadata/search.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,17 @@ def is_match(params, module_metadata, regex_cache)
179179
when 'aka'
180180
match = [keyword, search_term] if (module_metadata.notes['AKA'] || []).any? { |aka| aka =~ regex }
181181
when 'author', 'authors'
182-
match = [keyword, search_term] if module_metadata.author.any? { |author| author =~ regex }
182+
match = [keyword, search_term] if module_metadata.author && module_metadata.author.any? { |author| author =~ regex }
183183
when 'arch'
184184
match = [keyword, search_term] if module_metadata.arch =~ regex
185185
when 'cve'
186-
match = [keyword, search_term] if module_metadata.references.any? { |ref| ref =~ /^cve\-/i and ref =~ regex }
186+
match = [keyword, search_term] if module_metadata.references && module_metadata.references.any? { |ref| ref =~ /^cve\-/i and ref =~ regex }
187187
when 'osvdb'
188-
match = [keyword, search_term] if module_metadata.references.any? { |ref| ref =~ /^osvdb\-/i and ref =~ regex }
188+
match = [keyword, search_term] if module_metadata.references && module_metadata.references.any? { |ref| ref =~ /^osvdb\-/i and ref =~ regex }
189189
when 'bid'
190-
match = [keyword, search_term] if module_metadata.references.any? { |ref| ref =~ /^bid\-/i and ref =~ regex }
190+
match = [keyword, search_term] if module_metadata.references && module_metadata.references.any? { |ref| ref =~ /^bid\-/i and ref =~ regex }
191191
when 'edb'
192-
match = [keyword, search_term] if module_metadata.references.any? { |ref| ref =~ /^edb\-/i and ref =~ regex }
192+
match = [keyword, search_term] if module_metadata.references && module_metadata.references.any? { |ref| ref =~ /^edb\-/i and ref =~ regex }
193193
when 'check'
194194
if module_metadata.check
195195
matches_check = %w(true yes).any? { |val| val =~ regex}
@@ -255,9 +255,9 @@ def is_match(params, module_metadata, regex_cache)
255255
when 'ref', 'ref_name'
256256
match = [keyword, search_term] if module_metadata.ref_name =~ regex
257257
when 'reference', 'references'
258-
match = [keyword, search_term] if module_metadata.references.any? { |ref| ref =~ regex }
258+
match = [keyword, search_term] if module_metadata.references && module_metadata.references.any? { |ref| ref =~ regex }
259259
when 'target', 'targets'
260-
match = [keyword, search_term] if module_metadata.targets.any? { |target| target =~ regex }
260+
match = [keyword, search_term] if module_metadata.targets && module_metadata.targets.any? { |target| target =~ regex }
261261
when 'type'
262262
match = [keyword, search_term] if Msf::MODULE_TYPES.any? { |module_type| search_term == module_type and module_metadata.type == module_type }
263263
else

lib/msf/ui/console/command_dispatcher/modules.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def cmd_search_help
380380
print_line
381381
print_line "Keywords:"
382382
{
383-
'adapter' => 'Modules with a matching adater reference name',
383+
'adapter' => 'Modules with a matching adapter reference name',
384384
'aka' => 'Modules with a matching AKA (also-known-as) name',
385385
'author' => 'Modules written by this author',
386386
'arch' => 'Modules affecting this architecture',

spec/lib/msf/core/modules/metadata/search_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def get_metadata
5757
it { expect(described_class.parse_search_string("session_type:Meterpreter ")).to eq({"session_type"=>[["meterpreter"], []]}) }
5858
it { expect(described_class.parse_search_string("session_type:shell ")).to eq({"session_type"=>[["shell"], []]}) }
5959
it { expect(described_class.parse_search_string("action:forge_golden ")).to eq({"action"=>[["forge_golden"], []]}) }
60+
it { expect(described_class.parse_search_string("targets:windows ")).to eq({"targets"=>[["windows"], []]}) }
61+
it { expect(described_class.parse_search_string("targets:osx ")).to eq({"targets"=>[["osx"], []]}) }
62+
it { expect(described_class.parse_search_string("targets:ubuntu ")).to eq({"targets"=>[["ubuntu"], []]}) }
6063
end
6164

6265
describe '#find' do
@@ -233,6 +236,30 @@ def inverse_query_terms(search_string)
233236
it_should_behave_like 'search_filter', accept: accept, reject: reject
234237
end
235238

239+
context 'on a module with a #targets of ["windows"]' do
240+
let(:opts) { { 'targets' => ['windows'] } }
241+
accept = %w[targets:windows]
242+
reject = %w[targets:unrelated]
243+
244+
it_should_behave_like 'search_filter', accept: accept, reject: reject
245+
end
246+
247+
context 'on a module with a #targets of ["osx"]' do
248+
let(:opts) { { 'targets' => ['osx'] } }
249+
accept = %w[targets:osx]
250+
reject = %w[targets:unrelated]
251+
252+
it_should_behave_like 'search_filter', accept: accept, reject: reject
253+
end
254+
255+
context 'on a module with a #targets of ["ubuntu"]' do
256+
let(:opts) { { 'targets' => ['ubuntu'] } }
257+
accept = %w[targets:ubuntu]
258+
reject = %w[targets:unrelated]
259+
260+
it_should_behave_like 'search_filter', accept: accept, reject: reject
261+
end
262+
236263
context 'on a module that supports the osx platform' do
237264
let(:opts) { ({ 'platform' => 'osx' }) }
238265
accept = %w(platform:osx os:osx)

0 commit comments

Comments
 (0)