Skip to content

Commit afcbaff

Browse files
committed
Revert "add -R capability like hosts -R"
Pulling out the set_rhosts_from_addrs -- that's not required for grep-like functionality, and adding this method to the global namespace is undesirable. This reverts commit 52596ae.
1 parent 91e3f4c commit afcbaff

File tree

3 files changed

+41
-65
lines changed

3 files changed

+41
-65
lines changed

lib/msf/core/set_rhosts.rb

Lines changed: 0 additions & 36 deletions
This file was deleted.

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

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module CommandDispatcher
2020
class Core
2121

2222
include Msf::Ui::Console::CommandDispatcher
23-
require 'msf/core/set_rhosts'
2423

2524
# Session command options
2625
@@sessions_opts = Rex::Parser::Arguments.new(
@@ -75,8 +74,7 @@ class Core
7574
"-B" => [ true, "Show arg lines of output Before a match." ],
7675
"-s" => [ true, "Skip arg lines of output before attempting match."],
7776
"-k" => [ true, "Keep (include) arg lines at start of output." ],
78-
"-c" => [ false, "Only print a count of matching lines." ],
79-
"-R" => [ false, "Set RHOSTS with the results, can only be used when command output has 'addresses' as the first column" ])
77+
"-c" => [ false, "Only print a count of matching lines." ])
8078

8179
@@search_opts = Rex::Parser::Arguments.new(
8280
"-h" => [ false, "Help banner." ])
@@ -2518,11 +2516,6 @@ def cmd_grep(*args)
25182516
# skip arg number of lines at the top of the output, useful for avoiding undesirable matches
25192517
output_mods[:skip] = val.to_i
25202518
args.shift(2)
2521-
when "-R"
2522-
output_mods[:set_rhosts] = true
2523-
args.shift
2524-
output_mods[:keep] = 6 unless output_mods[:keep].to_i > 6 # we need the column headers
2525-
rhosts = []
25262519
end
25272520
end
25282521
# after deleting parsed options, the only args left should be the pattern, the cmd to run, and cmd args
@@ -2592,25 +2585,7 @@ def temp_output.write(msg = '')
25922585

25932586
# now control output based on remaining output_mods such as :count
25942587
return print_status(count.to_s) if output_mods[:count]
2595-
2596-
if output_mods[:set_rhosts]
2597-
# we don't use the db to confirm these hosts because we want to keep grep independent of db status so we
2598-
# require the first column to be the addresses otherwise there's no good way to parse the table.to_s output
2599-
col_names_row_index = nil
2600-
our_lines.each_with_index do |line,idx|
2601-
if line =~ /^address/ # this is assumed to be the line w/the column names
2602-
col_names_row_index = idx
2603-
break
2604-
end
2605-
end
2606-
rhosts_row_start = col_names_row_index + 1
2607-
rhosts_row_start += 1 if our_lines[rhosts_row_start] =~ /^-+/ # skip the "-----" separator if present
2608-
row_of_interest = our_lines.slice(rhosts_row_start..-1)
2609-
rhosts = row_of_interest.map {|row| row.split(/\s/).first}
2610-
set_rhosts_from_addrs(rhosts)
2611-
else
2612-
our_lines.each {|line| print line}
2613-
end
2588+
our_lines.each {|line| print line}
26142589
end
26152590

26162591
#

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module CommandDispatcher
1111
class Db
1212

1313
require 'tempfile'
14-
require 'msf/core/set_rhosts'
1514

1615
include Msf::Ui::Console::CommandDispatcher
1716

@@ -1528,7 +1527,7 @@ def cmd_db_rebuild_cache
15281527
print_error("The database is not connected")
15291528
return
15301529
end
1531-
1530+
15321531
print_status("Purging and rebuilding the module cache in the background...")
15331532
framework.threads.spawn("ModuleCacheRebuild", true) do
15341533
framework.db.purge_all_module_details
@@ -1543,6 +1542,44 @@ def cmd_db_rebuild_cache_help
15431542
print_line
15441543
end
15451544

1545+
#
1546+
# Set RHOSTS in the +active_module+'s (or global if none) datastore from an array of addresses
1547+
#
1548+
# This stores all the addresses to a temporary file and utilizes the
1549+
# <pre>file:/tmp/filename</pre> syntax to confer the addrs. +rhosts+
1550+
# should be an Array. NOTE: the temporary file is *not* deleted
1551+
# automatically.
1552+
#
1553+
def set_rhosts_from_addrs(rhosts)
1554+
if rhosts.empty?
1555+
print_status "The list is empty, cowardly refusing to set RHOSTS"
1556+
return
1557+
end
1558+
if active_module
1559+
mydatastore = active_module.datastore
1560+
else
1561+
# if there is no module in use set the list to the global variable
1562+
mydatastore = self.framework.datastore
1563+
end
1564+
1565+
if rhosts.length > 5
1566+
# Lots of hosts makes 'show options' wrap which is difficult to
1567+
# read, store to a temp file
1568+
rhosts_file = Rex::Quickfile.new("msf-db-rhosts-")
1569+
mydatastore['RHOSTS'] = 'file:'+rhosts_file.path
1570+
# create the output file and assign it to the RHOSTS variable
1571+
rhosts_file.write(rhosts.join("\n")+"\n")
1572+
rhosts_file.close
1573+
else
1574+
# For short lists, just set it directly
1575+
mydatastore['RHOSTS'] = rhosts.join(" ")
1576+
end
1577+
1578+
print_line "RHOSTS => #{mydatastore['RHOSTS']}"
1579+
print_line
1580+
end
1581+
1582+
15461583
def db_find_tools(tools)
15471584
found = true
15481585
missed = []

0 commit comments

Comments
 (0)