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
unstable
HD Moore 2010-05-30 13:49:28 +00:00
parent 845407a356
commit 766b591988
1 changed files with 24 additions and 6 deletions

View File

@ -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 <addr1,addr2>] [-c <column1,column2>]"
print_line "Usage: db_hosts [-h|--help] [-u|--up] [-a <addr1,addr2>] [-c <column1,column2>] [-o output-file ]"
print_line
print_line " -a <addr1,addr2> Search for a list of addresses"
print_line " -c <col1,col2> 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 <file> 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