World-writable web files (777)
HighL06Linux serversFind files and folders anyone can write to and tighten them so other accounts…
What is the risk
Files writable by others (777 and similar) can be changed by any account on the server. If another site on the same server is hacked, it can plant a web shell in yours.
People often set 777 to get an install working and forget about it.
How to check
Linux
sudo find /var/www -perm -0002 \( -type f -o -type d \) -lsHow to fix
Linux
sudo find /var/www -type d -perm -0002 -exec chmod o-w {} +
sudo find /var/www -type f -perm -0002 -exec chmod o-w {} +This removes write access for others only. Usually 755 for folders and 644 for files is enough.
Give write access to the web server account (www-data on Debian and Ubuntu, apache or nginx on RHEL) only for upload and cache folders. Let a deploy account own the code.
How to prevent it
- Even if an install guide says 777, do it for that one folder only and undo it afterwards.
- Keep the deploy account and the web server account separate.
Check again after fixing
Linux
sudo find /var/www -perm -0002 \( -type f -o -type d \) -lsNo output means it is fixed.
Run the downloaded check again and make sure this item passes.