Weak File Permissions for Linux Privilege Escalation
World-writable or group-writable files that are executed or read by root are a direct escalation path. This includes scripts in cron jobs, service configs, init scripts, environment files, and sudo helper scripts. No exploit required — write the file, wait for root to execute it.
Prerequisites Check
Run a broad writable file search immediately — this catches misconfigurations that automated tools sometimes miss:
Also check files writable by your group:
Scripts Executed by Root
The highest impact target — any writable script that root runs via cron, systemd, or init:
If writable, inject payload:
Wait for execution, then:
/etc/rc.local
/etc/rc.local runs at boot as root. If writable:
In labs and CTF boxes this is frequently left world-writable. It fires on the next reboot — in exam contexts, the box may be rebooted as part of the scenario.
/etc/environment and /etc/profile
These files are sourced at login and affect all users including root. If writable, inject a command or PATH manipulation:
For the LD_PRELOAD injection technique see https://hackindex.io/platforms/linux/privilege-escalation/ld-preload-environment-hijacking.
/etc/sudoers and /etc/sudoers.d/
If writable, add a passwordless sudo rule for your user:
Test immediately:
Writable /etc/passwd or /etc/shadow
Covered in detail at https://hackindex.io/platforms/linux/privilege-escalation/passwd-shadow-manipulation.
Quick check:
World-Writable Directories in Execution Paths
A world-writable directory in PATH is more valuable than a writable file — you can create any binary name there:
# Check directories in PATH
echo $PATH | tr ':' '\n' | while read dir; do
[ -w "$dir" ] && echo "WRITABLE PATH DIR: $dir"
done
# Check system-wide PATH
grep "PATH=" /etc/environment /etc/profile 2>/dev/null | tr ':' '\n' | while read dir; do
[ -w "$dir" ] && echo "WRITABLE SYSTEM PATH: $dir"
done
See https://hackindex.io/platforms/linux/privilege-escalation/writable-path-hijacking for the full PATH hijacking workflow.
Writable Python/Perl/Ruby Libraries
If root runs interpreter scripts and the library directory is writable:
See https://hackindex.io/platforms/linux/privilege-escalation/python-library-hijacking for Python-specific exploitation.
Automated Detection
LinPEAS detects most writable file issues automatically:
Look for the "Interesting writable files owned by me or writable by everyone" section in the output.
Also use find directly with tee to save results:
Cross-reference against files executed by root processes using pspy. See https://hackindex.io/platforms/linux/privilege-escalation/privilege-escalation-enumeration-tools.
References
-
find(1) Manualman7.org/linux/man-pages/man1/find.1.html (opens in new tab)
Permission-based file searching with -writable, -perm, and -group flags.
-
sudoers(5) Manualman7.org/linux/man-pages/man5/sudoers.5.html (opens in new tab)
sudoers.d directory inclusion and rule syntax.
Was this helpful?
Your feedback helps improve this page.