@@ -401,51 +401,58 @@ def cmd_search(*args)
401
401
end
402
402
}
403
403
404
+ matching_modules = [ ]
405
+
406
+ # Check if the database is usable
407
+ use_db = true
404
408
if framework . db
405
- if framework . db . migrated && framework . db . modules_cached
406
- search_modules_sql ( match , search_term )
407
- return
408
- else
409
+ if !( framework . db . migrated && framework . db . modules_cached )
409
410
print_warning ( "Module database cache not built yet, using slow search" )
411
+ use_db = false
410
412
end
411
413
else
412
414
print_warning ( "Database not connected, using slow search" )
415
+ use_db = false
413
416
end
414
417
415
- tbl = generate_module_table ( "Matching Modules" , search_term )
416
- [
417
- framework . exploits ,
418
- framework . auxiliary ,
419
- framework . post ,
420
- framework . payloads ,
421
- framework . nops ,
422
- framework . encoders
423
- ] . each do |mset |
424
- mset . each do |m |
425
- o = mset . create ( m [ 0 ] ) rescue nil
426
-
427
- # Expected if modules are loaded without the right pre-requirements
428
- next if not o
429
-
430
- if not o . search_filter ( match )
431
- tbl << [ o . fullname , o . disclosure_date . nil? ? "" : o . disclosure_date . strftime ( DISCLOSURE_DATE_FORMAT ) , o . rank_to_s , o . name ]
418
+ # Do the actual search
419
+ if use_db
420
+ framework . db . search_modules ( match ) . each do |o |
421
+ matching_modules << o
422
+ end
423
+ else
424
+ [
425
+ framework . exploits ,
426
+ framework . auxiliary ,
427
+ framework . post ,
428
+ framework . payloads ,
429
+ framework . nops ,
430
+ framework . encoders
431
+ ] . each do |mset |
432
+ mset . each do |m |
433
+ begin
434
+ o = mset . create ( m [ 0 ] )
435
+ if o && !o . search_filter ( match )
436
+ matching_modules << o
437
+ end
438
+ rescue
439
+ end
432
440
end
433
441
end
434
442
end
435
- print_line ( tbl . to_s )
436
443
437
- end
438
-
439
- # Prints table of modules matching the search_string.
440
- #
441
- # @param (see Msf::DBManager#search_modules)
442
- # @return [void]
443
- def search_modules_sql ( search_string , search_term = nil )
444
+ # Display the table of matches
444
445
tbl = generate_module_table ( "Matching Modules" , search_term )
445
- framework . db . search_modules ( search_string ) . each do |o |
446
- tbl << [ o . fullname , o . disclosure_date . nil? ? "" : o . disclosure_date . strftime ( DISCLOSURE_DATE_FORMAT ) , RankingName [ o . rank ] . to_s , o . name ]
446
+ matching_modules . each do |o |
447
+ tbl << [
448
+ o . fullname ,
449
+ o . disclosure_date . nil? ? "" : o . disclosure_date . strftime ( DISCLOSURE_DATE_FORMAT ) ,
450
+ RankingName [ o . rank ] . to_s ,
451
+ o . name
452
+ ]
447
453
end
448
454
print_line ( tbl . to_s )
455
+
449
456
end
450
457
451
458
#
0 commit comments