jborean93 / pypsexec

Remote Windows execution like PsExec on Python
MIT License
113 stars 38 forks source link

[FEATURE REQUEST] get, put #51

Closed ghost-ng closed 2 years ago

ghost-ng commented 2 years ago

Can there be a plan to upload and download files from the client/server? Or maybe this already exists and I am missing it? Thanks for the great module!

jborean93 commented 2 years ago

I'm reluctant to implement this as anything done inside pypsexec is really just going to be a mirror of what's possible in smbclient/smbprotocol. For example copying a file is as simple as

import smbclient

smbclient.shutil.copyfile("/tmp/local.txt", r"\\server\share\local.txt", username="...", password="...")

The benefits of this approach is that you can do more than just copy a file, directory, do server side copies, create directories, etc. The smbclient module is part of smbprotocol which is a dependency of pypsexec.

ghost-ng commented 2 years ago

thank you for your response. Is there a way I can reuse the existing session for this? I am dissecting the package and found the self.session object but cant seem to find a function that can reuse this object that can help with the transfer. I would like to streamline and not have to re-authenticate to make this happen. I apologize for my ignorance, I am trying to use this as an opportunity to learn about the python smb packages.

jborean93 commented 2 years ago

Yes unfortunately that is one downside you do need to re-authenticate a new session. Technically you can reuse the self.session object if you use the low level API but that's very verbose and I wouldn't recommend it. Ultimately re-authenticating with smbclient again isn't that bad, it's at most 2-3 messages (2 for kerb, 3 for ntlm) plus the tree connect which would have had to happen anyway.