Resolve #4507 - respond_to? + send = evil

Since Ruby 2.1, the respond_to? method is more strict because it does
not check protected methods. So when you use send(), clearly you're
ignoring this type of access control. The patch is meant to preserve
this behavior to avoid potential breakage.

Resolve #4507
bug/bundler_fix
sinn3r 2015-01-02 13:21:15 -06:00
parent 5596cee803
commit d45cdd61aa
13 changed files with 26 additions and 26 deletions

View File

@ -179,23 +179,23 @@ class EventDispatcher
if respond_to?(subscribers, true) if respond_to?(subscribers, true)
found = true found = true
self.send(subscribers).each do |sub| self.send(subscribers).each do |sub|
next if not sub.respond_to?(name) next if not sub.respond_to?(name, true)
sub.send(name, *args) sub.send(name, *args)
end end
else else
(general_event_subscribers + custom_event_subscribers).each do |sub| (general_event_subscribers + custom_event_subscribers).each do |sub|
next if not sub.respond_to?(name) next if not sub.respond_to?(name, true)
sub.send(name, *args) sub.send(name, *args)
found = true found = true
end end
end end
when "add" when "add"
if respond_to?(subscribers) if respond_to?(subscribers, true)
found = true found = true
add_event_subscriber(self.send(subscribers), *args) add_event_subscriber(self.send(subscribers), *args)
end end
when "remove" when "remove"
if respond_to?(subscribers) if respond_to?(subscribers, true)
found = true found = true
remove_event_subscriber(self.send(subscribers), *args) remove_event_subscriber(self.send(subscribers), *args)
end end

View File

@ -78,7 +78,7 @@ module Exploit::Remote::FtpServer
return if not cmd return if not cmd
# Allow per-command overrides # Allow per-command overrides
if(self.respond_to?("on_client_command_#{cmd.downcase}")) if self.respond_to?("on_client_command_#{cmd.downcase}", true)
return self.send("on_client_command_#{cmd.downcase}", c, arg) return self.send("on_client_command_#{cmd.downcase}", c, arg)
end end

View File

@ -32,7 +32,7 @@ module RubyDL
def method_missing(meth, *args, &block) def method_missing(meth, *args, &block)
str = meth.to_s str = meth.to_s
lower = str[0,1].downcase + str[1..-1] lower = str[0,1].downcase + str[1..-1]
if self.respond_to? lower if self.respond_to?(lower, true)
self.send lower, *args self.send lower, *args
else else
super super

View File

@ -39,7 +39,7 @@ class Auxiliary
# Allow modules to define their own commands # Allow modules to define their own commands
# #
def method_missing(meth, *args) def method_missing(meth, *args)
if (mod and mod.respond_to?(meth.to_s)) if (mod and mod.respond_to?(meth.to_s, true) )
# Initialize user interaction # Initialize user interaction
mod.init_ui(driver.input, driver.output) mod.init_ui(driver.input, driver.output)

View File

@ -1088,13 +1088,13 @@ class Db
end end
elsif term == "output" elsif term == "output"
orderlist << make_sortable(note.data["output"]) orderlist << make_sortable(note.data["output"])
elsif note.respond_to?(term) elsif note.respond_to?(term, true)
orderlist << make_sortable(note.send(term)) orderlist << make_sortable(note.send(term))
elsif note.respond_to?(term.to_sym) elsif note.respond_to?(term.to_sym, true)
orderlist << make_sortable(note.send(term.to_sym)) orderlist << make_sortable(note.send(term.to_sym))
elsif note.respond_to?("data") && note.send("data").respond_to?(term) elsif note.respond_to?("data", true) && note.send("data").respond_to?(term, true)
orderlist << make_sortable(note.send("data").send(term)) orderlist << make_sortable(note.send("data").send(term))
elsif note.respond_to?("data") && note.send("data").respond_to?(term.to_sym) elsif note.respond_to?("data", true) && note.send("data").respond_to?(term.to_sym, true)
orderlist << make_sortable(note.send("data").send(term.to_sym)) orderlist << make_sortable(note.send("data").send(term.to_sym))
else else
orderlist << "" orderlist << ""
@ -1682,7 +1682,7 @@ class Db
end end
end end
meth = "db_connect_#{framework.db.driver}" meth = "db_connect_#{framework.db.driver}"
if(self.respond_to?(meth)) if(self.respond_to?(meth, true))
self.send(meth, *args) self.send(meth, *args)
if framework.db.active and not framework.db.modules_cached if framework.db.active and not framework.db.modules_cached
print_status("Rebuilding the module cache in the background...") print_status("Rebuilding the module cache in the background...")

View File

@ -173,7 +173,7 @@ class Tree
# Tree that responds to the call. # Tree that responds to the call.
# #
def method_missing(method_id,*params,&block) def method_missing(method_id,*params,&block)
if not parameters.nil? and parameters.respond_to?(method_id) then if not parameters.nil? and parameters.respond_to?(method_id, true) then
return parameters.send(method_id, *params, &block) return parameters.send(method_id, *params, &block)
elsif not is_root? then elsif not is_root? then
@parent.send method_id, *params, &block @parent.send method_id, *params, &block

View File

@ -293,7 +293,7 @@ module Rex
# XXX: Actually implement more of these # XXX: Actually implement more of these
def process_service(service,banner) def process_service(service,banner)
meth = "process_service_#{service.gsub("-","_")}" meth = "process_service_#{service.gsub("-","_")}"
if self.respond_to? meth if self.respond_to?(meth, true)
self.send meth, banner self.send meth, banner
else else
return (first_line banner) return (first_line banner)

View File

@ -24,7 +24,7 @@ module Kernel
payload = nil payload = nil
# Generate the recovery stub # Generate the recovery stub
if opts['Recovery'] and Kernel::Recovery.respond_to?(opts['Recovery']) if opts['Recovery'] and Kernel::Recovery.respond_to?(opts['Recovery'], true)
opts['RecoveryStub'] = Kernel::Recovery.send(opts['Recovery'], opts) opts['RecoveryStub'] = Kernel::Recovery.send(opts['Recovery'], opts)
end end
@ -35,10 +35,10 @@ module Kernel
end end
# Generate the stager # Generate the stager
if opts['Stager'] and Kernel::Stager.respond_to?(opts['Stager']) if opts['Stager'] and Kernel::Stager.respond_to?(opts['Stager'], true)
payload = Kernel::Stager.send(opts['Stager'], opts) payload = Kernel::Stager.send(opts['Stager'], opts)
# Or, generate the migrator # Or, generate the migrator
elsif opts['Migrator'] and Kernel::Migration.respond_to?(opts['Migrator']) elsif opts['Migrator'] and Kernel::Migration.respond_to?(opts['Migrator'], true)
payload = Kernel::Migration.send(opts['Migrator'], opts) payload = Kernel::Migration.send(opts['Migrator'], opts)
else else
raise ArgumentError, "A stager or a migrator must be specified." raise ArgumentError, "A stager or a migrator must be specified."

View File

@ -105,7 +105,7 @@ module DispatcherShell
print_error "The #{cmd} command is DEPRECATED" print_error "The #{cmd} command is DEPRECATED"
if cmd == "db_autopwn" if cmd == "db_autopwn"
print_error "See http://r-7.co/xY65Zr instead" print_error "See http://r-7.co/xY65Zr instead"
elsif method and self.respond_to?("cmd_#{method}") elsif method and self.respond_to?("cmd_#{method}", true)
print_error "Use #{method} instead" print_error "Use #{method} instead"
self.send("cmd_#{method}", *args) self.send("cmd_#{method}", *args)
end end
@ -116,7 +116,7 @@ module DispatcherShell
print_error "The #{cmd} command is DEPRECATED" print_error "The #{cmd} command is DEPRECATED"
if cmd == "db_autopwn" if cmd == "db_autopwn"
print_error "See http://r-7.co/xY65Zr instead" print_error "See http://r-7.co/xY65Zr instead"
elsif method and self.respond_to?("cmd_#{method}_help") elsif method and self.respond_to?("cmd_#{method}_help", true)
print_error "Use 'help #{method}' instead" print_error "Use 'help #{method}' instead"
self.send("cmd_#{method}_help") self.send("cmd_#{method}_help")
end end
@ -150,9 +150,9 @@ module DispatcherShell
next if (dispatcher.commands.nil?) next if (dispatcher.commands.nil?)
next if (dispatcher.commands.length == 0) next if (dispatcher.commands.length == 0)
if dispatcher.respond_to?("cmd_#{cmd}") if dispatcher.respond_to?("cmd_#{cmd}", true)
cmd_found = true cmd_found = true
break unless dispatcher.respond_to? "cmd_#{cmd}_help" break unless dispatcher.respond_to?("cmd_#{cmd}_help", true)
dispatcher.send("cmd_#{cmd}_help") dispatcher.send("cmd_#{cmd}_help")
help_found = true help_found = true
break break

View File

@ -79,7 +79,7 @@ class Metasploit4 < Msf::Exploit::Remote
end end
def exploit def exploit
unless self.respond_to?(target[:callback]) unless self.respond_to?(target[:callback], true)
fail_with(Failure::NoTarget, "Invalid target specified: no callback function defined") fail_with(Failure::NoTarget, "Invalid target specified: no callback function defined")
end end

View File

@ -113,7 +113,7 @@ class Metasploit3 < Msf::Exploit::Remote
sploit << [target.ret].pack("V") sploit << [target.ret].pack("V")
sploit << [target['FakeObject']].pack("V") sploit << [target['FakeObject']].pack("V")
sploit << [target['FakeObject']].pack("V") sploit << [target['FakeObject']].pack("V")
if target[:callback_rop] and self.respond_to?(target[:callback_rop]) if target[:callback_rop] and self.respond_to?(target[:callback_rop], true)
sploit << self.send(target[:callback_rop]) sploit << self.send(target[:callback_rop])
else else
sploit << [target['JmpESP']].pack("V") sploit << [target['JmpESP']].pack("V")

View File

@ -178,7 +178,7 @@ child_pid = fork do
def method_missing(meth, *args, &block) def method_missing(meth, *args, &block)
str = meth.to_s str = meth.to_s
lower = str[0,1].downcase + str[1..-1] lower = str[0,1].downcase + str[1..-1]
if self.respond_to? lower if self.respond_to? lower, true
self.send lower, *args self.send lower, *args
else else
super super

View File

@ -140,9 +140,9 @@ class Plugin::Wiki < Msf::Plugin
outputs = [] outputs = []
# Output the table # Output the table
if respond_to? "#{command}_to_table" if respond_to? "#{command}_to_table", true
table = send "#{command}_to_table", tbl_opts table = send "#{command}_to_table", tbl_opts
if table.respond_to? "to_#{wiki_type}" if table.respond_to? "to_#{wiki_type}", true
if tbl_opts[:file_name] if tbl_opts[:file_name]
print_status("Wrote the #{command} table to a file as a #{wiki_type} formatted table") print_status("Wrote the #{command} table to a file as a #{wiki_type} formatted table")
File.open(tbl_opts[:file_name],"wb") {|f| File.open(tbl_opts[:file_name],"wb") {|f|