From 2d0a6e1d601a7d7c60bd2c624b1cd38260e62a0f Mon Sep 17 00:00:00 2001 From: dadevel Date: Tue, 5 Aug 2025 00:21:27 +0200 Subject: [PATCH] Add symlink support to smbclient --- impacket/examples/smbclient.py | 17 ++++++++++++ impacket/smb3structs.py | 22 +++++++++++++++ impacket/smbconnection.py | 49 +++++++++++++++++++++++++++++++++- 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/impacket/examples/smbclient.py b/impacket/examples/smbclient.py index efd7f1adc8..c9af87498e 100755 --- a/impacket/examples/smbclient.py +++ b/impacket/examples/smbclient.py @@ -25,6 +25,7 @@ import cmd import os import ntpath +import shlex from six import PY2 from impacket.dcerpc.v5 import samr, transport, srvs @@ -123,6 +124,8 @@ def do_help(self,line): cat {filename} - reads the filename from the current path mount {target,path} - creates a mount point from {path} to {target} (admin required) umount {path} - removes the mount point at {path} without deleting the directory (admin required) + create_symlink {target,path} - creates a symlink from {path} to {target}, can be file or dir, path must exist (admin required) + remove_symlink {path} - removes the symlink at {path} without deleting the directory (admin required) list_snapshots {path} - lists the vss snapshots for the specified path info - returns NetrServerInfo main results who - returns the sessions currently connected at the target host (admin required) @@ -664,6 +667,20 @@ def do_umount(self, mountpoint): self.smb.removeMountPoint(self.tid, mountPath) + def do_create_symlink(self, line): + target, path = shlex.split(line) + target = target.replace('/','\\') + path = path.replace('/','\\') + if not path.startswith('\\'): + path = ntpath.join(self.pwd, path) + self.smb.createSymlink(self.tid, path, target) + + def do_remove_symlink(self, line): + path = line.replace('/','\\') + if not path.startswith('\\'): + path = ntpath.join(self.pwd, path) + self.smb.removeSymlink(self.tid, path) + def do_EOF(self, line): print('Bye!\n') return True diff --git a/impacket/smb3structs.py b/impacket/smb3structs.py index 556e3e6f06..5ef8978a77 100644 --- a/impacket/smb3structs.py +++ b/impacket/smb3structs.py @@ -1296,6 +1296,28 @@ class MOUNT_POINT_REPARSE_GUID_DATA_STRUCTURE(Structure): ("DataBuffer", ":") ) +class SYMLINK_REPARSE_DATA_STRUCTURE(Structure): + structure = ( + ('ReparseTag', '