Skip to content

smbserver: only list entries of the queried folder in lookup_folder - #5307

Open
musthaf-bughunter wants to merge 1 commit into
secdev:masterfrom
musthaf-bughunter:smbserver-query-directory-pattern
Open

musthaf-bughunter wants to merge 1 commit into
secdev:masterfrom
musthaf-bughunter:smbserver-query-directory-pattern

Conversation

@musthaf-bughunter

Copy link
Copy Markdown
Contributor

Description

SMB_Server.lookup_folder passes the client-supplied QueryDirectory FileName pattern to Path.glob() (smbserver.py#L1147), which follows .. and subfolder components. A match outside the share makes lookup_file() raise FileNotFoundError (smbserver.py#L1067), which is not caught, so the session stops answering; no match returns STATUS_NO_MORE_FILES. A client, including a guest, can therefore probe for file names anywhere on the server's filesystem.

cli = smbclient("127.0.0.1", guest=True, cli=False)
cli.use("test")
cli.smbsock.set_TID(cli.current_tree)
fid = cli.smbsock.create_request(cli.normalize_path(cli.pwd), type="folder")
cli.smbsock.query_directory(fid, FileName="../../etc/pass*")  # times out if a match exists, else ['.']

The fix only keeps glob results whose resolved parent is the queried folder. A test is added to smbclientserver.uts.

The QueryDirectory FileName pattern is passed to Path.glob(), which
follows '..' and subfolders. A match outside the share made
lookup_file() raise and the session stop answering, while no match
returned STATUS_NO_MORE_FILES, so a client could probe for file names
anywhere on the server (e.g. '../../etc/pass*').

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

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.99%. Comparing base (4cef323) to head (dba5097).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5307   +/-   ##
=======================================
  Coverage   78.99%   78.99%           
=======================================
  Files         375      375           
  Lines       98802    98802           
=======================================
+ Hits        78044    78046    +2     
+ Misses      20758    20756    -2     
Files with missing lines Coverage Δ
scapy/layers/smbserver.py 75.03% <ø> (+0.25%) ⬆️

... and 2 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