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:'
|
|
|
|
|
2014-07-24 20:04:00 +00:00
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'Rsync Unauthenticated List Command',
|
2014-07-24 21:26:41 +00:00
|
|
|
'Description' => 'List all (listable) modules from a rsync daemon',
|
|
|
|
'Author' => 'ikkini',
|
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
|
|
|
|
)
|
|
|
|
register_options(
|
|
|
|
[
|
2014-08-28 23:40:55 +00:00
|
|
|
Opt::RPORT(873)
|
|
|
|
], self.class)
|
2014-07-24 20:04:00 +00:00
|
|
|
end
|
|
|
|
|
2015-10-12 20:03:55 +00:00
|
|
|
def read_timeout
|
|
|
|
10
|
|
|
|
end
|
|
|
|
|
2015-10-12 20:37:59 +00:00
|
|
|
def rsync_requires_auth?(rmodule)
|
|
|
|
sock.puts("#{rmodule}\n")
|
|
|
|
res = sock.get_once
|
|
|
|
if res && (res =~ /^#{RSYNC_HEADER} AUTHREQD/)
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-12 18:19:31 +00:00
|
|
|
def rsync_list
|
|
|
|
sock.puts("#list\n")
|
|
|
|
|
|
|
|
list = []
|
|
|
|
# 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-10-12 20:37:59 +00:00
|
|
|
next if module_line =~ /^#{RSYNC_HEADER} EXIT$/
|
2015-10-12 18:19:31 +00:00
|
|
|
list << module_line.split(/\t/).map(&:strip)
|
|
|
|
end
|
2015-10-12 20:03:55 +00:00
|
|
|
|
2015-10-12 18:19:31 +00:00
|
|
|
list
|
|
|
|
end
|
|
|
|
|
|
|
|
def rsync_negotiate
|
2015-10-12 20:03:55 +00:00
|
|
|
return unless greeting = sock.get(read_timeout)
|
2014-08-28 23:40:55 +00:00
|
|
|
|
2015-10-12 17:56:21 +00:00
|
|
|
greeting.strip!
|
2015-10-12 20:03:55 +00:00
|
|
|
control_lines = []
|
|
|
|
motd_lines = []
|
|
|
|
greeting.split(/\n/).map do |greeting_line|
|
2015-10-12 20:37:59 +00:00
|
|
|
if greeting_line =~ /^#{RSYNC_HEADER}/
|
2015-10-12 20:03:55 +00:00
|
|
|
control_lines << greeting_line
|
|
|
|
else
|
|
|
|
motd_lines << greeting_line
|
|
|
|
end
|
2015-10-12 18:19:31 +00:00
|
|
|
end
|
2015-10-12 20:03:55 +00:00
|
|
|
|
|
|
|
control_lines.map do |control_line|
|
2015-10-12 20:37:59 +00:00
|
|
|
if /^#{RSYNC_HEADER} (?<version>\d+(\.\d+)?)$/ =~ control_line
|
|
|
|
version = Regexp.last_match('version')
|
2015-10-12 20:03:55 +00:00
|
|
|
motd = motd_lines.empty? ? nil : motd_lines.join("\n")
|
2015-10-12 20:37:59 +00:00
|
|
|
sock.puts("#{RSYNC_HEADER} #{version}\n")
|
|
|
|
return version, motd
|
2015-10-12 20:03:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
nil
|
2015-10-12 18:19:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
2015-10-12 20:03:55 +00:00
|
|
|
connect
|
|
|
|
version, motd = rsync_negotiate
|
|
|
|
unless version
|
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
|
|
|
)
|
2015-10-12 20:03:55 +00:00
|
|
|
vprint_good("#{ip}:#{rport} - rsync MOTD: #{motd}") if motd
|
2014-08-28 23:40:55 +00:00
|
|
|
|
2015-10-12 18:19:31 +00:00
|
|
|
listing = rsync_list
|
2015-10-12 20:37:59 +00:00
|
|
|
disconnect
|
2015-10-12 18:19:31 +00:00
|
|
|
if listing.empty?
|
2015-10-12 20:03:55 +00:00
|
|
|
print_status("#{ip}:#{rport} - rsync #{version}: no modules found")
|
2015-10-12 16:51:00 +00:00
|
|
|
else
|
2015-10-30 16:49:07 +00:00
|
|
|
print_good("#{ip}:#{rport} - rsync #{version}: #{listing.size} modules found: " \
|
|
|
|
"#{listing.map(&:first).join(', ')}")
|
2015-10-12 20:37:59 +00:00
|
|
|
listing.each do |name_comment|
|
|
|
|
connect
|
|
|
|
rsync_negotiate
|
|
|
|
name_comment << rsync_requires_auth?(name_comment.first)
|
|
|
|
disconnect
|
|
|
|
end
|
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-10-12 20:03:55 +00:00
|
|
|
'Header' => "rsync modules for #{ip}:#{rport}",
|
2015-10-12 16:51:00 +00:00
|
|
|
'Columns' =>
|
|
|
|
[
|
|
|
|
"Name",
|
2015-10-12 20:37:59 +00:00
|
|
|
"Comment",
|
|
|
|
"Authentication?"
|
2015-10-12 18:19:31 +00:00
|
|
|
],
|
|
|
|
'Rows' => listing
|
|
|
|
)
|
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-10-12 20:03:55 +00:00
|
|
|
data: { modules: listing },
|
|
|
|
update: :unique_data
|
2015-10-12 16:51:00 +00:00
|
|
|
)
|
|
|
|
end
|
2014-07-24 20:04:00 +00:00
|
|
|
end
|
|
|
|
end
|