Skip to content

Commit 6bd4306

Browse files
committed
Merge pull request rapid7#1119 from bug/fix-module-search
[FIXRM rapid7#7561] [SEERM rapid7#7553]
2 parents 1ce1cdf + 30d7de3 commit 6bd4306

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

lib/msf/core/db_manager.rb

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def connect(opts={})
196196

197197
# Prefer the config file's pool setting
198198
nopts['pool'] ||= 75
199-
199+
200200
# Prefer the config file's wait_timeout setting too
201201
nopts['wait_timeout'] ||= 300
202202

@@ -342,11 +342,13 @@ def update_all_module_details
342342
return if not self.migrated
343343
return if self.modules_caching
344344

345+
self.framework.cache_thread = Thread.current
346+
345347
self.modules_cached = false
346348
self.modules_caching = true
347349

348350
::ActiveRecord::Base.connection_pool.with_connection {
349-
351+
350352
refresh = []
351353
skipped = []
352354

@@ -394,6 +396,9 @@ def update_all_module_details
394396
end
395397
end
396398

399+
self.framework.cache_initialized = true
400+
self.framework.cache_thread = nil
401+
397402
self.modules_cached = true
398403
self.modules_caching = false
399404

@@ -460,16 +465,16 @@ def module_to_details_hash(m)
460465

461466
res[:description] = m.description.to_s.strip
462467

463-
m.arch.map{ |x|
464-
bits << [ :arch, { :name => x.to_s } ]
468+
m.arch.map{ |x|
469+
bits << [ :arch, { :name => x.to_s } ]
465470
}
466471

467-
m.platform.platforms.map{ |x|
468-
bits << [ :platform, { :name => x.to_s.split('::').last.downcase } ]
472+
m.platform.platforms.map{ |x|
473+
bits << [ :platform, { :name => x.to_s.split('::').last.downcase } ]
469474
}
470475

471-
m.author.map{|x|
472-
bits << [ :author, { :name => x.to_s } ]
476+
m.author.map{|x|
477+
bits << [ :author, { :name => x.to_s } ]
473478
}
474479

475480
m.references.map do |r|
@@ -500,14 +505,14 @@ def module_to_details_hash(m)
500505
# Some modules are a combination, which means they are actually aggressive
501506
res[:stance] = m.stance.to_s.index("aggressive") ? "aggressive" : "passive"
502507

503-
508+
504509
m.class.mixins.each do |x|
505510
bits << [ :mixin, { :name => x.to_s } ]
506511
end
507512
end
508513

509514
if(m.type == "auxiliary")
510-
515+
511516
m.actions.each_index do |i|
512517
bits << [ :action, { :name => m.actions[i].name.to_s } ]
513518
end
@@ -523,9 +528,9 @@ def module_to_details_hash(m)
523528

524529
res
525530
end
526-
527-
528-
531+
532+
533+
529534
#
530535
# This provides a standard set of search filters for every module.
531536
# The search terms are in the form of:
@@ -562,7 +567,7 @@ def search_modules(search_string, inclusive=false)
562567
end
563568

564569
::ActiveRecord::Base.connection_pool.with_connection {
565-
570+
566571
where_q = []
567572
where_v = []
568573

@@ -572,12 +577,12 @@ def search_modules(search_string, inclusive=false)
572577
case kt
573578
when 'text'
574579
xv = "%#{kv}%"
575-
where_q << ' ( ' +
580+
where_q << ' ( ' +
576581
'module_details.fullname ILIKE ? OR module_details.name ILIKE ? OR module_details.description ILIKE ? OR ' +
577582
'module_authors.name ILIKE ? OR module_actions.name ILIKE ? OR module_archs.name ILIKE ? OR ' +
578-
'module_targets.name ILIKE ? OR module_platforms.name ILIKE ? ' +
583+
'module_targets.name ILIKE ? OR module_platforms.name ILIKE ? OR module_refs.name ILIKE ?' +
579584
') '
580-
where_v << [ xv, xv, xv, xv, xv, xv, xv, xv ]
585+
where_v << [ xv, xv, xv, xv, xv, xv, xv, xv, xv ]
581586
when 'name'
582587
xv = "%#{kv}%"
583588
where_q << ' ( module_details.fullname ILIKE ? OR module_details.name ILIKE ? ) '
@@ -594,7 +599,7 @@ def search_modules(search_string, inclusive=false)
594599
# TODO
595600
when 'type'
596601
where_q << ' ( module_details.mtype = ? ) '
597-
where_v << [ kv ]
602+
where_v << [ kv ]
598603
when 'app'
599604
where_q << ' ( module_details.stance = ? )'
600605
where_v << [ ( kv == "client") ? "passive" : "active" ]
@@ -604,11 +609,11 @@ def search_modules(search_string, inclusive=false)
604609
when 'cve','bid','osvdb','edb'
605610
where_q << ' ( module_refs.name = ? )'
606611
where_v << [ kt.upcase + '-' + kv ]
607-
612+
608613
end
609614
end
610615
end
611-
616+
612617
qry = Mdm::ModuleDetail.select("DISTINCT(module_details.*)").
613618
joins(
614619
"LEFT OUTER JOIN module_authors ON module_details.id = module_authors.module_detail_id " +
@@ -629,4 +634,3 @@ def search_modules(search_string, inclusive=false)
629634

630635
end
631636
end
632-

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,13 +1335,11 @@ def cmd_search(*args)
13351335
}
13361336

13371337
if framework.db and framework.db.migrated and framework.db.modules_cached
1338-
sql_results = search_modules_sql(match)
1339-
return sql_results if sql_results # Patches around #7553
1340-
else
1341-
print_warning("Database not connected or cache not built.")
1338+
search_modules_sql(match)
1339+
return
13421340
end
13431341

1344-
print_warning("Falling back to slow search.")
1342+
print_warning("Database not connected or cache not built, using slow search")
13451343

13461344
tbl = generate_module_table("Matching Modules")
13471345
[

lib/msf/ui/console/driver.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,7 @@ def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {
228228

229229
# Rebuild the module cache in a background thread
230230
self.framework.threads.spawn("ModuleCacheRebuild", true) do
231-
self.framework.cache_thread = Thread.current
232231
self.framework.modules.refresh_cache_from_module_files
233-
self.framework.cache_initialized = true
234-
self.framework.cache_thread = nil
235232
end
236233
end
237234

0 commit comments

Comments
 (0)