Skip to content

smbclient: verify the final SESSION_SETUP response signature - #5326

Open
musthaf-bughunter wants to merge 1 commit into
secdev:masterfrom
musthaf-bughunter:smbclient-verify-session-setup
Open

musthaf-bughunter wants to merge 1 commit into
secdev:masterfrom
musthaf-bughunter:smbclient-verify-session-setup

Conversation

@musthaf-bughunter

Copy link
Copy Markdown
Contributor

Description

SMBStreamSocket.recv only verifies signatures once session.SigningKey is set (smb2.py#L3846), but SMB_Client derives the keys in AUTHENTICATED (smbclient.py#L651), after the final SESSION_SETUP response was received. Its signature is therefore never checked, contrary to [MS-SMB2] 3.2.5.3.1 / 3.2.5.1.3.

A man-in-the-middle can clear SMB2_SESSION_FLAG_ENCRYPT_DATA in that response: against a server with REQUIRE_ENCRYPTION=True (SMB 3.0, 3.0.2, 3.1.1), the client keeps EncryptData=False and sends its next requests (TREE_CONNECT, ...) in plaintext. The added test relays the exchange between SMB_Server and SMB_Client over socketpairs and clears the flag; it fails on master with tampered SESSION_SETUP response was accepted.

The response is now verified in AUTHENTICATED for non-guest sessions when signing is required or the dialect is 3.1.1. SMB2_Header.verify raises Scapy_Exception instead of Exception so the failure can be caught.

SMB_Client derives the signing key in AUTHENTICATED, after the final
SESSION_SETUP response went through SMBStreamSocket.recv, so the
signature of that response was never checked ([MS-SMB2] 3.2.5.3.1).
A man-in-the-middle could clear SMB2_SESSION_FLAG_ENCRYPT_DATA and the
client then sent its next requests unencrypted. Verify the response
once the keys are computed, for non-guest sessions.

AI-Assisted: yes (Claude Opus 5.5)
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.15%. Comparing base (9192d14) to head (0590689).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5326      +/-   ##
==========================================
+ Coverage   81.12%   81.15%   +0.02%     
==========================================
  Files         376      376              
  Lines       99524    99530       +6     
==========================================
+ Hits        80743    80770      +27     
+ Misses      18781    18760      -21     
Files with missing lines Coverage Δ
scapy/layers/smb2.py 90.60% <100.00%> (+0.20%) ⬆️
scapy/layers/smbclient.py 70.17% <100.00%> (+0.41%) ⬆️

... and 10 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant