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

Ensure CommunicationError is raised correctly, not EncryptionError #263

Conversation

cgranleese-r7
Copy link
Contributor

@cgranleese-r7 cgranleese-r7 commented Mar 15, 2024

Note

This PR is in conjunction with a PR in Metasploit-Framework . This PR will need to be landed before the framework PR.

This PR is to add a more precise error being raised when a session is dead. Currently in Metasploit-Framework if a session dies we would have had a RubySMB::Error::EncryptionError error being raised which wasn't accurate. This change will now raise an RubySMB::Error::CommunicationError when a session dies, which feels a lot closer in terms of accuracy.

@cgranleese-r7 cgranleese-r7 changed the title Adds EOFError raise for when a session is dead Adds EOFError raise when a session is dead Mar 15, 2024
@cgranleese-r7 cgranleese-r7 marked this pull request as draft March 15, 2024 12:15
lib/ruby_smb/client.rb Outdated Show resolved Hide resolved
@cgranleese-r7 cgranleese-r7 force-pushed the adds-eoferror-raise-when-response-is-nil-meaning-the-session-is-dead branch 3 times, most recently from 55b6a43 to 2716df6 Compare March 19, 2024 13:21
@cgranleese-r7 cgranleese-r7 marked this pull request as ready for review March 19, 2024 15:32
@@ -578,7 +578,7 @@ def recv_packet(encrypt: false)
raw_response = dispatcher.recv_packet
rescue RubySMB::Error::CommunicationError => e
if encrypt
raise RubySMB::Error::EncryptionError, "Communication error with the "\
raise e, "Communication error with the "\
Copy link
Contributor

Choose a reason for hiding this comment

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

For the context that you plan to use this in; if the session is killed - will the message be shown to the user as an encryption error?

Copy link
Contributor Author

@cgranleese-r7 cgranleese-r7 Mar 19, 2024

Choose a reason for hiding this comment

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

Good point. Should I add logic above this to check if the response is nil and raise a specific message for that scenario, or do you have something in mind?

Suggested change
raise e, "Communication error with the "\
raise RubySMB::Error::CommunicationError, "An error occurred reading from the Socket #{e.message}" if raw_response.nil?
if encrypt
raise e, "Communication error with the "\

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, actually doing my suggestion leave us in almost the same scenario we were for my original implementation. So probably not what we want 🤔

Copy link
Contributor

@adfoster-r7 adfoster-r7 Mar 20, 2024

Choose a reason for hiding this comment

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

I think long-term we should probably handle this better, potentially special casing this error if it's got a connection to a windows 8 target

For now, maybe we could just re-word the error message to be less clear-cut that the communication error was caused by encryption issues

      if encrypt
          raise e, "Communication error with the "\
            "remote host: #{e.message}. The server supports encryption and this error may have been caused by encryption issues."

Or maybe we could have special case for the amount of encrypted messages sent already, and if it's more than 1 - we just don't need this message any more

@cgranleese-r7 cgranleese-r7 force-pushed the adds-eoferror-raise-when-response-is-nil-meaning-the-session-is-dead branch from 2716df6 to aa9ed6e Compare March 20, 2024 12:25
@adfoster-r7 adfoster-r7 merged commit fa81d23 into rapid7:master Mar 20, 2024
6 checks passed
@adfoster-r7 adfoster-r7 changed the title Adds EOFError raise when a session is dead Ensure CommunicationError is raised correctly, not EncryptionError Mar 20, 2024
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.

3 participants