jborean93 / smbprotocol

Python SMBv2 and v3 Client
MIT License
318 stars 73 forks source link

Is there a way to get the shares names of a server? #283

Closed creddie closed 1 month ago

creddie commented 1 month ago

I am using the following code to list the files inside a share, its working for server A, but the question that I have is, is there a way to get the shares, if they were not told?

Long story, but the issue that I am facing is that Server B, has a share, and I don't have the name of it. Security wise, the user that I am using has access, since if I change the password, I get a invalid login error. I can even telnet to Server B successfully.

But as far as the share name, I keep getting for all my guesses:

BadNetworkName: Received unexpected status from the server: The specified share name cannot be found on the remote server. (3221225676) STATUS_BAD_NETWORK_NAME: 0xc00000cc

If this helps I am using Databricks for both servers, but Server A is a Windows machine and Server B is a fsx share in AWS.

Thanks in advance for your time.

-ed

import smbclient

#host
# fsx_dns_name    = 'vpce-0.us-east-1.vpce.amazonaws.com'
# share                = 'Share' --?

username        = 'domain\user'
password        = 'pass'

# Register the SMB session
smbclient.register_session(
    server=fsx_dns_name,
    username=username,       
    password=password
)

# List the directory contents
folder_path = rf"\\{fsx_dns_name}\{share}"

file_list = smbclient.listdir(folder_path)

for f in file_list:
    print(f)
jborean93 commented 1 month ago

There is technically a way to do so in the protocol/RPC side but it's not implemented in this library unfortunately. It requires an RPC call which is different from SMB and is not something I've yet had time to implement sorry.

adiroiban commented 1 month ago

See https://github.com/jborean93/smbprotocol/issues/118

I think that this is a duplicate.

jborean93 commented 1 month ago

Thanks, I thought there was an existing issue for this request. While support for this may be added in the future I have no plans on adding it anytime soon.

adiroiban commented 1 month ago

maybe leave #118 open. Even if you don't plan to add it yourself, it can be left open and closed one someone else implements it.

If you are on Windowns, just use win32net.NetShareEnum

jborean93 commented 1 month ago

Trying to implement an RPC layer is quite a lot of work, someone is free to work on it if they wish but I've got no plans on doing so. While the issues in this repo are starting to creep up and I should probably spend some time to go through them all again I don't see too much value in keeping open feature requests I have no plan on addressing at this point in time.

adiroiban commented 1 month ago

My idea is that if there is an open issue, it will be easier to find.

People can then read and see that there are workarounds.

If they really need this in smbprotocol, they can send a PR.

With an issue closed, it might send the message that you don't want to have this code in smbprotocol at all