Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upload/download/delete/mkdir/rmdir to smb session #18895

Merged

Conversation

dwelch-r7
Copy link
Contributor

@dwelch-r7 dwelch-r7 commented Feb 27, 2024

Merge after rapid7/ruby_smb#262

This PR adds the ability to upload/download/delete/mkdir/rmdir from within the smb session type

Verification Steps

  • Get an smb session (enable the session type with `features set smb_session_type true)
  • Upload a file with upload <local_file> and upload <local_file> <remote_path>
  • Download a file with download <remote_file> and download <remote_file> <local_path>
  • Delete a file with `delete <file_name>
  • Make a directory with mkdir <directory_name>
  • Delete a directory with rmdir <directory_name>
  • Deleting a directory with files inside displays a message to the user
  • Verify psexec still works

@dwelch-r7 dwelch-r7 force-pushed the add-upload-download-smb-session branch from ff901bb to db87cfa Compare February 28, 2024 11:43

full_path = as_ntpath(Pathname.new(shell.cwd).join(remote_path).to_s)
fd = simple_client.open(full_path, 'o')
fd.delete
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the fd object need closed? 🤔

Copy link
Contributor

@adfoster-r7 adfoster-r7 Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we ensure this close happens 👀

Side note; I wish the simple client offered a proc based API so all this cleanup would happen automagically

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

close is the first thing that happens when calling off to delete

def delete
begin
close
rescue StandardError
end
client.delete(name, tree_id)
end

@cgranleese-r7
Copy link
Contributor

Tested against Windows 10

A couple of the <cmd> -h commands points at the incorrect help output, probably worth double checking them all. I added any I came across while testing below under the corresponding command.

upload

Is the intended functionality to overwrite a file if one exists with the same name? Not familiar with how the SMB client handles that so just curious.
image

download

remote

image

local after downloading from session

image

delete

image

Noticed that delete -h returns the help output for download
image

mkdir

mkdir also worked when passing a directory with spaces 👍
image

mkdir -h returns upload help info:
image

rmdir

image

rmdir -h returns download help info:
image

Note

Not sure if this is an issue and isn't related to this PR but thought I'd call it out. Should ls be taking paths and return the appropriate output for the given path?
Currently if I pass ls a directory it just returns the pwd's ls output, rather than returning the directory I passed ls output:
image

If that is something we'd want to do, we should also update the output to have the passed path be returned somewhere like here maybe?

SMB (192.168.175.193\my_share\test) > ls
ls (\test) <-- Something like this
==

    #  Type  Name          Created                  Accessed       Written        Changed        Size
    -  ----  ----          -------                  --------       -------        -------        ----
    0  DIR   .             2023-12-13T15:25:18+00:  2024-03-01T11  2024-03-01T11  2024-03-01T11
                           00                       :31:31+00:00   :31:40+00:00   :31:40+00:00
    1  DIR   ..            2023-12-13T15:25:18+00:  2024-03-01T11  2024-03-01T11  2024-03-01T11
                           00                       :31:31+00:00   :31:40+00:00   :31:40+00:00
    2  FILE  smb_test.txt  2024-03-01T11:21:23+00:  2024-03-01T11  2024-03-01T11  2024-03-01T11  5
                           00                       :21:43+00:00   :21:43+00:00   :21:43+00:00

@cgranleese-r7 cgranleese-r7 self-assigned this Mar 1, 2024
@cgranleese-r7 cgranleese-r7 added the rn-enhancement release notes enhancement label Mar 1, 2024
@dwelch-r7 dwelch-r7 force-pushed the add-upload-download-smb-session branch from e5f6dca to 4e6663a Compare March 1, 2024 15:48
@cgranleese-r7
Copy link
Contributor

cgranleese-r7 commented Mar 1, 2024

Tested ls changes to now take a path. As well as larger uploads and downloads.

ls <path>

image

upload/download larger files

Uploaded a 2GB file fine. Took quite a while but it did upload correctly.

<cmd> -h

All commands now return the appropriate help output.

cgranleese-r7
cgranleese-r7 previously approved these changes Mar 4, 2024
Copy link
Contributor

@cgranleese-r7 cgranleese-r7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from some methods needing yard docs, it looks good to me 👍

@cgranleese-r7
Copy link
Contributor

cgranleese-r7 commented Mar 4, 2024

Upload/download completion status, works as expected 👍
image

@dwelch-r7 dwelch-r7 force-pushed the add-upload-download-smb-session branch from 8d76c2d to 55ed7b2 Compare March 5, 2024 10:45
@dwelch-r7 dwelch-r7 force-pushed the add-upload-download-smb-session branch from 7f7088c to e2dd58f Compare March 5, 2024 11:52
@adfoster-r7
Copy link
Contributor

@dwelch-r7 Needs a rebase 👍

@dwelch-r7 dwelch-r7 force-pushed the add-upload-download-smb-session branch 4 times, most recently from 7104bf7 to 6200642 Compare March 12, 2024 11:25
@dwelch-r7 dwelch-r7 marked this pull request as ready for review March 12, 2024 11:31
@dwelch-r7 dwelch-r7 force-pushed the add-upload-download-smb-session branch 2 times, most recently from d804706 to cb91c98 Compare March 12, 2024 11:52
@dwelch-r7 dwelch-r7 force-pushed the add-upload-download-smb-session branch from cb91c98 to 689caf4 Compare March 12, 2024 11:56
@cgranleese-r7
Copy link
Contributor

Tested against Windows 10 and everything I previous tested still worked. Added screenshots for the new additional verification steps below:

Error when running rmdir against a directory that isn't empty

image

psexec

image

@adfoster-r7 adfoster-r7 merged commit 15c56a8 into rapid7:master Mar 14, 2024
51 checks passed
@adfoster-r7
Copy link
Contributor

Release Notes

This PR adds the ability to upload/download/delete/mkdir/rmdir from within the SMB session type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn-enhancement release notes enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants