Welcome to Notes Time πŸ‘‹

Notes Time is your trusted platform for free study notes, tutorials, and guides designed to make learning simple, clear, and effective.

Whether you’re exploring Full Stack Web Development, mastering Cyber Security, or diving into Digital Marketing β€” we’ve got you covered with easy-to-understand content and practical examples.

Learn smarter, grow faster, and upskill with Notes Time β€” your digital study companion for tech and career success.

Subscribe to our newsletter and get our newest updates right on your inbox.

Privilege Escalation via Writable /etc/passwd & Shadow Abuse

By Himanshu Shekhar Β· 12 Feb 2026

Privilege Escalation via Writable /etc/passwd & Shadow Abuse

Privilege Escalation via Writable /etc/passwd & Shadow Abuse (Conceptual Overview)

/etc/passwd and /etc/shadow are the two most critical files for Linux user authentication. The passwd file maps usernames to user IDs (UIDs), while the shadow file stores encrypted password hashes. When these files have incorrect permissions, the entire system's authentication foundation is compromised.

⚠️ CRITICAL SECURITY WARNING: This section explains why these files must be strictly protected. No exploitation techniques are provided. World-writable passwd or readable shadow files are considered immediate, catastrophic security failures.

πŸ“„ What Are /etc/passwd and /etc/shadow?

πŸ“ /etc/passwd

Stores user account information:

  • Username
  • User ID (UID)
  • Group ID (GID)
  • Home directory
  • Login shell

Expected permission: -rw-r--r-- (644)
Owner: root
Group: root

πŸ”’ /etc/shadow

Stores secure password information:

  • Encrypted password hashes
  • Password aging information
  • Account expiration details

Expected permission: -rw-r----- (640) or -rw------- (600)
Owner: root
Group: shadow

πŸ’‘ Historical note: Very old Unix systems stored password hashes directly in /etc/passwd. Modern systems use shadow passwords to separate hash storage from public user data.

🧠 How Privilege Escalation Happens (High-Level)

πŸ“ Writable /etc/passwd
  • βœ” A non-root user has write access to /etc/passwd
  • βœ” User adds a new entry with UID 0 (root)
  • βœ” New user authenticates with known password
  • βœ” User gains persistent root access
πŸ”“ Readable /etc/shadow
  • βœ” A non-root user can read /etc/shadow
  • βœ” Password hashes are extracted
  • βœ” Hashes are cracked offline
  • βœ” Plaintext passwords are recovered
✍️ Writable /etc/shadow (Rare, Catastrophic)
  • βœ” User overwrites root hash with known password hash
  • βœ” Root password becomes attacker-controlled
🚨 Critical distinction: Unlike SUID or sudo misconfigurations, writable passwd or readable shadow files represent complete and immediate system compromise. No "exploitation" is requiredβ€”only file access.

πŸ”₯ Why These Misconfigurations Are Catastrophic

  • βœ” No exploit required – only file write/read capability
  • βœ” Persistent access – backdoors survive reboots
  • βœ” Complete control – attacker becomes root
  • βœ” Difficult to detect – new user may blend in
  • βœ” Immediate incident – assume breach, initiate IR

🌍 Real-World Example (Defensive View)

πŸ“‹ Scenario: Legacy Backup Script Misconfiguration

A system administrator writes a backup script that modifies file permissions for maintenance. Due to a logic error, the script executes:

chmod 666 /etc/passwd

The error is not noticed during the maintenance window. Any local user can now write to /etc/passwd. A non-privileged developer adds a new root user:

echo "hacker::0:0:root:/root:/bin/bash" >> /etc/passwd

The developer now has full, persistent root access to the system.

🚨 Defensive lesson: Never use wildcard chmod on system directories. Use configuration management to enforce correct permissions.

πŸ” Detecting Permission Misconfigurations

  • βœ” Automated file integrity monitoring – AIDE, Tripwire, Osquery
  • βœ” Permission auditing – Weekly checks of critical file permissions
  • βœ” User account reviews – Unexpected UID 0 entries
  • βœ” Configuration management – Ansible/Puppet enforcing baseline permissions

πŸ›‘οΈ Preventing Passwd/Shadow Privilege Escalation

πŸ”’ File Permission Hardening
  • βœ” chmod 644 /etc/passwd – root only write
  • βœ” chmod 640 /etc/shadow – root:shadow read
  • βœ” chown root:root /etc/passwd
  • βœ” chown root:shadow /etc/shadow
πŸ›‘οΈ System Hardening
  • βœ” File Integrity Monitoring (AIDE, Tripwire)
  • βœ” Immutable attribute: chattr +i /etc/passwd
  • βœ” Regular permission audits via cron
  • βœ” SELinux/AppArmor mandatory access controls
βœ… Golden rule: No user except root should ever have write access to /etc/passwd. No user except root and shadow group should ever read /etc/shadow.

🧾 Key Takeaways

  • βœ” /etc/passwd writable = immediate root backdoor
  • βœ” /etc/shadow readable = password hash exposure
  • βœ” /etc/shadow writable = root password replacement
  • βœ” These are permission failures, not vulnerability exploits
  • βœ” Prevention requires defense in depth and monitoring

πŸ” Passwd/Shadow – Command Awareness (Defensive Auditing)

Commands used by system administrators and security auditors to verify correct permissions on authentication files. Shown for defensive awareness only.

⚠️ Awareness only. These commands verify securityβ€”they do not exploit anything.

πŸ” Permission Verification Commands
  • Check /etc/passwd permissions
    ls -la /etc/passwd
    Expected: -rw-r--r-- (644)
  • Check /etc/shadow permissions
    ls -la /etc/shadow
    Expected: -rw-r----- (640) or -rw------- (600)
  • Check for world-writable passwd
    find /etc -name passwd -perm -o+w 2>/dev/null
    Should return NO results
  • Check for world-readable shadow
    find /etc -name shadow -perm -o+r 2>/dev/null
    Should return NO results

πŸ‘₯ User Account Auditing
  • List all users with UID 0 (root privileges)
    awk -F: '$3==0{print $1}' /etc/passwd
    Should only show "root". Any other user is suspicious.
  • Check for accounts without passwords
    awk -F: '($2=="" ){print $1}' /etc/shadow
    Empty password field = no authentication required
  • List all user accounts with valid shells
    grep -v "/nologin\|/false" /etc/passwd
    Identify interactive user accounts

πŸ“Š File Integrity Monitoring
  • Check file checksum (detect modifications)
    md5sum /etc/passwd /etc/shadow
    Compare against known-good baseline
  • Set immutable attribute (prevent modification)
    chattr +i /etc/passwd /etc/shadow
    Even root must remove immutable flag first
  • Check immutable attribute status
    lsattr /etc/passwd /etc/shadow
    "i" indicates immutable

πŸ›‘οΈ Remediation Commands (Defensive)
  • Fix /etc/passwd permissions
    sudo chmod 644 /etc/passwd
    sudo chown root:root /etc/passwd
  • Fix /etc/shadow permissions
    sudo chmod 640 /etc/shadow
    sudo chown root:shadow /etc/shadow
  • Remove unauthorized UID 0 user
    sudo userdel -r unauthorized_user

πŸ›‘οΈ Defender Takeaways
  • βœ” Audit weekly: Check permissions on /etc/passwd and /etc/shadow
  • βœ” Monitor: Alert on any modification to these files
  • βœ” Harden: Consider immutable flag on production systems
  • βœ” Verify: Only one UID 0 account should exist
βœ… Correct permissions + file integrity monitoring + immutable flag = complete protection against passwd/shadow privilege escalation.
πŸ“š

πŸ“š Related Blogs

Privilege Escalation via Docker / Container Escapes

By Himanshu Shekhar Β· 12 Feb 2026

Privilege Escalation via Docker / Container Escape...

Privilege Escalation via Weak File Permissions & Group Membership Abuse

By Himanshu Shekhar Β· 12 Feb 2026

Privilege Escalation via Weak File Permissions & G...

Privilege Escalation via Linux Capabilities

By Himanshu Shekhar Β· 10 Feb 2026

Privilege Escalation via Linux Capabilities (Conce...

Privilege Escalation via SUID (Conceptual Guide)

By Himanshu Shekhar Β· 10 Feb 2026

Privilege Escalation via SUID (Conceptual Overview...

DC-1 VulnHub: Drupal 7 Exploitation and SUID Privilege Escalation

By Himanshu Shekhar Β· 10 Feb 2026

DC-1 VulnHub Walkthr...

Privilege Escalation via Misconfigured NFS

By Himanshu Shekhar Β· 10 Feb 2026

Privilege Escalation via Misconfigured NFS (Concep...

Privilege Escalation via PATH Variable Manipulation

By Himanshu Shekhar Β· 10 Feb 2026

Privilege Escalation via PATH Variable Manipulatio...

Privilege Escalation via Cron Jobs

By Himanshu Shekhar Β· 10 Feb 2026

Privilege Escalation via Cron Jobs...

TryHackMe BLOG Room – Full Walkthrough

By Himanshu Shekhar Β· 10 Feb 2026

πŸ§ͺ TryHackMe – BLOG Room (Full Lab Walkthrough)...

Active Directory Domain Services – Setup Windows Server Conceptual

By Himanshu Shekhar Β· 10 Feb 2026

πŸ› οΈ Step-by-Step: Set...

Privilege Escalation via Kernel Vulnerabilities

By Himanshu Shekhar Β· 10 Feb 2026

Privilege Escalation via Kernel Vulnerabilities...

Privilege Escalation via Sudo Misconfiguration

By Himanshu Shekhar Β· 10 Feb 2026

Privilege Escalation via Sudo (Conceptual Overv...

+