SMB File Transfer

05.06.2024 · dadevel

File Transfer over the SMB protocol.


Linux Samba.

❯ smbclient -U administrator%'passw0rd' //
smb: \> put local.txt
smb: \> get remote.txt

Python impacket (can be unreliable with large files over spotty connections).

❯ impacket-smbclient administrator:'passw0rd'@
# use share
# put local.txt
# get remote.txt

Generally all Windows programs that expect absolute file paths also accept paths to network shares aka UNC paths.

Copy files in PowerShell.

cp ./local.txt //
cp // .

Copy directories in PowerShell.

cp . // -Recurse
cp // . -Recurse

Authenticate against a share in PowerShell.

New-PSDrive -PSProvider FileSystem -Persist -Name S -Root \\\share -Credential (New-Object System.Management.Automation.PsCredential('smbuser', (ConvertTo-SecureString 'passw0rd' -AsPlainText -Force)))

Copy files with Windows builtins.

copy /y .\local.txt \\\share\remote.txt
copy /y \\\share\remote.txt .\local.txt

Copy directories with Windows builtins.

robocopy.exe /e . \\\share
robocopy.exe /e \\\share .

Authenticate against a share with Windows builtins.

net.exe use \\\share passw0rd /user:smbuser
net.exe use \\\share /delete
net.exe use s: \\\share /user:smbuser passw0rd


impacket with support for SMBv1 and SMBv2.

sudo impacket-smbserver -smb2support share ./srv  # anonymous access
sudo impacket-smbserver -smb2support -username smbuser -password 'passw0rd' share ./srv

Samba with support for SMBv3.

pacman -S extra/samba
cat << EOF > /etc/samba/smb.conf
  server role = standalone server
  security = user
  workgroup = WORKGROUP
  guest ok = yes

   path = /srv/smb
   public = yes
   writable = yes
useradd --create-home /srv/smb --user-group --shell /sbin/nologin smbuser
smbpasswd -a smbuser
smbd --foreground --no-process-group --debug-stdout --debuglevel 1