add -a to db_hosts to replace db_add_hots, see #4963

git-svn-id: file:///home/svn/framework3/trunk@13218 4d416f70-5f16-0410-b530-b9f4589650da
unstable
James Lee 2011-07-19 06:09:10 +00:00
parent ad53b4f115
commit 7b7b9670d2
1 changed files with 57 additions and 41 deletions

View File

@ -189,6 +189,7 @@ class Db
host_search = nil
set_rhosts = false
hostlist = []
mode = :search
output = nil
default_columns = ::Msf::DBManager::Host.column_names.sort
@ -199,6 +200,8 @@ class Db
default_columns.delete_if {|v| (v[-2,2] == "id")}
while (arg = args.shift)
case arg
when '-a','--add'
mode = :add
when '-c'
list = args.shift
if(!list)
@ -225,6 +228,7 @@ class Db
print_line "Usage: db_hosts [ options ] [addr1 addr2 ...]"
print_line
print_line "OPTIONS:"
print_line " -a,--add Add the hosts instead of searching"
print_line " -c <col1,col2> Only show the given columns (see list below)"
print_line " -h,--help Show this help information"
print_line " -u,--up Only show hosts which are up"
@ -244,11 +248,24 @@ class Db
# all.
host_search = (hostlist.empty? ? nil : hostlist)
col_names = default_columns + virtual_columns
if col_search
col_names = col_search
else
col_names = default_columns + virtual_columns
end
case mode
when :add
hostlist.each do |address|
host = framework.db.find_or_create_host(:host => address)
print_status("Time: #{host.created_at} Host: host=#{host.address}")
if set_rhosts
# only unique addresses
rhosts << host.address unless rhosts.include?(host.address)
end
end
when :search
tbl = Rex::Ui::Text::Table.new(
{
'Header' => "Hosts",
@ -257,15 +274,14 @@ class Db
framework.db.hosts(framework.db.workspace, onlyup, host_search).each do |host|
columns = col_names.map do |n|
# Deal with the special cases
if virtual_columns.include?(n)
case n
when "svcs"
host.services.length
when "vulns"
host.vulns.length
when "workspace"
host.workspace.name
when "svcs"; host.services.length
when "vulns"; host.vulns.length
when "workspace"; host.workspace.name
end
# Otherwise, it's just an attribute
else
host.attributes[n] || ""
end
@ -277,7 +293,6 @@ class Db
rhosts << host.address unless rhosts.include?(host.address)
end
end
if output
print_status("Wrote hosts to #{output}")
::File.open(output, "wb") { |ofd|
@ -287,6 +302,7 @@ class Db
print_line
print_line tbl.to_s
end
end
# Finally, handle the case where the user wants the resulting list
# of hosts to go into RHOSTS.