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

Add mode to file and io reads and writes #16343

Conversation

sjanusz-r7
Copy link
Contributor

This PR adds a mode to File.read and File.write calls, as per the comment here: #16325 (comment)

Verification

  • Start msfconsole
  • use a module that is currently failing due to File.read or File.write calls
  • Confirm that the module fails
  • Checkout this PR
  • Retry running the module
  • Confirm that with this PR, the module works

@sjanusz-r7 sjanusz-r7 force-pushed the add-mode-to-file-and-io-reads-and-writes branch 6 times, most recently from 8bbffce to 75ec339 Compare March 15, 2022 13:36
@sjanusz-r7 sjanusz-r7 force-pushed the add-mode-to-file-and-io-reads-and-writes branch from 75ec339 to 18d715b Compare March 15, 2022 13:39
@@ -77,7 +77,7 @@ def process_file(base64_file, save_path)
begin
# If we are running the data service on the same box this will ensure we only write
# the file if it is somehow not there already.
unless File.exists?(save_path) && File.read(save_path) == decoded_file
unless File.exists?(save_path) && File.read(save_path, mode: 'rb') == decoded_file
File.open(save_path, 'w+') { |file| file.write(decoded_file) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
File.open(save_path, 'w+') { |file| file.write(decoded_file) }
File.write(save_path, decoded_file, mode: 'wb')

@@ -166,7 +166,7 @@ def mssql_upload_exec(exe, debug=false)

print_status("Warning: This module will leave #{var_payload}.exe in the SQL Server %TEMP% directory")
print_status("Writing the debug.com loader to the disk...")
h2b = File.read(datastore['HEX2BINARY'], File.size(datastore['HEX2BINARY']))
h2b = File.read(datastore['HEX2BINARY'], File.size(datastore['HEX2BINARY']), mode: 'rb')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's revert this as the line below splits on \n

@sjanusz-r7 sjanusz-r7 closed this Mar 21, 2022
@sjanusz-r7
Copy link
Contributor Author

Closing this as these changes are now consolidated into a single PR here: #16325

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants