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

Patches File to use .exist? when .exists? is called #19217

Merged
merged 1 commit into from
May 31, 2024

Conversation

zgoldman-r7
Copy link
Contributor

@zgoldman-r7 zgoldman-r7 commented May 29, 2024

Adds a patch to address #19160
File.exists? has been deprecated in favor of File.exist? in Ruby 3.2+, but not all gems have eliminated its usage. This adds a patch to convert File.exists? to the newer File.exist? when called
Previously, tab completing a path option would cause metasploit to crash when using ruby 3.2+:

/home/zgoldman/.rvm/gems/ruby-3.2.3@metasploit-framework/gems/rb-readline-0.5.5/lib/rbreadline.rb:8490:in `append_to_match': undefined method `exists?' for File:Class (NoMethodError)
Did you mean?  exist?

To test:

  • In ruby 3.2+, try and set a path option for a module, and tab complete it. Ensure it doesn't crash.

@adfoster-r7
Copy link
Contributor

Does this PR plan to cover the work mentioned in the original internal Jira ticket about Rubocop? Or is that a separate effort

@zgoldman-r7
Copy link
Contributor Author

Does this PR plan to cover the work mentioned in the original internal Jira ticket about Rubocop? Or is that a separate effort

@adfoster-r7 I'm working on that now which is why I left this in draft 👍

@zgoldman-r7 zgoldman-r7 force-pushed the file-exists-patch branch 2 times, most recently from 354ea10 to 0e88d90 Compare May 30, 2024 01:40
@zgoldman-r7 zgoldman-r7 marked this pull request as ready for review May 30, 2024 01:43
@adfoster-r7
Copy link
Contributor

adfoster-r7 commented May 30, 2024

I don't think the boilerplate Rubocop code is required; you can verify this on a new module such as modules/exploits/multi/http/apache_normalize_path_rce.rb that when the deprecated File.exists? code is present - Rubocop validates it correctly and would fail CI if a user tried to introduce this:

diff --git a/modules/exploits/multi/http/apache_normalize_path_rce.rb b/modules/exploits/multi/http/apache_normalize_path_rce.rb
index b219e49213..3b8514c40b 100644
--- a/modules/exploits/multi/http/apache_normalize_path_rce.rb
+++ b/modules/exploits/multi/http/apache_normalize_path_rce.rb
@@ -131,6 +131,7 @@ class MetasploitModule < Msf::Exploit::Remote
   end
 
   def exploit
+    print_status 'foo exists' if File.exists?('foo')
     @proto = (ssl ? 'https' : 'http')
 
     if (!check.eql? Exploit::CheckCode::Vulnerable) && !datastore['ForceExploit']

Rubocop output:

rubocop modules/exploits/multi/http/apache_normalize_path_rce.rb
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
Inspecting 1 file
W

Offenses:

modules/exploits/multi/http/apache_normalize_path_rce.rb:134:34: W: [Correctable] Lint/DeprecatedClassMethods: File.exists? is deprecated in favor of File.exist?.
    print_status 'foo exists' if File.exists?('foo')
                                 ^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense autocorrectable

i.e. for the scope of the ticket We may be able to integrate a rubocop rule to ensure that folk don’t contribute File.exists? calls into new module - it looks like one is already provided by rubocop, and there's nothing additional to action there

@adfoster-r7 adfoster-r7 merged commit 3e75c42 into rapid7:master May 31, 2024
57 of 58 checks passed
@adfoster-r7
Copy link
Contributor

Release Notes

Fixes path tab completion for modules when using Ruby 3.2+

@adfoster-r7 adfoster-r7 added the rn-fix release notes fix label May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn-fix release notes fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants