learn/phase-3/p3-w12/lesson 05
Milestone 12 · lesson 5

Weak Permissions & Credential Hunting

Hands-on. Two of the easiest privesc wins: files with the wrong permissions, and passwords left lying around.
Lab: Creds in Plain Sight

Hunt the filesystem for a password a careless user left behind.

What you'll learn

  • Find and abuse dangerously-permissioned files: a writable /etc/passwd, a readable /etc/shadow.
  • Hunt for credentials in config files, history, backups, and SSH keys.
  • Grep a whole filesystem for passwords and secrets efficiently.
  • Turn a found password into higher access by reusing it (su, ssh).

Weak Permissions & Credential Hunting

Not every privesc needs a clever exploit. Two of the most reliable wins are just carelessness: a file with the wrong permissions, or a password someone left lying around. On real boxes these find root more often than any CVE.

Part 1: weak file permissions

A permission bit in the wrong place is a direct path up. The big ones to check:

A writable /etc/passwd

/etc/passwd defines every account. If your user can write to it, you can add your own root account. Historically it can even hold a password hash in the second field:

$ ls -l /etc/passwd
-rw-rw-rw- 1 root root ...          # world-writable, jackpot
$ openssl passwd -1 hacked          # make a hash
$1$xyz$Q9....
# add a uid-0 user with that hash:
$ echo 'pwn:$1$xyz$Q9....:0:0:root:/root:/bin/bash' >> /etc/passwd
$ su pwn        # password: hacked  ->  you are root (uid 0)

A readable /etc/shadow

/etc/shadow holds the password hashes and is normally root-only. If it's readable, copy root's hash and crack it offline:

$ cat /etc/shadow | grep root
root:$6$....:19700:...
# crack it with a wordlist:
$ john --wordlist=/usr/share/wordlists/rockyou.txt shadow.txt

Writable service/config files

A config or script that a root service reads or runs, and that you can write, is the same idea as the cron case: change it, and your code runs as root.

Part 2: credential hunting

Passwords hide in plain sight all over a system. Look everywhere:

WhereWhat you'll find
~/.bash_history, ~/.mysql_historycommands with passwords pasted in
/var/www, app config (.env, wp-config.php, config.php, database.yml)DB and API credentials
~/.ssh/id_rsa, authorized_keysprivate keys to log in elsewhere
backups (*.bak, *.sql, *.tar.gz)dumps full of data and creds
/etc/fstab, mounted sharesstored mount passwords
environment (env, /proc/*/environ)secrets passed to services

The grep sweep

grep -riI "password" / 2>/dev/null            # the whole box, ignore binaries & errors
grep -riI "password\|passwd\|secret\|api_key\|token" /var/www /home /opt 2>/dev/null
cat ~/.bash_history                            # what did this user actually type?
find / -name "id_rsa" -o -name "*.pem" 2>/dev/null   # private keys
find / -name "*.env" -o -name "config.php" 2>/dev/null

The payoff: password reuse

People reuse passwords. A database password from a .env is often also the root password, or another user's, or works on another host:

su root                 # try the found password as root
su otheruser            # or as another user
ssh admin@10.0.0.30     # or on another box (lateral movement)

The fix (what you report)

Lock down permissions (/etc/shadow 640 root:shadow, /etc/passwd 644, configs 600), never store plaintext secrets in world-readable files, use a secrets manager, and never reuse passwords across accounts and hosts. Report the exact file, its permissions, and the credential it exposed.

Common questions

"Isn't editing /etc/passwd outdated? Passwords are in /etc/shadow now." Right, real accounts keep their hash in /etc/shadow. But /etc/passwd still accepts a hash in its second field for backward compatibility. So if /etc/passwd is writable, you add a brand-new uid-0 line with your own hash, that's a valid root account, no need to touch /etc/shadow at all.

"I found a hash. How do I know if it's crackable?" Look at the prefix: $1$ (MD5) and $6$ (SHA-512) are crackable with john/hashcat given a good wordlist, weak passwords fall fast, strong ones may never. Cracking isn't guaranteed; it's a bet on the password being weak. If it resists, pivot to another vector.

"Where's the single best place to look for passwords?" Shell history (~/.bash_history) and app config files (.env, wp-config.php, config.php) pay off most often, people paste live credentials into both constantly. After that, private SSH keys (~/.ssh/id_rsa) and backup files.

"I found a password but su root says 'Authentication failure'. Did I waste my time?" Not necessarily, try it everywhere else. People reuse passwords, so a DB password might be another user's login (su otheruser) or work on a different host (ssh admin@10.0.0.30). One found password is a key you try in every lock.

Why this matters

The flashy exploits get the headlines, but a readable config file or a password in someone's shell history is what actually ends most engagements. It costs nothing, leaves almost no trace, and works constantly. After SUID and cron, the credential sweep is the third thing to run on every box.

Check your understanding

5 questions

Type an answer and press Check. Grading is keyword-based and forgiving, so short answers are fine.

  1. 1

    Write a recursive grep that searches the whole filesystem for the word 'password' (case-insensitive), ignoring errors.

  2. 2

    Which two files would you read first to find a user's recently typed commands and any secrets in them?

  3. 3

    You find /etc/shadow is world-readable. What do you do with it to get root?

  4. 4

    You find /etc/passwd is writable by your user. Write the openssl command that generates a password hash you could paste in to add a root account.

  5. 5

    Write a find command that locates private SSH keys anywhere on the box.