Executables in temp folders
HighL11Linux serversFind executables hiding in /tmp, /dev/shm or /var/tmp and stop programs from…
What is the risk
Temp folders are writable by everyone, so they are the first place attackers drop and run their tools.
Miners and backdoors also hide in places like /dev/shm that are wiped on reboot.
How to check
Linux
sudo find /tmp /var/tmp /dev/shm -type f -perm -u+x -ls 2>/dev/null
sudo ls -l /proc/*/exe 2>/dev/null | grep -E '/tmp|/dev/shm|deleted'The second line shows programs running from temp folders or still running after being deleted.
How to fix
Linux
sudo mkdir -p /root/evidence
sudo cp -p /tmp/suspect /root/evidence/
sudo kill 1234
sudo rm /tmp/suspectCopy it first, stop it if it is running, then delete it (replace suspect and 1234 with what you found). Find the way in as well (same as L10).
Linux
tmpfs /dev/shm tmpfs defaults,nodev,nosuid,noexec 0 0
sudo mount -o remount,nodev,nosuid,noexec /dev/shmAdd the first line to /etc/fstab and apply it now with the second. /tmp can be done the same way, but some installers need to run from /tmp, so test first.
How to prevent it
- Use disable_functions so web PHP cannot start a shell (P04).
- Treat unknown processes that use a lot of CPU for a long time as suspicious (top).
Check again after fixing
Linux
sudo find /tmp /var/tmp /dev/shm -type f -perm -u+x -ls 2>/dev/null
findmnt /dev/shmnoexec should appear in the options on the second line.
Run the downloaded check again and make sure this item passes.