Land #9954, Add search filtering to the CSV output option

4.x
Brent Cook 2018-04-30 17:01:34 -05:00 committed by Metasploit
parent 37767e9d4c
commit f4d9788454
No known key found for this signature in database
GPG Key ID: CDFB5FA52007B954
1 changed files with 29 additions and 19 deletions

View File

@ -19,8 +19,9 @@ module Msf
CMD_USE_TIMEOUT = 3 CMD_USE_TIMEOUT = 3
@@search_opts = Rex::Parser::Arguments.new( @@search_opts = Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner."], "-h" => [ false, "Help banner"],
"-S" => [ true, "Row search filter."], "-o" => [ true, "Send output to a file in csv format"],
"-S" => [ true, "Search string for row filter"],
) )
def commands def commands
@ -410,7 +411,12 @@ module Msf
end end
def cmd_search_help def cmd_search_help
print_line "Usage: search <keywords>" print_line "Usage: search [ options ] <keywords>"
print_line
print_line "OPTIONS:"
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 print_line
print_line "Keywords:" print_line "Keywords:"
{ {
@ -444,24 +450,27 @@ module Msf
match = '' match = ''
search_term = nil search_term = nil
output_file = nil
@@search_opts.parse(args) { |opt, idx, val| @@search_opts.parse(args) { |opt, idx, val|
case opt case opt
when "-t" when "-S"
print_error("Deprecated option. Use type:#{val} instead")
cmd_search_help
return
when "-S", "--search"
search_term = val search_term = val
when "-h" when "-h"
cmd_search_help cmd_search_help
return return
when "-S" when '-o'
search_term = val output_file = val
else else
match += val + " " match += val + " "
end end
} }
if match.empty? && search_term.nil?
print_error("Keywords or search argument required\n")
cmd_search_help
return
end
# Display the table of matches # Display the table of matches
tbl = generate_module_table("Matching Modules", search_term) tbl = generate_module_table("Matching Modules", search_term)
framework.search(match, logger: self).each do |m| framework.search(match, logger: self).each do |m|
@ -472,8 +481,16 @@ module Msf
m.name m.name
] ]
end end
if output_file
print_status("Wrote search results to #{output_file}")
::File.open(output_file, "wb") { |ofd|
ofd.write(tbl.to_csv)
}
else
print_line(tbl.to_s) print_line(tbl.to_s)
end end
end
# #
# Tab completion for the search command # Tab completion for the search command
@ -487,13 +504,6 @@ module Msf
return @@search_opts.fmt.keys return @@search_opts.fmt.keys
end end
case (words[-1])
when "-r"
return RankingName.sort.map{|r| r[1]}
when "-t"
return %w{auxiliary encoder exploit nop payload post}
end
[] []
end end