Repository navigation
Reply with STATUS_DATA_ERROR when an SMB2 request fails to parse - #307
Open
Pushpenderrathore wants to merge 1 commit into
Open
Pushpenderrathore wants to merge 1 commit into
Pushpenderrathore wants to merge 1 commit into
Conversation
GenericPacket.read falls back to SMB1::Packet::EmptyPacket when the raw bytes can be parsed as neither the request class nor SMB2::Packet::ErrorPacket, so a well-formed SMB2 header followed by a truncated or malformed body produced an SMB1 EmptyPacket here. The handler only checked for SMB2::Packet::ErrorPacket and so dispatched the SMB1 object to the SMB2 do_* method, which raised NoMethodError on request.smb2_header and dropped the connection without a reply. The rescue branch was also missing an early return and read response.smb_header, which does not exist on an SMB2 ErrorPacket. Return STATUS_DATA_ERROR from the rescue, add SMB1::Packet::EmptyPacket to the parse-failure check, and use smb2_header when stamping the status. This matches handle_smb1's shape so an unparsable body always reaches the client as an SMB2 error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
GenericPacket.read(lib/ruby_smb/generic_packet.rb:51-63) falls back toSMB1::Packet::EmptyPacketwhen the raw bytes can be parsed as neither the request class norSMB2::Packet::ErrorPacket. A well-formed SMB2 header followed by a truncated or malformed body therefore returned an SMB1 EmptyPacket from an SMB2 request class's.read.handle_smb2only checkedis_a?(SMB2::Packet::ErrorPacket), missed the fallback, and dispatched the SMB1 object to the SMB2do_*method, which raised NoMethodError onrequest.smb2_headerand dropped the connection without a reply.The rescue branch was also missing an early return and wrote
response.smb_header.nt_status, which does not exist on an SMB2 ErrorPacket.Return STATUS_DATA_ERROR from the rescue, add
SMB1::Packet::EmptyPacketto the parse-failure check, and usesmb2_headerwhen stamping the status. This matcheshandle_smb1's shape so an unparsable body always reaches the client as an SMB2 error.Lab PoC
Reproducer builds an SMB2 header with
command = SESSION_SETUPand appends a two-byte body, then hands it toRubySMB::Server::ServerClient#handle_smb2.Before (upstream/master at b303067):
After (this branch):
Verification Steps
bundle exec rspec spec/lib/ruby_smb/server/server_client_spec.rbpasses locally (27 examples, 0 failures)bundle exec rspec spec/lib/ruby_smb/server/passes locally (365 examples, 0 failures)ServerClient#handle_smb2returns anSMB2::Packet::ErrorPacketwithSTATUS_DATA_ERRORfor a truncated SESSION_SETUP body (upstream crashed with NoMethodError onrequest.smb2_header)Test Evidence
365 examples in
spec/lib/ruby_smb/server/, 0 failures. New describe#handle_smb2 with a malformed request bodyasserts both the SMB2 ErrorPacket reply and thatdo_session_setup_smb2is not invoked.