ExecutionFile accessAnti-forensics
/tmp, /var/tmp and /dev/shm: Linux Staging Directories
World-writable Linux directories attackers use to stage tools: tmpfs versus disk, cleanup ages, noexec, memfd fileless execution and what survives reboot.
- Location
- /tmp, /var/tmp, /dev/shm, /run/user/<uid>
- Proves
- That files were dropped or run from world-writable locations, by which user and when
- Timestamps
- Inode times (mtime, ctime, atime, birth where supported) in the filesystem's native precision; tmpfs keeps them in RAM only
- Access
- Any user can write; root needed to read other users' files (mode 1777 with sticky bit)
- Retention
- tmpfs: lost at reboot; disk: until cleaned by systemd-tmpfiles ages (upstream 10 days /tmp, 30 days /var/tmp) or deleted
- Collection
- UAC, Velociraptor, tar, AVML
Tools
Compare all tools- findCLI · built into Linux
- statCLI · built into Linux
- debugfsCLI · built into Linux
- The Sleuth KitCLI · open source
- VelociraptorPlatform · open source
What it is
Every Linux system has directories that any user may write to: /tmp, /var/tmp and the shared-memory mount /dev/shm, plus per-user runtime directories under /run/user/<uid>. Attackers use them to download tools, unpack payloads, write scanner output and run binaries, because they are always present and usually writable even from a compromised web server account. The forensic value depends on one question first: is the directory on disk or on tmpfs (RAM)?
Where it lives
| Directory | Typical backing | Survives reboot | Notes |
|---|---|---|---|
/tmp | tmpfs on Fedora, Arch, openSUSE Tumbleweed and Debian 13 new installs; disk on Ubuntu, RHEL and Debian 12 and earlier | Only if on disk | Mode 1777 (sticky bit) |
/var/tmp | Disk on all mainstream distributions | Yes | Intended for files that persist across reboots |
/dev/shm | tmpfs (POSIX shared memory) | No | Frequently used for fileless staging |
/run/user/<uid> | tmpfs created per logged-in user by systemd-logind | No | Removed when the user's last session ends |
/run/lock, /var/lock | tmpfs | No | Occasionally abused |
Confirm on the host: findmnt /tmp /var/tmp /dev/shm (live) or /etc/fstab plus systemctl is-enabled tmp.mount and the files in /usr/lib/tmpfiles.d/, /etc/tmpfiles.d/ (image).
What it proves
- A file existed in a world-writable location, with its owner UID, permissions and timestamps: often the dropped tool itself.
- The executing account: files owned by
www-data,apacheornginxin/tmppoint to web application compromise. - Execution from these paths when correlated with /proc (
exe,cwd), shell history, auditEXECVErecords or cron entries. - Fileless execution: a process whose
/proc/<pid>/exepoints to/memfd:<name> (deleted)ran from an anonymous memory file created withmemfd_create, which never touches a directory at all. - Not proven: absence. Cleanup timers, reboots on tmpfs and attacker deletion all remove files routinely.
Key fields
| Item | Meaning |
|---|---|
| Owner UID / GID | Account that created the file |
| Mode | Executable bits on dropped files; setuid bits are a red flag |
| Hidden names | Leading dot, spaces, or names imitating system files (.X11-unix look-alikes, .ICE-unix) |
| Mount options | noexec, nosuid, nodev on /tmp and /dev/shm (hardening; noexec does not stop interpreters such as bash script or python file) |
| tmpfiles.d line | Type, path, mode, owner, age: q /tmp 1777 root root 10d in upstream systemd |
Timestamps
Disk-backed directories keep the normal inode times of their filesystem (nanosecond mtime, ctime, atime and birth time on ext4 and XFS v5; see ext4 timestamps). tmpfs also tracks these times, but only in memory; stat on a live system shows them, including birth time on recent kernels. systemd-tmpfiles ages files by their most recent atime, mtime and ctime, so reading a file can keep it alive.
Retention
- tmpfs (
/dev/shm,/run/user,/tmpwhere applicable): everything is lost at reboot or unmount. Capture live or through a memory image. - systemd-tmpfiles-clean.timer runs daily and removes entries older than the configured age. Upstream defaults are 10 days for
/tmpand 30 days for/var/tmp; Debian 13 adopts them for new installs, while upgraded Debian systems get an/etc/tmpfiles.d/tmp.confpreserving the old behaviour. Always read the actual configuration on the image. - Deleted files on disk may be recoverable from unallocated space or the filesystem journal for a while.
Collection
# live: list with full timestamps before anything is cleaned
find /tmp /var/tmp /dev/shm /run/user -xdev -printf '%M %u %g %s %TY-%Tm-%Td %TT %CY-%Cm-%Cd %CT %p\n' 2>/dev/null
# archive tmpfs content (it will not survive a reboot)
tar -cpzf /media/ir/host01-shm.tgz --xattrs /dev/shm /tmp
- UAC collects file listings (
bodyfile) across the filesystem and can copy suspicious files; its live-response process artifacts copy binaries of processes whose executable was deleted, which catches self-deleting droppers. - Velociraptor
Linux.Search.FileFinderorGeneric.Forensic.Timelineover these paths on many hosts. - Take memory (AVML or LiME) when
/dev/shmor memfd execution is suspected.
Parsing
On a disk image, build a timeline of the directories with The Sleuth Kit (fls -r -m / <image> > body; mactime -b body) or Plaso, then filter for /tmp, /var/tmp and deleted entries. debugfs -R 'stat <path>' on ext4 shows the four timestamps and the deletion time of a deleted inode.
Investigator tips
- Look for executables, ELF headers and scripts:
find /tmp /var/tmp /dev/shm -type f -perm -u+xandfileon each result. - Files owned by service accounts, especially the web server user, are strong indicators of initial access through an application.
- A
/tmpmountednoexecdoes not preventbash /tmp/x.shorpython3 /tmp/x.py; check how the file was executed. - Correlate file birth times with cron jobs and journal entries: droppers are often re-fetched by a scheduled task after cleanup.
- On live hosts,
ls -l /proc/*/exe | grep -E 'memfd|deleted'catches fileless and self-deleted binaries that no directory listing will show. - Remember the sticky bit: users can create files in
/tmpbut cannot delete other users' files there, so an attacker deleting root-owned files needed root.