Staging and Compressing Data for Exfiltration on Linux
Compressing before transferring reduces size, speeds up transfer, and lets you move a collection of files as a single object. Staging in the right location avoids permission issues and reduces the chance of leaving traces in monitored directories.
Staging Location
Pick a writable location that fits the situation:
/dev/shm/ # memory-backed, no disk writes, cleared on reboot
/tmp/ # writable by all, may be cleared on reboot
/var/tmp/ # persists across reboots, often overlooked
/dev/shm/ is the preferred staging area when stealth matters — nothing is written to disk. Use /var/tmp/ when you need the staged file to survive a reboot.
Create a working directory to keep things organised:
Use a non-obvious name. Avoid names like loot or exfil.
Compressing with tar
A single directory:
Multiple targets:
c — create, z — gzip compression, f — filename. The 2>/dev/null suppresses permission errors on files you cannot read.
Verify the archive contents before transferring:
Compressing with zip
Useful when the receiving end is Windows or when password protection is needed:
Password-protected:
Splitting Large Archives
If the transfer channel has size limits or you want to move data in smaller chunks:
This produces files named chunk_aa, chunk_ab, etc., each 5MB. Adjust the size with -b. Reassemble on the receiving end:
Base64 Encoding for Text Channel Transfer
When the transfer channel only supports text — a web form, a command injection that returns output, a restricted shell — encode the archive as base64:
Copy the output, then decode on your attacker machine:
For large files, split before encoding:
Checking Archive Size
Know the size before choosing a transfer method. Files under a few MB can go over almost any channel. Anything over 50MB warrants a dedicated transfer method rather than a covert channel.
Cleaning Up
After successful transfer, remove the staged files:
/dev/shm/ is wiped on reboot anyway, but removing it immediately avoids leaving traces if the system is inspected before rebooting.
References
-
Linux man page Full reference for tar options including compression, exclusion patterns, and archive verification.
-
Linux man page Reference for splitting files by size or line count.
Was this helpful?
Your feedback helps improve this page.