Land #4960, hosts -i, -n, and -m support
This commit is contained in:
commit
cf645772b6
|
@ -219,6 +219,36 @@ class Db
|
|||
cmd_hosts("-h")
|
||||
end
|
||||
|
||||
def change_host_info(rws, data)
|
||||
rws.each do |rw|
|
||||
rw.each do |ip|
|
||||
id = framework.db.get_host(:address => ip).id
|
||||
framework.db.hosts.update(id, :info => data)
|
||||
framework.db.report_note(:host => ip, :type => 'host.info', :data => data)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def change_host_name(rws, data)
|
||||
rws.each do |rw|
|
||||
rw.each do |ip|
|
||||
id = framework.db.get_host(:address => ip).id
|
||||
framework.db.hosts.update(id, :name => data)
|
||||
framework.db.report_note(:host => ip, :type => 'host.name', :data => data)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def change_host_comment(rws, data)
|
||||
rws.each do |rw|
|
||||
rw.each do |ip|
|
||||
id = framework.db.get_host(:address => ip).id
|
||||
framework.db.hosts.update(id, :comments => data)
|
||||
framework.db.report_note(:host => ip, :type => 'host.comments', :data => data)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def cmd_hosts(*args)
|
||||
return unless active?
|
||||
::ActiveRecord::Base.connection_pool.with_connection {
|
||||
|
@ -266,7 +296,15 @@ class Db
|
|||
set_rhosts = true
|
||||
when '-S', '--search'
|
||||
search_term = /#{args.shift}/nmi
|
||||
|
||||
when '-i', '--info'
|
||||
mode = :new_info
|
||||
info_data = args.shift
|
||||
when '-n', '--name'
|
||||
mode = :new_name
|
||||
name_data = args.shift
|
||||
when '-m', '--comment'
|
||||
mode = :new_comment
|
||||
comment_data = args.shift
|
||||
when '-h','--help'
|
||||
print_line "Usage: hosts [ options ] [addr1 addr2 ...]"
|
||||
print_line
|
||||
|
@ -279,6 +317,9 @@ class Db
|
|||
print_line " -o <file> Send output to a file in csv format"
|
||||
print_line " -R,--rhosts Set RHOSTS from the results of the search"
|
||||
print_line " -S,--search Search string to filter by"
|
||||
print_line " -i,--info Change the info of a host"
|
||||
print_line " -n,--name Change the name of a host"
|
||||
print_line " -m,--comment Change the comment of a host"
|
||||
print_line
|
||||
print_line "Available columns: #{default_columns.join(", ")}"
|
||||
print_line
|
||||
|
@ -317,6 +358,18 @@ class Db
|
|||
# Sentinal value meaning all
|
||||
host_ranges.push(nil) if host_ranges.empty?
|
||||
|
||||
case mode
|
||||
when :new_info
|
||||
change_host_info(host_ranges, info_data)
|
||||
return
|
||||
when :new_name
|
||||
change_host_name(host_ranges, name_data)
|
||||
return
|
||||
when :new_comment
|
||||
change_host_comment(host_ranges, comment_data)
|
||||
return
|
||||
end
|
||||
|
||||
each_host_range_chunk(host_ranges) do |host_search|
|
||||
framework.db.hosts(framework.db.workspace, onlyup, host_search).each do |host|
|
||||
if search_term
|
||||
|
|
|
@ -391,6 +391,9 @@ describe Msf::Ui::Console::CommandDispatcher::Db do
|
|||
" -o <file> Send output to a file in csv format",
|
||||
" -R,--rhosts Set RHOSTS from the results of the search",
|
||||
" -S,--search Search string to filter by",
|
||||
" -i,--info Change the info of a host",
|
||||
" -n,--name Change the name of a host",
|
||||
" -m,--comment Change the comment of a host",
|
||||
"Available columns: address, arch, comm, comments, created_at, cred_count, detected_arch, exploit_attempt_count, host_detail_count, info, mac, name, note_count, os_flavor, os_lang, os_name, os_sp, purpose, scope, service_count, state, updated_at, virtual_host, vuln_count"
|
||||
]
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue