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

Specify mode rb on file reads #16174

Merged
merged 1 commit into from
Feb 13, 2022

Conversation

AlanFoster
Copy link
Contributor

@AlanFoster AlanFoster commented Feb 12, 2022

Fixes an edge case when reading files on Windows, and fixes Ruby 3 crashes when reading files.

Windows fix

The file upload support of Meterpreter was broken on windows machines, which was doing additional EOL<->CRLF conversions on windows:

"b"  Binary file mode
     Suppresses EOL <-> CRLF conversion on Windows. And
     sets external encoding to ASCII-8BIT unless explicitly
     specified.

Crash fix

Ruby 2.7:

irb
2.7.1 :001 > RUBY_DESCRIPTION
 => "ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]" 
2.7.1 :003 > File.read('/etc/passwd', {:mode => 'rb'}).length
(irb):3: warning: Using the last argument as keyword parameters is deprecated
 => 7630 

Ruby 3:

/ # irb
irb(main):001:0> RUBY_DESCRIPTION
=> "ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux-musl]"
irb(main):002:0> File.read('/etc/passwd', {:mode => 'rb'}).length
(irb):2:in `read': no implicit conversion of Hash into Integer (TypeError)
	from (irb):2:in `<main>'
	from /usr/local/lib/ruby/gems/3.0.0/gems/irb-1.3.5/exe/irb:11:in `<top (required)>'
	from /usr/local/bin/irb:23:in `load'
	from /usr/local/bin/irb:23:in `<main>'

@timwr
Copy link
Contributor

timwr commented Feb 13, 2022

Looks good to me. I suspect some of these calls could be refactored to use the exploit_data function from file.rb, but I'll go ahead and land this for now to keep things simple and avoid needlessly breaking things.

@timwr timwr merged commit a13ae38 into rapid7:master Feb 13, 2022
@timwr
Copy link
Contributor

timwr commented Feb 13, 2022

Release notes

The change fixes the mode specification on File.read required for ruby 3 on multiple modules.

This pull request was closed.
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