Skip to content

Commit cf64577

Browse files
committed
Land rapid7#4960, hosts -i, -n, and -m support
2 parents 7eec88c + 38dbd18 commit cf64577

File tree

2 files changed

+57
-1
lines changed
  • lib/msf/ui/console/command_dispatcher
  • spec/lib/msf/ui/console/command_dispatcher

2 files changed

+57
-1
lines changed

lib/msf/ui/console/command_dispatcher/db.rb

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,36 @@ def cmd_hosts_help
219219
cmd_hosts("-h")
220220
end
221221

222+
def change_host_info(rws, data)
223+
rws.each do |rw|
224+
rw.each do |ip|
225+
id = framework.db.get_host(:address => ip).id
226+
framework.db.hosts.update(id, :info => data)
227+
framework.db.report_note(:host => ip, :type => 'host.info', :data => data)
228+
end
229+
end
230+
end
231+
232+
def change_host_name(rws, data)
233+
rws.each do |rw|
234+
rw.each do |ip|
235+
id = framework.db.get_host(:address => ip).id
236+
framework.db.hosts.update(id, :name => data)
237+
framework.db.report_note(:host => ip, :type => 'host.name', :data => data)
238+
end
239+
end
240+
end
241+
242+
def change_host_comment(rws, data)
243+
rws.each do |rw|
244+
rw.each do |ip|
245+
id = framework.db.get_host(:address => ip).id
246+
framework.db.hosts.update(id, :comments => data)
247+
framework.db.report_note(:host => ip, :type => 'host.comments', :data => data)
248+
end
249+
end
250+
end
251+
222252
def cmd_hosts(*args)
223253
return unless active?
224254
::ActiveRecord::Base.connection_pool.with_connection {
@@ -266,7 +296,15 @@ def cmd_hosts(*args)
266296
set_rhosts = true
267297
when '-S', '--search'
268298
search_term = /#{args.shift}/nmi
269-
299+
when '-i', '--info'
300+
mode = :new_info
301+
info_data = args.shift
302+
when '-n', '--name'
303+
mode = :new_name
304+
name_data = args.shift
305+
when '-m', '--comment'
306+
mode = :new_comment
307+
comment_data = args.shift
270308
when '-h','--help'
271309
print_line "Usage: hosts [ options ] [addr1 addr2 ...]"
272310
print_line
@@ -279,6 +317,9 @@ def cmd_hosts(*args)
279317
print_line " -o <file> Send output to a file in csv format"
280318
print_line " -R,--rhosts Set RHOSTS from the results of the search"
281319
print_line " -S,--search Search string to filter by"
320+
print_line " -i,--info Change the info of a host"
321+
print_line " -n,--name Change the name of a host"
322+
print_line " -m,--comment Change the comment of a host"
282323
print_line
283324
print_line "Available columns: #{default_columns.join(", ")}"
284325
print_line
@@ -317,6 +358,18 @@ def cmd_hosts(*args)
317358
# Sentinal value meaning all
318359
host_ranges.push(nil) if host_ranges.empty?
319360

361+
case mode
362+
when :new_info
363+
change_host_info(host_ranges, info_data)
364+
return
365+
when :new_name
366+
change_host_name(host_ranges, name_data)
367+
return
368+
when :new_comment
369+
change_host_comment(host_ranges, comment_data)
370+
return
371+
end
372+
320373
each_host_range_chunk(host_ranges) do |host_search|
321374
framework.db.hosts(framework.db.workspace, onlyup, host_search).each do |host|
322375
if search_term

spec/lib/msf/ui/console/command_dispatcher/db_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@
391391
" -o <file> Send output to a file in csv format",
392392
" -R,--rhosts Set RHOSTS from the results of the search",
393393
" -S,--search Search string to filter by",
394+
" -i,--info Change the info of a host",
395+
" -n,--name Change the name of a host",
396+
" -m,--comment Change the comment of a host",
394397
"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"
395398
]
396399
end

0 commit comments

Comments
 (0)