Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn off Ruby deprecation warnings for all users #13360

Merged
merged 1 commit into from
Apr 29, 2020

Conversation

dwelch-r7
Copy link
Contributor

Turns off warnings for all users, this is a temporary measure to limit the confusion we're seeing with end users on ruby 2.7.0 that now produces several warnings.
There will be another PR up soon to enable warnings only when msf is being used in a development environment

  • Switch to ruby 2.7.0
  • Start up msfconsole
  • Observe the warnings
  • Checkout this branch
  • Start up msfconsole
  • Warnings should be gone

@@ -8,6 +8,9 @@
require 'pathname'

begin
# TODO: Temporary until warnings can be turned on only for developers to prevent confusion for end users
Warning[:deprecated] = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would any of the other tools be impacted, like msfvenom etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this should affect any other tools no
do you think we should be disabling warnings from other tools? I don't think we've had any issues from that (yet)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some scenarios msfvenom loads msf, which will trigger warnings:

$ ruby --version
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18]
$ bundle exec ruby ./msfvenom -p windows/meterpreter/reverse_tcp LHOST=127.0.0.1 --encrypt rc4 --encrypt-key thisisakey -f c
/Users/user/.rvm/gems/ruby-2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:84: warning: deprecated Object#=~ is called on Integer; it always returns nil
/Users/user/.rvm/gems/ruby-2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:84: warning: deprecated Object#=~ is called on Integer; it always returns nil

...

Other tools may also load msf

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good to land this change for now, and we can look into the other edgecases as part of the follow up work 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➜  metasploit-framework git:(turn-off-warnings) ✗ ./msfvenom -p windows/meterpreter/reverse_tcp LHOST=127.0.0.1 --encrypt rc4 --encrypt-key thisisakey -f c
/Users/dwelch/.rvm/gems/ruby-2.7.0@metasploit-framework/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:84: warning: deprecated Object#=~ is called on Integer; it always returns nil
/Users/dwelch/.rvm/gems/ruby-2.7.0@metasploit-framework/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:84: warning: deprecated Object#=~ is called on Integer; it always returns nil

just checked, it doesn't affect msfvenom, it's loading those files sure but not via the msfconsole file where I added the change

Copy link
Contributor

@adfoster-r7 adfoster-r7 Apr 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msfvenom loads msf directly here:

def require_deps
require 'msfenv'
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
require 'rex'
require 'msf/ui'
require 'msf/base'
require 'msf/core/payload_generator'
@framework_loaded = true
end

I think that means that either the deprecated warning suppression needs to be in the entrypoints of our tools, or closer to the entrypoint of msf itself.

@adfoster-r7 adfoster-r7 added the usability Usability improvements label Apr 29, 2020
@adfoster-r7
Copy link
Contributor

Confirmed that this no longer shows warnings with Ruby 2.7 on bootup, or later:

Master:

msf5 > irb
[*] Starting IRB shell...
[*] You are in the "framework" object

irb: warn: can't alias jobs from irb_jobs.
>> 123 =~ 'abc'
(irb):1: warning: deprecated Object#=~ is called on Integer; it always returns nil
=> nil

Branch:

msf5 > irb
[*] Starting IRB shell...
[*] You are in the "framework" object

irb: warn: can't alias jobs from irb_jobs.
>> 123 =~ 'abc'
=> nil

@adfoster-r7 adfoster-r7 changed the title Turn off warnings for all users Turn off Ruby deprecation warnings for all users Apr 29, 2020
@adfoster-r7 adfoster-r7 merged commit 6c75ced into rapid7:master Apr 29, 2020
@adfoster-r7
Copy link
Contributor

adfoster-r7 commented Apr 29, 2020

Release Notes

The msfconsole will no longer output ActiveRecord warning messages on start up when using Ruby 2.7.x

@dwelch-r7 dwelch-r7 deleted the turn-off-warnings branch April 29, 2020 11:33
@adfoster-r7 adfoster-r7 added the rn-fix release notes fix label Apr 30, 2020
@dwelch-r7 dwelch-r7 assigned dwelch-r7 and adfoster-r7 and unassigned dwelch-r7 May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn-fix release notes fix usability Usability improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants