From 766b5919881f5a21d547234069e8c5144df029ed Mon Sep 17 00:00:00 2001 From: HD Moore Date: Sun, 30 May 2010 13:49:28 +0000 Subject: [PATCH] Add -o to db_hosts, write the list of hosts to a file git-svn-id: file:///home/svn/framework3/trunk@9381 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/ui/console/command_dispatcher/db.rb | 30 ++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/msf/ui/console/command_dispatcher/db.rb b/lib/msf/ui/console/command_dispatcher/db.rb index 36e159e4f2..616c87a162 100644 --- a/lib/msf/ui/console/command_dispatcher/db.rb +++ b/lib/msf/ui/console/command_dispatcher/db.rb @@ -149,6 +149,7 @@ class Db onlyup = false host_search = nil col_search = nil + output = nil default_columns = ::Msf::DBManager::Host.column_names.sort default_columns.delete_if {|v| (v[-2,2] == "id")} while (arg = args.shift) @@ -175,13 +176,16 @@ class Db return end host_search = hostlist.strip().split(",") + when '-o' + output = args.shift when '-h','--help' - print_line "Usage: db_hosts [-h|--help] [-u|--up] [-a ] [-c ]" + print_line "Usage: db_hosts [-h|--help] [-u|--up] [-a ] [-c ] [-o output-file ]" print_line print_line " -a Search for a list of addresses" print_line " -c Only show the given columns" print_line " -h,--help Show this help information" print_line " -u,--up Only show hosts which are up" + print_line " -o Write out a file, one address per line" print_line print_line "Available columns: #{default_columns.join(", ")}" print_line @@ -189,6 +193,9 @@ class Db end end + ofd = nil + ofd = ::File.open(output, "w") if output + col_names = default_columns if col_search col_names.delete_if {|v| not col_search.include?(v)} @@ -198,14 +205,25 @@ class Db 'Columns' => col_names + ["Svcs", "Vulns", "Workspace"], }) framework.db.hosts(framework.db.workspace, onlyup, host_search).each do |host| - columns = col_names.map { |n| host.attributes[n] || "" } - columns += [host.services.length, host.vulns.length, host.workspace.name] - tbl << columns + if ofd + ofd.puts host.address + else + columns = col_names.map { |n| host.attributes[n] || "" } + columns += [host.services.length, host.vulns.length, host.workspace.name] + tbl << columns + end + end + + if ofd + print_status("Wrote hosts to #{output}") + ofd.close + else + print_line + print_line tbl.to_s if not ofd end - print_line - print_line tbl.to_s end + def cmd_db_services(*args) return unless active? onlyup = false