SMB File Transfer

05.06.2024 · dadevel

File Transfer over the SMB protocol.

Client

Linux Samba.

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

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

❯ impacket-smbclient administrator:'passw0rd'@192.0.2.1
# 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 //192.0.2.1/share/
cp //192.0.2.1/share/remote.txt .

Copy directories in PowerShell.

cp . //192.0.2.1/share -Recurse
cp //192.0.2.1/share . -Recurse

Authenticate against a share in PowerShell.

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

Copy files with Windows builtins.

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

Copy directories with Windows builtins.

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

Authenticate against a share with Windows builtins.

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

Server

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
[global]
  server role = standalone server
  security = user
  workgroup = WORKGROUP
  guest ok = yes

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