Linux File Transfers

Linux File Transfers

Linux systems provide numerous native tools for transferring files across networks. Understanding these methods is essential for security professionals conducting assessments or responding to incidents.

Base64 Encoding/Decoding

Base64 encoding allows transferring files without requiring traditional file transfer protocols, which is particularly useful for text-based terminal sessions.

Encoding and Transferring Files

# Check original file hash
md5sum id_rsa
4e301756a07ded0a2dd6953abf015278  id_rsa

# Encode file to base64
cat id_rsa | base64 -w 0

# Result: LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0KYjNCbGJuTnphQzFyWlhr...

Decoding on Target System

# Decode base64 string to file
echo -n 'LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0KYjNCbGJuTnph...' | base64 -d > id_rsa

# Verify file integrity
md5sum id_rsa
4e301756a07ded0a2dd6953abf015278  id_rsa

Web Downloads

Most Linux distributions include utilities that can interact with web servers for file transfers.

Using wget

Using curl

Fileless Attacks

Linux pipes allow executing downloaded content directly without saving to disk.

Direct Execution with curl

Direct Execution with wget

Bash /dev/tcp Downloads

When common utilities are unavailable, Bash's built-in networking capabilities can be used.

SSH/SCP Transfers

Secure Copy Protocol (SCP) provides encrypted file transfers using SSH.

Setting Up SSH Server

Downloading with SCP

Uploading with SCP

Python Web Server

Python's built-in HTTP server modules provide a quick way to serve files.

Starting a Web Server

Alternative Web Servers

Web Server with Upload Capability

Standard Python HTTP servers don't support file uploads. The uploadserver module adds this functionality.

Setting Up Upload Server

Uploading Files to Server

OpenSSL Transfers

OpenSSL can be used to create encrypted connections for file transfers.

Server Side

Client Side

Netcat Transfers

Netcat (nc) provides a simple way to transfer files between systems.

Receiving Side

Sending Side

Troubleshooting Network Restrictions

Identifying Available Outbound Protocols

Common Errors and Solutions

Unable to Connect

Solution: Check DNS settings or use IP address instead of hostname.

Connection Timeout

Solution: Verify network connectivity or try alternate port/protocol.

Permission Denied

Solution: Check file permissions or run with appropriate privileges.

Best Practices

  1. Use encrypted transfers (HTTPS, SCP) when possible

  2. Verify file integrity using checksums (md5sum, sha256sum)

  3. Clean up after transfers to avoid leaving evidence

  4. Prefer native tools that are likely to be available

  5. Consider fileless transfers for stealth operations

  6. Create temporary users for SCP/SSH transfers rather than using existing credentials

Last updated