Skip to content

Commit

Permalink
Land #11652, search -u to use first search result
Browse files Browse the repository at this point in the history
  • Loading branch information
wvu committed Apr 1, 2019
2 parents d3f3029 + e577b8f commit 36deece
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/msf/ui/console/command_dispatcher/modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Modules
"-h" => [ false, "Help banner"],
"-o" => [ true, "Send output to a file in csv format"],
"-S" => [ true, "Search string for row filter"],
"-u" => [ false, "Use module if there is one result"]
)

def commands
Expand Down Expand Up @@ -323,6 +324,7 @@ def cmd_search_help
print_line " -h Show this help information"
print_line " -o <file> Send output to a file in csv format"
print_line " -S <string> Search string for row filter"
print_line " -u Use module if there is one result"
print_line
print_line "Keywords:"
{
Expand Down Expand Up @@ -366,6 +368,7 @@ def cmd_search(*args)
end

match = ''
use = false
search_term = nil
output_file = nil
@@search_opts.parse(args) { |opt, idx, val|
Expand All @@ -377,6 +380,8 @@ def cmd_search(*args)
return
when '-o'
output_file = val
when "-u"
use = true
else
match += val + " "
end
Expand All @@ -391,16 +396,23 @@ def cmd_search(*args)
# Display the table of matches
tbl = generate_module_table("Matching Modules", search_term)
search_params = parse_search_string(match)
count = 0
begin
Msf::Modules::Metadata::Cache.instance.find(search_params).each do |m|
modules = Msf::Modules::Metadata::Cache.instance.find(search_params)
modules.each do |m|
tbl << [
count += 1,
m.full_name,
m.disclosure_date.nil? ? '' : m.disclosure_date.strftime("%Y-%m-%d"),
RankingName[m.rank].to_s,
m.check ? 'Yes' : 'No',
m.name
]
end
if modules.length == 1 && use
used_module = modules.first.full_name
cmd_use(used_module)
end
rescue ArgumentError
print_error("Invalid argument(s)\n")
cmd_search_help
Expand All @@ -413,6 +425,7 @@ def cmd_search(*args)
}
else
print_line(tbl.to_s)
print_status("Using #{used_module}") if used_module
end
end

Expand Down Expand Up @@ -485,7 +498,7 @@ def cmd_show(*args)
cmd_show_help
return
end

mod = self.active_module

args.each { |type|
Expand Down Expand Up @@ -1137,6 +1150,7 @@ def show_plugins # :nodoc:

def show_module_set(type, module_set, regex = nil, minrank = nil, opts = nil) # :nodoc:
tbl = generate_module_table(type)
count = 0
module_set.sort.each { |refname, mod|
o = nil

Expand Down Expand Up @@ -1168,6 +1182,7 @@ def show_module_set(type, module_set, regex = nil, minrank = nil, opts = nil) #
end
if (opts == nil or show == true)
tbl << [
count += 1,
refname,
o.disclosure_date.nil? ? "" : o.disclosure_date.strftime("%Y-%m-%d"),
o.rank_to_s,
Expand All @@ -1188,7 +1203,7 @@ def generate_module_table(type, search_term = nil) # :nodoc:
'Header' => type,
'Prefix' => "\n",
'Postfix' => "\n",
'Columns' => [ 'Name', 'Disclosure Date', 'Rank', 'Check', 'Description' ],
'Columns' => [ '#', 'Name', 'Disclosure Date', 'Rank', 'Check', 'Description' ],
'SearchTerm' => search_term
)
end
Expand Down

1 comment on commit 36deece

@wvu
Copy link
Contributor Author

@wvu wvu commented on 36deece Apr 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/first/only/, oops.

Please sign in to comment.