Handle rsync motd

bug/bundler_fix
Jon Hart 2015-10-12 13:03:55 -07:00
parent 73a6b47606
commit 4a3848cc4f
1 changed files with 38 additions and 14 deletions

View File

@ -27,53 +27,76 @@ class Metasploit3 < Msf::Auxiliary
], self.class)
end
def read_timeout
10
end
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
sock.get(20).split(/\n/).map(&:strip).map do |module_line|
sock.get(read_timeout).split(/\n/).map(&:strip).map do |module_line|
next if module_line =~ /^@RSYNCD: EXIT$/
list << module_line.split(/\t/).map(&:strip)
end
list
end
def rsync_negotiate
connect
return unless greeting = sock.get_once
return unless greeting = sock.get(read_timeout)
greeting.strip!
if /^@RSYNCD: (?<version>\d+(\.\d+)?)$/ =~ greeting
# making sure we match the version of the server
sock.puts("@RSYNCD: #{version}\n")
version
control_lines = []
motd_lines = []
greeting.split(/\n/).map do |greeting_line|
if greeting_line =~ /^@RSYNCD:/
control_lines << greeting_line
else
motd_lines << greeting_line
end
end
control_lines.map do |control_line|
if /^@RSYNCD: (?<version>\d+(\.\d+)?)$/ =~ control_line
motd = motd_lines.empty? ? nil : motd_lines.join("\n")
sock.puts("@RSYNCD: #{version}\n")
end
return version, motd
end
nil
end
def run_host(ip)
unless version = rsync_negotiate
connect
version, motd = rsync_negotiate
unless version
disconnect
return
end
info = "rsync protocol version #{version}"
info += ", MOTD '#{motd}'" if motd
report_service(
host: ip,
port: rport,
proto: 'tcp',
name: 'rsync',
info: "rsync protocol version #{version}"
info: info
)
vprint_good("#{ip}:#{rport} - rsync MOTD: #{motd}") if motd
listing = rsync_list
if listing.empty?
print_status("#{ip}:#{port} - rsync #{version}: no modules found")
print_status("#{ip}:#{rport} - rsync #{version}: no modules found")
else
# build a table to store the module listing in
listing_table = Msf::Ui::Console::Table.new(
Msf::Ui::Console::Table::Style::Default,
'Header' => "rsync modules",
'Header' => "rsync modules for #{ip}:#{rport}",
'Columns' =>
[
"Name",
@ -82,7 +105,8 @@ class Metasploit3 < Msf::Auxiliary
'Rows' => listing
)
print_good("#{ip}:#{rport} - rsync #{version}: #{listing_table.rows.size} modules found")
print_good("#{ip}:#{rport} - rsync #{version}: #{listing.size} modules found: " \
"#{listing.map(&:first).join(', ')}")
vprint_line(listing_table.to_s)
report_note(
@ -90,8 +114,8 @@ class Metasploit3 < Msf::Auxiliary
proto: 'tcp',
port: rport,
type: 'rsync_modules',
:data => { :modules => listing_table.rows },
:update => :unique_data
data: { modules: listing },
update: :unique_data
)
end
end