2014-07-24 20:04:00 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2014-07-24 20:04:00 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
include Msf::Exploit::Remote::Tcp
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
|
2015-10-12 20:37:59 +00:00
|
|
|
RSYNC_HEADER = '@RSYNCD:'
|
2015-11-06 20:25:27 +00:00
|
|
|
HANDLED_EXCEPTIONS = [
|
|
|
|
Rex::AddressInUse, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused,
|
|
|
|
::Errno::ETIMEDOUT, ::Timeout::Error, ::EOFError
|
|
|
|
]
|
2015-10-12 20:37:59 +00:00
|
|
|
|
2014-07-24 20:04:00 +00:00
|
|
|
def initialize
|
|
|
|
super(
|
2015-11-04 16:42:29 +00:00
|
|
|
'Name' => 'List Rsync Modules',
|
|
|
|
'Description' => %q(
|
|
|
|
An rsync module is essentially a directory share. These modules can
|
|
|
|
optionally be protected by a password. This module connects to and
|
|
|
|
negotiates with an rsync server, lists the available modules and,
|
|
|
|
optionally, determines if the module requires a password to access.
|
|
|
|
),
|
|
|
|
'Author' => [
|
|
|
|
'ikkini', # original metasploit module
|
2015-11-05 17:22:30 +00:00
|
|
|
'Jon Hart <jon_hart[at]rapid7.com>', # improved metasploit module
|
|
|
|
'Nixawk' # improved metasploit module
|
2015-11-04 16:42:29 +00:00
|
|
|
],
|
2014-08-28 23:47:56 +00:00
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
['URL', 'http://rsync.samba.org/ftp/rsync/rsync.html']
|
|
|
|
],
|
2014-07-24 20:04:00 +00:00
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
2015-11-04 18:01:38 +00:00
|
|
|
|
2014-07-24 20:04:00 +00:00
|
|
|
register_options(
|
|
|
|
[
|
2015-11-04 16:25:38 +00:00
|
|
|
OptBool.new('TEST_AUTHENTICATION',
|
|
|
|
[ true, 'Test if the rsync module requires authentication', true ]),
|
2014-08-28 23:40:55 +00:00
|
|
|
Opt::RPORT(873)
|
2015-11-04 18:01:38 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
register_advanced_options(
|
|
|
|
[
|
2015-11-04 18:11:00 +00:00
|
|
|
OptBool.new('SHOW_MOTD',
|
|
|
|
[ true, 'Show the rsync motd, if found', false ]),
|
2015-11-06 18:03:06 +00:00
|
|
|
OptBool.new('SHOW_VERSION',
|
|
|
|
[ true, 'Show the rsync version', false ]),
|
2015-11-04 18:01:38 +00:00
|
|
|
OptInt.new('READ_TIMEOUT', [ true, 'Seconds to wait while reading rsync responses', 2 ])
|
|
|
|
]
|
|
|
|
)
|
2014-07-24 20:04:00 +00:00
|
|
|
end
|
|
|
|
|
2015-10-12 20:03:55 +00:00
|
|
|
def read_timeout
|
2015-11-04 18:01:38 +00:00
|
|
|
datastore['READ_TIMEOUT']
|
2015-10-12 20:03:55 +00:00
|
|
|
end
|
|
|
|
|
2015-11-06 17:50:39 +00:00
|
|
|
def get_rsync_auth_status(rmodule)
|
2015-10-12 20:37:59 +00:00
|
|
|
sock.puts("#{rmodule}\n")
|
2015-11-04 18:01:38 +00:00
|
|
|
res = sock.get_once(-1, read_timeout)
|
2015-11-05 17:20:02 +00:00
|
|
|
if res
|
2015-11-06 17:50:39 +00:00
|
|
|
res.strip!
|
|
|
|
if res =~ /^#{RSYNC_HEADER} AUTHREQD \S+$/
|
2015-11-06 16:34:17 +00:00
|
|
|
'required'
|
2015-11-06 17:50:39 +00:00
|
|
|
elsif res =~ /^#{RSYNC_HEADER} OK$/
|
2015-11-06 16:34:17 +00:00
|
|
|
'not required'
|
2015-11-05 17:20:02 +00:00
|
|
|
else
|
2016-02-01 22:06:34 +00:00
|
|
|
vprint_error("unexpected response when connecting to #{rmodule}: #{res}")
|
2015-11-06 17:50:39 +00:00
|
|
|
"unexpected response '#{res}'"
|
2015-11-05 17:20:02 +00:00
|
|
|
end
|
2015-10-12 20:37:59 +00:00
|
|
|
else
|
2016-02-01 22:06:34 +00:00
|
|
|
vprint_error("no response when connecting to #{rmodule}")
|
2015-11-06 16:34:17 +00:00
|
|
|
'no response'
|
2015-10-12 20:37:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-12 18:19:31 +00:00
|
|
|
def rsync_list
|
|
|
|
sock.puts("#list\n")
|
|
|
|
|
2015-11-04 17:11:07 +00:00
|
|
|
modules_metadata = []
|
2015-10-12 18:19:31 +00:00
|
|
|
# the module listing is the module name and comment separated by a tab, each module
|
|
|
|
# on its own line, lines separated with a newline
|
2015-10-12 20:03:55 +00:00
|
|
|
sock.get(read_timeout).split(/\n/).map(&:strip).map do |module_line|
|
2015-11-04 17:12:02 +00:00
|
|
|
break if module_line =~ /^#{RSYNC_HEADER} EXIT$/
|
2015-11-02 17:14:41 +00:00
|
|
|
name, comment = module_line.split(/\t/).map(&:strip)
|
2015-11-04 16:47:37 +00:00
|
|
|
next unless name
|
2015-11-04 17:11:07 +00:00
|
|
|
modules_metadata << { name: name, comment: comment }
|
2015-10-12 18:19:31 +00:00
|
|
|
end
|
2015-10-12 20:03:55 +00:00
|
|
|
|
2015-11-04 17:11:07 +00:00
|
|
|
modules_metadata
|
2015-10-12 18:19:31 +00:00
|
|
|
end
|
|
|
|
|
2015-11-02 18:49:48 +00:00
|
|
|
# Attempts to negotiate the rsync protocol with the endpoint.
|
2015-11-04 17:43:10 +00:00
|
|
|
def rsync_negotiate
|
2015-10-30 20:13:44 +00:00
|
|
|
# rsync is promiscuous and will send the negotitation and motd
|
|
|
|
# upon connecting. abort if we get nothing
|
2015-11-04 18:01:38 +00:00
|
|
|
return unless (greeting = sock.get_once(-1, read_timeout))
|
2014-08-28 23:40:55 +00:00
|
|
|
|
2015-11-02 17:12:57 +00:00
|
|
|
# parse the greeting control and data lines. With some systems, the data
|
|
|
|
# lines at this point will be the motd.
|
|
|
|
greeting_control_lines, greeting_data_lines = rsync_parse_lines(greeting)
|
2015-10-12 20:03:55 +00:00
|
|
|
|
2015-10-30 20:13:44 +00:00
|
|
|
# locate the rsync negotiation and complete it by just echo'ing
|
|
|
|
# back the same rsync version that it sent us
|
|
|
|
version = nil
|
2015-11-02 17:12:57 +00:00
|
|
|
greeting_control_lines.map do |greeting_control_line|
|
|
|
|
if /^#{RSYNC_HEADER} (?<version>\d+(\.\d+)?)$/ =~ greeting_control_line
|
2015-10-12 20:37:59 +00:00
|
|
|
version = Regexp.last_match('version')
|
|
|
|
sock.puts("#{RSYNC_HEADER} #{version}\n")
|
2015-10-12 20:03:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-30 20:13:44 +00:00
|
|
|
unless version
|
2016-02-01 22:06:34 +00:00
|
|
|
vprint_error("no rsync negotiation found")
|
2015-10-30 20:13:44 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-11-04 18:01:38 +00:00
|
|
|
_, post_neg_data_lines = rsync_parse_lines(sock.get_once(-1, read_timeout))
|
2015-11-04 17:43:10 +00:00
|
|
|
motd_lines = greeting_data_lines + post_neg_data_lines
|
2015-11-02 17:18:10 +00:00
|
|
|
[ version, motd_lines.empty? ? nil : motd_lines.join("\n") ]
|
2015-11-02 17:12:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# parses the control and data lines from the provided response data
|
|
|
|
def rsync_parse_lines(response_data)
|
|
|
|
control_lines = []
|
|
|
|
data_lines = []
|
|
|
|
|
|
|
|
if response_data
|
|
|
|
response_data.strip!
|
|
|
|
response_data.split(/\n/).map do |line|
|
|
|
|
if line =~ /^#{RSYNC_HEADER}/
|
|
|
|
control_lines << line
|
|
|
|
else
|
|
|
|
data_lines << line
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
[ control_lines, data_lines ]
|
2015-10-12 18:19:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
2015-11-06 17:44:05 +00:00
|
|
|
begin
|
|
|
|
connect
|
|
|
|
version, motd = rsync_negotiate
|
|
|
|
unless version
|
2016-02-01 22:06:34 +00:00
|
|
|
vprint_error("does not appear to be rsync")
|
2015-11-06 17:44:05 +00:00
|
|
|
disconnect
|
|
|
|
return
|
|
|
|
end
|
2015-11-06 20:25:27 +00:00
|
|
|
rescue *HANDLED_EXCEPTIONS => e
|
2016-02-01 22:06:34 +00:00
|
|
|
vprint_error("error while connecting and negotiating: #{e}")
|
2015-10-12 18:19:31 +00:00
|
|
|
disconnect
|
|
|
|
return
|
|
|
|
end
|
2014-10-18 22:29:36 +00:00
|
|
|
|
2015-10-12 20:03:55 +00:00
|
|
|
info = "rsync protocol version #{version}"
|
|
|
|
info += ", MOTD '#{motd}'" if motd
|
2015-10-12 17:56:21 +00:00
|
|
|
report_service(
|
2015-10-12 16:05:01 +00:00
|
|
|
host: ip,
|
|
|
|
port: rport,
|
2015-10-12 17:56:21 +00:00
|
|
|
proto: 'tcp',
|
|
|
|
name: 'rsync',
|
2015-10-12 20:03:55 +00:00
|
|
|
info: info
|
2014-08-28 23:40:55 +00:00
|
|
|
)
|
2016-02-01 22:06:34 +00:00
|
|
|
print_status("rsync version: #{version}") if datastore['SHOW_VERSION']
|
|
|
|
print_status("rsync MOTD: #{motd}") if motd && datastore['SHOW_MOTD']
|
2014-08-28 23:40:55 +00:00
|
|
|
|
2015-11-06 17:44:05 +00:00
|
|
|
modules_metadata = {}
|
|
|
|
begin
|
|
|
|
modules_metadata = rsync_list
|
2015-11-06 20:25:27 +00:00
|
|
|
rescue *HANDLED_EXCEPTIONS => e
|
2015-11-06 17:44:05 +00:00
|
|
|
vprint_error("#{peer} -- error while listing modules: #{e}")
|
|
|
|
return
|
|
|
|
ensure
|
|
|
|
disconnect
|
|
|
|
end
|
|
|
|
|
2015-11-04 17:11:07 +00:00
|
|
|
if modules_metadata.empty?
|
2016-02-01 22:06:34 +00:00
|
|
|
print_status("no rsync modules found")
|
2015-10-12 16:51:00 +00:00
|
|
|
else
|
2015-11-04 17:11:07 +00:00
|
|
|
modules = modules_metadata.map { |m| m[:name] }
|
2016-02-01 22:06:34 +00:00
|
|
|
print_good("#{modules.size} rsync modules found: #{modules.join(', ')}")
|
2015-11-04 16:25:38 +00:00
|
|
|
|
|
|
|
table_columns = %w(Name Comment)
|
|
|
|
if datastore['TEST_AUTHENTICATION']
|
2015-11-06 17:50:39 +00:00
|
|
|
table_columns << 'Authentication'
|
2015-11-04 17:11:07 +00:00
|
|
|
modules_metadata.each do |module_metadata|
|
2015-11-06 17:44:05 +00:00
|
|
|
begin
|
|
|
|
connect
|
|
|
|
rsync_negotiate
|
2015-11-06 17:50:39 +00:00
|
|
|
module_metadata[:authentication] = get_rsync_auth_status(module_metadata[:name])
|
2015-11-06 20:25:27 +00:00
|
|
|
rescue *HANDLED_EXCEPTIONS => e
|
2016-02-01 22:06:34 +00:00
|
|
|
vprint_error("error while testing authentication on #{module_metadata[:name]}: #{e}")
|
2015-11-06 20:25:27 +00:00
|
|
|
break
|
2015-11-06 17:44:05 +00:00
|
|
|
ensure
|
|
|
|
disconnect
|
|
|
|
end
|
2015-11-04 16:25:38 +00:00
|
|
|
end
|
2015-10-12 20:37:59 +00:00
|
|
|
end
|
2015-11-02 17:12:57 +00:00
|
|
|
|
2015-10-12 16:51:00 +00:00
|
|
|
# build a table to store the module listing in
|
|
|
|
listing_table = Msf::Ui::Console::Table.new(
|
|
|
|
Msf::Ui::Console::Table::Style::Default,
|
2015-11-04 17:05:33 +00:00
|
|
|
'Header' => "rsync modules for #{peer}",
|
2015-11-04 16:25:38 +00:00
|
|
|
'Columns' => table_columns,
|
2015-11-04 17:11:07 +00:00
|
|
|
'Rows' => modules_metadata.map(&:values)
|
2015-10-12 18:19:31 +00:00
|
|
|
)
|
2015-10-12 16:51:00 +00:00
|
|
|
vprint_line(listing_table.to_s)
|
|
|
|
|
|
|
|
report_note(
|
|
|
|
host: ip,
|
|
|
|
proto: 'tcp',
|
|
|
|
port: rport,
|
2015-10-12 17:56:21 +00:00
|
|
|
type: 'rsync_modules',
|
2015-11-04 17:11:07 +00:00
|
|
|
data: { modules: modules_metadata }
|
2015-10-12 16:51:00 +00:00
|
|
|
)
|
|
|
|
end
|
2014-07-24 20:04:00 +00:00
|
|
|
end
|
2015-11-04 18:01:38 +00:00
|
|
|
|
|
|
|
def setup
|
|
|
|
fail_with(Failure::BadConfig, 'READ_TIMEOUT must be > 0') if read_timeout <= 0
|
|
|
|
end
|
2014-07-24 20:04:00 +00:00
|
|
|
end
|