Skip to content

Commit

Permalink
Resolve rapid7#4507 - respond_to? + send = evil
Browse files Browse the repository at this point in the history
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 rapid7#4507
  • Loading branch information
wchen-r7 committed Jan 2, 2015
1 parent 5596cee commit d45cdd6
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions lib/msf/core/event_dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,23 @@ def method_missing(name, *args)
if respond_to?(subscribers, true)
found = true
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)
end
else
(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)
found = true
end
end
when "add"
if respond_to?(subscribers)
if respond_to?(subscribers, true)
found = true
add_event_subscriber(self.send(subscribers), *args)
end
when "remove"
if respond_to?(subscribers)
if respond_to?(subscribers, true)
found = true
remove_event_subscriber(self.send(subscribers), *args)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/msf/core/exploit/ftpserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def on_client_data(c)
return if not cmd

# 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)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/msf/core/post/osx/ruby_dl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Importable
def method_missing(meth, *args, &block)
str = meth.to_s
lower = str[0,1].downcase + str[1..-1]
if self.respond_to? lower
if self.respond_to?(lower, true)
self.send lower, *args
else
super
Expand Down
2 changes: 1 addition & 1 deletion lib/msf/ui/console/command_dispatcher/auxiliary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def commands
# Allow modules to define their own commands
#
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
mod.init_ui(driver.input, driver.output)
Expand Down
10 changes: 5 additions & 5 deletions lib/msf/ui/console/command_dispatcher/db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1088,13 +1088,13 @@ def cmd_notes(*args)
end
elsif term == "output"
orderlist << make_sortable(note.data["output"])
elsif note.respond_to?(term)
elsif note.respond_to?(term, true)
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))
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))
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))
else
orderlist << ""
Expand Down Expand Up @@ -1682,7 +1682,7 @@ def cmd_db_connect(*args)
end
end
meth = "db_connect_#{framework.db.driver}"
if(self.respond_to?(meth))
if(self.respond_to?(meth, true))
self.send(meth, *args)
if framework.db.active and not framework.db.modules_cached
print_status("Rebuilding the module cache in the background...")
Expand Down
2 changes: 1 addition & 1 deletion lib/rabal/tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def walk(tree,method)
# Tree that responds to the call.
#
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)
elsif not is_root? then
@parent.send method_id, *params, &block
Expand Down
2 changes: 1 addition & 1 deletion lib/rex/parser/foundstone_nokogiri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def first_line(str)
# XXX: Actually implement more of these
def process_service(service,banner)
meth = "process_service_#{service.gsub("-","_")}"
if self.respond_to? meth
if self.respond_to?(meth, true)
self.send meth, banner
else
return (first_line banner)
Expand Down
6 changes: 3 additions & 3 deletions lib/rex/payloads/win32/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def self.construct(opts = {})
payload = nil

# 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)
end

Expand All @@ -35,10 +35,10 @@ def self.construct(opts = {})
end

# 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)
# 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)
else
raise ArgumentError, "A stager or a migrator must be specified."
Expand Down
8 changes: 4 additions & 4 deletions lib/rex/ui/text/dispatcher_shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def deprecated_cmd(method=nil, *args)
print_error "The #{cmd} command is DEPRECATED"
if cmd == "db_autopwn"
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"
self.send("cmd_#{method}", *args)
end
Expand All @@ -116,7 +116,7 @@ def deprecated_help(method=nil)
print_error "The #{cmd} command is DEPRECATED"
if cmd == "db_autopwn"
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"
self.send("cmd_#{method}_help")
end
Expand Down Expand Up @@ -150,9 +150,9 @@ def cmd_help(cmd=nil, *ignored)
next if (dispatcher.commands.nil?)
next if (dispatcher.commands.length == 0)

if dispatcher.respond_to?("cmd_#{cmd}")
if dispatcher.respond_to?("cmd_#{cmd}", 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")
help_found = true
break
Expand Down
2 changes: 1 addition & 1 deletion modules/exploits/linux/misc/hikvision_rtsp_bof.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def initialize(info = {})
end

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")
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def exploit
sploit << [target.ret].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])
else
sploit << [target['JmpESP']].pack("V")
Expand Down
2 changes: 1 addition & 1 deletion modules/post/osx/capture/keylog_recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ module Importable
def method_missing(meth, *args, &block)
str = meth.to_s
lower = str[0,1].downcase + str[1..-1]
if self.respond_to? lower
if self.respond_to? lower, true
self.send lower, *args
else
super
Expand Down
4 changes: 2 additions & 2 deletions plugins/wiki.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ def wiki(wiki_type, *args)
outputs = []

# Output the table
if respond_to? "#{command}_to_table"
if respond_to? "#{command}_to_table", true
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]
print_status("Wrote the #{command} table to a file as a #{wiki_type} formatted table")
File.open(tbl_opts[:file_name],"wb") {|f|
Expand Down

0 comments on commit d45cdd6

Please sign in to comment.