Lab 09: Linux Security Basics
🎯 Objective
Master Linux file permissions as a security mechanism: understand rwx bits, SUID/SGID, sticky bit, find world-writable files, and understand why /tmp is a security risk.
📚 Background
Linux uses a discretionary access control (DAC) model for file permissions. Every file has an owner, a group, and permissions for three classes: owner (u), group (g), and others (o). Each class has read (r=4), write (w=2), and execute (x=1) bits. So chmod 755 sets owner=rwx(7), group=r-x(5), others=r-x(5).
SUID (Set User ID) is a special permission bit. When set on an executable, it runs with the file owner's privileges rather than the executing user's. For example, /usr/bin/passwd has SUID set and is owned by root — allowing regular users to change their own passwords (which requires writing to /etc/shadow). Attackers look for SUID binaries they can abuse to escalate privileges.
SGID (Set Group ID) is similar but for groups. On directories, SGID ensures new files inherit the directory's group. Sticky bit on directories means only the file owner can delete their files, even if the directory is world-writable — this is why /tmp has the sticky bit (so users can't delete each other's temp files).
World-writable files (permissions 777 or o+w) are accessible by every user — a significant security risk. World-writable scripts in cron jobs are a classic privilege escalation path.
⏱️ Estimated Time
40 minutes
📋 Prerequisites
Basic Linux command line
Docker with
innozverse-cybersecimage
🛠️ Tools Used
ls -la— List permissionschmod,chown— Modify permissionsfind— Find files by permissionstat— Detailed file metadata
🔬 Lab Instructions
Step 1: Understanding File Permissions
📸 Verified Output:
💡 What this means:
/etc/passwdis readable by everyone (r--for others) — it contains usernames but not passwords./etc/shadowis only readable by root and the shadow group (r-----) — it contains password hashes. This design separates what's needed for user lookup from what's sensitive.
Step 2: Permission Bits in Detail
📸 Verified Output:
💡 What this means: The
sin SUID (rwsr-xr-x) indicates the SUID bit is set. When you execute this file, it runs as the file's owner (often root), not as you. This is the primary way attackers escalate from regular user to root — finding vulnerable SUID files.
Step 3: Find SUID Files
📸 Verified Output:
💡 What this means: These SUID binaries are legitimate —
/usr/bin/passwdneeds SUID to write to /etc/shadow as root. However, if an attacker can exploit a vulnerability insuormount, they get root. Tools like GTFOBins (gtfobins.github.io) catalog SUID binary abuses. Thetat the end of/tmp's permissions is the sticky bit.
Step 4: Demonstrate File Permission Changes
📸 Verified Output:
💡 What this means: SSH private keys MUST be
400or600— SSH will refuse to use them if they're world-readable. This is a built-in security check. If you accidentally expose a private key, rotate it immediately.
Step 5: Find World-Writable Files
📸 Verified Output:
💡 What this means: This is a classic privilege escalation path in CTF challenges and real penetration tests. If a cron job run by root executes a world-writable script, any user can modify that script to run arbitrary code as root. Always check cron jobs and their target script permissions during security audits.
Step 6: umask — Default Permission Mask
📸 Verified Output:
💡 What this means:
umask 022is the standard default — group and others get read but not write. Settingumask 077in user shell profiles makes all new files private by default. Sensitive applications like SSH key generation should use a restrictive umask.
Step 7: /tmp Security Risks
📸 Verified Output:
💡 What this means: The
t(sticky bit) prevents users from deleting each other's files in /tmp. But symlink races are still possible: an attacker creates/tmp/target_filenameas a symlink to/etc/sudoersbefore a root script creates the file — the root script then overwrites sudoers! Usemktempfor random unpredictable filenames.
Step 8: Linux User and Group Security
📸 Verified Output:
💡 What this means: Only
rootshould have UID 0. Multiple UID 0 accounts is a serious backdoor indicator. System accounts use/usr/sbin/nologinas their shell — they can't be logged into interactively, only used by services. Thexin the password field means the actual hash is in /etc/shadow.
Step 9: File Capabilities (Alternative to SUID)
📸 Verified Output:
💡 What this means: Linux capabilities split root's omnipotent privileges into ~40 distinct capabilities. If Python3 had
cap_setuidorcap_dac_override, an attacker with code execution could escalate to root. Always audit capabilities withgetcap -r / 2>/dev/nullduring security assessments.
Step 10: Security Audit Script
📸 Verified Output:
💡 What this means: This mini-audit checks the most common security issues. No world-writable files in /etc is good. 8 SUID files is a reasonable count for a standard installation. This is what automated tools like LinPEAS and LinEnum do comprehensively — run during post-exploitation to find privilege escalation paths.
✅ Verification
📸 Verified Output:
🚨 Common Mistakes
Forgetting that SUID on scripts is mostly ignored: Linux ignores SUID on interpreted scripts for security. Only binaries honor SUID.
World-writable directories in PATH: If any directory in $PATH is world-writable, attackers can plant malicious binaries.
Confusing /tmp sticky bit with security: The sticky bit prevents deletion, but world-writable /tmp still allows creating/reading files — never store sensitive data in /tmp.
📝 Summary
Linux file permissions (rwx for owner/group/others) are the foundation of access control; misconfigured permissions are a leading privilege escalation vector
SUID/SGID bits run programs with the file owner's/group's privileges; audit SUID files regularly against a known-good baseline
World-writable files and directories are dangerous — especially if executed by privileged processes (cron, systemd)
/tmp is world-writable but sticky — use mktemp for random filenames; never store sensitive data there without encryption
🔗 Further Reading
Last updated
