Skip to content

DFS share support in smbprotocol #300

@akarasik

Description

@akarasik

Hello!

I am trying to connect to a DFS share using the low-level smbprotocol classes and functions, but it seems to be lacking the ability of getting the referral to be able to get a tree from the right hostname and path.
I found that getting the referral is tied to the ClientConfig from smbclient, and I couldn't make it work with the smbprotocol functions.

Is there a way in which smbprotocol can support connecting to DFS shares? or even just getting the referral for future tree usage?

Here are some code snippets for example:

This code works for connecting to the DFS share and getting the files list, due to the fact that scandir eventualy uses the get_smb_tree that converts the hostname to the referral host:

hostname = 'some.host'
username = 'myuser'
password = 'mypass'
share_name = 'shares/MYSHARE'
remote_port = '445'
connection_timeout = 10
SMBPROTOCOL_AUTH_PROTOCOL = 'ntlm'
SMBPROTOCOL_REQUIRE_SIGN = True

register_session(server=hostname, username=username, password=password, port=remote_port, connection_timeout=connection_timeout, auth_protocol=SMBPROTOCOL_AUTH_PROTOCOL, require_signing=SMBPROTOCOL_REQUIRE_SIGN)
filelist_iter = scandir(rf"\\{hostname}\{share_name}", search_pattern="*", username=username, password=password)

While when running this code results in an exception of NT_STATUS_BAD_NETWORK_NAME when executing tree.connect:

hostname = 'some.host'
username = 'myuser'
password = 'mypass'
share_name = 'shares/MYSHARE'
remote_port = '445'
connection_timeout = 10
SMBPROTOCOL_AUTH_PROTOCOL = 'ntlm'
SMBPROTOCOL_REQUIRE_SIGN = True

session = register_session(server=hostname, username=username, password=password, port=remote_port, connection_timeout=connection_timeout, auth_protocol=SMBPROTOCOL_AUTH_PROTOCOL, require_signing=SMBPROTOCOL_REQUIRE_SIGN)
tree = TreeConnect(session, rf'\\{hostname}\{share_name}')
tree.connect(require_secure_negotiate=SMBPROTOCOL_REQUIRE_SIGN)

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions