Add search cmd option to write CSV output file

GSoC/Meterpreter_Web_Console
Matthew Kienow 2018-04-29 23:08:24 -04:00
parent 8164379f7a
commit ca7b10af39
No known key found for this signature in database
GPG Key ID: 40787F8B1EAC6E41
1 changed files with 21 additions and 4 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,6 +450,7 @@ 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 "-t"
@ -457,6 +464,8 @@ module Msf
return return
when "-S" when "-S"
search_term = val search_term = val
when '-o'
output_file = val
else else
match += val + " " match += val + " "
end end
@ -472,7 +481,15 @@ module Msf
m.name m.name
] ]
end end
print_line(tbl.to_s)
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)
end
end end
# #