From 8233c5bf48013db6e8147e8ff49cddb6b7ee3d86 Mon Sep 17 00:00:00 2001 From: twosevenzero Date: Tue, 21 Mar 2023 12:53:54 -0400 Subject: [PATCH] Closes Issue #697. Added a flag to append self.host to the filename of the retrieved file from the get-file option. --- cme/protocols/smb.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cme/protocols/smb.py b/cme/protocols/smb.py index 2752431c..b7917499 100755 --- a/cme/protocols/smb.py +++ b/cme/protocols/smb.py @@ -227,10 +227,9 @@ class smb(connection): sgroup.add_argument("--only-files", action='store_true', help='only spider files') tgroup = smb_parser.add_argument_group("Files", "Options for put and get remote files") - tgroup.add_argument("--put-file", nargs=2, metavar="FILE", - help='Put a local file into remote target, ex: whoami.txt \\\\Windows\\\\Temp\\\\whoami.txt') - tgroup.add_argument("--get-file", nargs=2, metavar="FILE", - help='Get a remote file, ex: \\\\Windows\\\\Temp\\\\whoami.txt whoami.txt') + tgroup.add_argument("--put-file", nargs=2, metavar="FILE", help='Put a local file into remote target, ex: whoami.txt \\\\Windows\\\\Temp\\\\whoami.txt') + tgroup.add_argument("--get-file", nargs=2, metavar="FILE", help='Get a remote file, ex: \\\\Windows\\\\Temp\\\\whoami.txt whoami.txt') + tgroup.add_argument("--append-host", action='store_true', help='append the host to the get-file filename') cgroup = smb_parser.add_argument_group("Command Execution", "Options for executing commands") cgroup.add_argument('--exec-method', choices={"wmiexec", "mmcexec", "smbexec", "atexec"}, default=None, @@ -1410,10 +1409,13 @@ class smb(connection): def get_file(self): self.logger.info('Copy {} to {}'.format(self.args.get_file[0], self.args.get_file[1])) - with open(self.args.get_file[1], 'wb+') as file: + file_handle = self.args.get_file[1] + if self.args.append_host: + file_handle = self.args.get_file[1] + "_" + self.host + with open(file_handle, 'wb+') as file: try: self.conn.getFile(self.args.share, self.args.get_file[0], file.write) - self.logger.success(f"File {self.args.get_file[0]} was transferred to {self.args.get_file[1]}") + self.logger.success('File {} was transferred to {}'.format(self.args.get_file[0], file_handle)) except Exception as e: self.logger.error('Error reading file {}: {}'.format(self.args.share, e))