← All lessons Stage 1 · Lesson 2
15 min

Files, permissions and users

Stage 1 · Lesson 2 · 15 minutes · Requires Lesson 1


The one-line answer

Every file records who owns it and what each class of user may do with it. Nearly every Linux privilege escalation is a permission that was set too loosely.


Why you should care

Stage 0 taught you that the server enforces authorisation for web applications. This is the same idea one layer down — the operating system deciding who can read, write and execute what.

When you compromise a low-privilege account and need to become root, you are hunting for a permission mistake. When you defend a server, you are preventing one. This lesson is the foundation of both.


How it actually works

Reading ls -l

-rw-r--r--  1 priya  staff   2048  Feb 14 09:12  notes.txt
drwxr-xr-x  3 priya  staff   4096  Feb 14 08:00  projects
-rwxr-xr-x  1 root   root    8192  Jan 02 11:30  backup.sh

Take the first field apart:

- rw- r-- r--
│ │   │   │
│ │   │   └─ others: everyone else
│ │   └───── group: members of the file's group
│ └───────── owner: the file's owner
└─────────── type: - file, d directory, l symlink

Three permissions per class:

LetterOn a fileOn a directory
rread contentslist contents
wmodify contentscreate and delete files inside
xexecute itenter it with cd

The directory column surprises people. Write permission on a directory lets you delete files inside it — including files you do not own and cannot even read. That is a genuine escalation path, not a technicality.

Numeric permissions

Each permission has a value: r=4, w=2, x=1. Add them per class.

rwx = 4+2+1 = 7
rw- = 4+2   = 6
r-x = 4+1   = 5
r-- = 4     = 4
NumericSymbolicMeaning
644rw-r--r--Owner edits, everyone reads
600rw-------Owner only — correct for keys and secrets
755rwxr-xr-xOwner edits, everyone runs
700rwx------Owner only, executable
777rwxrwxrwxEveryone can do everything — almost always wrong
chmod 600 ~/.ssh/id_rsa      # correct for a private key
chmod 755 script.sh          # runnable by anyone
chmod +x script.sh           # add execute, leave the rest alone

chmod 777 is the most common insecure fix in the world. Someone hits a permission error, applies 777, the error disappears, and a world-writable file is left behind permanently. If that file is a script root runs on a schedule, every user on the system can now execute code as root.

Users, groups and root

whoami          # current user
id              # UID, GID, and all group memberships
groups          # groups you belong to

Typical output:

uid=1001(priya) gid=1001(priya) groups=1001(priya),27(sudo),999(docker)

Read that carefully. sudo means this user can become root. And docker is quietly equivalent — anyone in the docker group can mount the host filesystem inside a container and read or write anything on it. Docker group membership is effectively root access, and a great many administrators do not realise it.

Root is UID 0 and bypasses permission checks entirely.

sudo runs one command as another user, normally root, and logs it. Its configuration lives in /etc/sudoers.

sudo -l         # what may I run with sudo?

sudo -l is among the first commands run after gaining any foothold. If it reports that you may run /usr/bin/vim as root without a password, that is game over — vim can spawn a shell from inside itself.

The account files

/etc/passwd — world-readable, one line per account:

priya:x:1001:1001:Priya S:/home/priya:/bin/bash

Username, x (password stored elsewhere), UID, GID, description, home directory, login shell.

A shell of /usr/sbin/nologin means the account cannot log in interactively — normal for service accounts. An unexpected account with /bin/bash and UID 0 is a backdoor, because UID 0 is root regardless of the username.

/etc/shadow — root-readable only, holds the actual password hashes:

priya:$6$xyz...:19800:0:99999:7:::

The $6$ prefix indicates SHA-512. $y$ is yescrypt, $2b$ is bcrypt. If a non-root user can read /etc/shadow, that is a critical finding — those hashes can be taken offline and attacked at leisure, exactly as described in Stage 0 Lesson 6.

SUID and SGID

A binary with the SUID bit runs as its owner, not as whoever launched it.

-rwsr-xr-x  1 root  root  68208  Jan 12 10:00  /usr/bin/passwd
   ↑
   s instead of x

passwd must write to /etc/shadow, which only root may do — so it runs as root even when you launch it. That is legitimate and necessary.

The danger is SUID on the wrong binary. If find, vim, python or bash carries SUID root, any user obtains a root shell in a single command.

find / -perm -4000 -type f 2>/dev/null

That command is run on essentially every Linux privilege escalation attempt. Compare results against what is normal. The site GTFOBins catalogues which binaries can be abused this way and the exact syntax for each.

The sticky bit

drwxrwxrwt  10 root root 4096 Feb 14 09:00 /tmp
         ↑

The t on a world-writable directory restricts deletion to file owners. Without it, anyone could delete anyone's files in /tmp.


See it yourself

ls -l /etc/passwd /etc/shadow

Note the difference: /etc/passwd is 644, /etc/shadow is 640 or 000 and owned by root. That single design decision is why password hashes are not casually readable by every process on the system.

id
sudo -l
find / -perm -4000 -type f 2>/dev/null | head -20

Look at that SUID list. Most entries are expected — passwd, sudo, mount, ping. Learning what normal looks like is the only way to recognise abnormal, and that principle carries through the entire blue team side of this field.

Now watch permissions change:

mkdir permtest && cd permtest
touch secret.txt
chmod 600 secret.txt && ls -l secret.txt
chmod 777 secret.txt && ls -l secret.txt
chmod 644 secret.txt && ls -l secret.txt

How attackers abuse this

World-writable scripts run by root. A cron job executes /opt/backup.sh as root every hour. The file is 777. Any user appends a reverse shell to it and waits. This is one of the most common privilege escalation paths in production, and it is always a configuration mistake rather than a software vulnerability.

Misconfigured SUID binaries. A developer sets SUID on a Python interpreter to "make a script work." Any user now runs arbitrary code as root in one line.

Dangerous sudo rules. sudo -l reveals permission to run a text editor, an interpreter, or tar as root. All of these can spawn shells or write arbitrary files. Restricting which binary someone may run as root is not the same as restricting what they may do.

Readable credentials. .env files at 644, config files with database passwords, private keys with group read access, .git/config containing tokens. Enormous numbers of real compromises escalate purely by reading files that were never meant to be readable.

Group membership as a backdoor. Adding a user to docker, lxd, disk or adm grants far more than it appears to. These are frequently overlooked in access reviews.

Writable directories in PATH. If a directory you can write to appears in root's PATH before /usr/bin, you place a malicious ls there and wait for an administrator to run it.


Common mistakes

"777 fixes permission errors." It removes the error and creates a vulnerability. The correct fix is identifying which user needs which access and granting exactly that.

"Only root can be dangerous." Group memberships, SUID binaries and sudo rules all provide paths from an ordinary account to root. The account you compromise is rarely the account you finish with.

"Permissions on the file are enough." Directory permissions matter independently. A read-only file inside a writable directory can still be deleted and replaced.

"It is an internal server, permissions matter less." Internal servers are exactly where lateral movement happens after an initial foothold. Stage 0 Lesson 1 covered why private addresses are not protection.


Check yourself

  1. A file is -rw-r--r-- root root inside a directory that is drwxrwxrwx. Can an ordinary user change the file's contents?
  2. sudo -l reports you may run /usr/bin/find as root without a password. Why is that a serious problem?
  3. Why is membership of the docker group roughly equivalent to root access?
Answers
  1. Not directly — the file itself is only writable by root. But the user can delete it and create a replacement, because write permission on a directory controls creation and deletion of its entries. The practical effect is the same as modifying it, which is why directory permissions must be considered alongside file permissions.
  1. find has an -exec flag that runs arbitrary commands. Running sudo find . -exec /bin/bash \; spawns a root shell immediately. Restricting a user to one specific binary is only meaningful if that binary cannot execute other things — and many common utilities can.
  1. Docker containers can mount host filesystem paths. A user in the docker group can start a container mounting / and read or modify any file on the host, including /etc/shadow and /etc/sudoers, entirely bypassing the permission system. The group is a root-equivalent privilege that does not look like one on an access review.

Your lab

Challenge 06 — Navigate a Linux filesystem

The flag is protected by permissions. Read the filesystem carefully, and pay attention to what is readable and by whom.

→ Open Stage 1 labs


Summary in your language

தமிழ் சுருக்கம் (Tamil summary)

File permissions — Linux பாதுகாப்பின் அடிப்படை

ஒவ்வொரு file-ம் யாருக்கு சொந்தம், யார் என்ன செய்யலாம் என்பதைப் பதிவு செய்கிறது.

-rw-r--r--   priya  staff   notes.txt
 │  │  │
 │  │  └─ others (மற்ற அனைவரும்)
 │  └──── group (குழு)
 └─────── owner (உரிமையாளர்)
  • r = படிக்க (4)
  • w = எழுத (2)
  • x = இயக்க (1)

முக்கியமான எண்கள்:

  • 600 — உரிமையாளர் மட்டும் ← key, password-க்கு இதுதான் சரி
  • 644 — உரிமையாளர் எழுதலாம், அனைவரும் படிக்கலாம்
  • 755 — உரிமையாளர் எழுதலாம், அனைவரும் இயக்கலாம்
  • 777 — அனைவரும் எல்லாம் செய்யலாம் — கிட்டத்தட்ட எப்போதும் தவறு

chmod 777 — உலகின் மிகப் பொதுவான பாதுகாப்புத் தவறு

permission error வந்ததும் பலர் 777 கொடுத்து சரிசெய்கிறார்கள். error போய்விடும், ஆனால் அந்த file-ஐ அனைவரும் மாற்ற முடியும். அந்த file-ஐ root ஓட்டினால், அனைவரும் root ஆக முடியும்.

முக்கியமான commands:

id              # நான் யார், எந்த குழுக்களில் இருக்கிறேன்
sudo -l         # நான் எதை root-ஆக ஓட்ட முடியும்
find / -perm -4000 -type f 2>/dev/null   # SUID files

SUID என்றால் என்ன?

சில programs அவற்றின் உரிமையாளராக இயங்கும் — யார் ஓட்டினாலும். passwd command root-ஆக இயங்குகிறது, ஏனெனில் அது /etc/shadow-ல் எழுத வேண்டும். இது சரியானது.

ஆனால் vim, python, find போன்றவற்றுக்கு SUID root இருந்தால் — எந்த user-ம் ஒரே command-ல் root ஆகிவிடலாம்.

கவனிக்க வேண்டியவை:

  • /etc/passwd — அனைவரும் படிக்கலாம் (accounts பட்டியல்)
  • /etc/shadow — root மட்டும் (password hashes) ← இதை நீங்கள் படிக்க முடிந்தால் அது critical finding
  • docker group-ல் இருப்பது root-க்கு சமம் — பலருக்கு இது தெரியாது

எதற்காக இதைக் கற்கிறோம்?

ஒரு system-ல் சாதாரண user-ஆக நுழைந்த பிறகு root ஆக மாற வேண்டும் என்றால் — நீங்கள் தேடுவது ஒரு permission தவறை. இதைத்தான் privilege escalation என்பார்கள்.

हिंदी सारांश (Hindi summary)

File permissions — Linux सुरक्षा की नींव

हर file यह दर्ज करती है कि उसका मालिक कौन है और कौन क्या कर सकता है।

-rw-r--r--   priya  staff   notes.txt
 │  │  │
 │  │  └─ others (बाक़ी सब)
 │  └──── group (समूह)
 └─────── owner (मालिक)
  • r = पढ़ना (4)
  • w = लिखना (2)
  • x = चलाना (1)

ज़रूरी संख्याएँ:

  • 600 — सिर्फ़ मालिक ← keys और passwords के लिए यही सही है
  • 644 — मालिक लिखे, सब पढ़ें
  • 755 — मालिक लिखे, सब चलाएँ
  • 777 — सब कुछ कर सकते हैं — लगभग हमेशा ग़लत

chmod 777 — दुनिया की सबसे आम सुरक्षा ग़लती

permission error आते ही लोग 777 लगा देते हैं। error चला जाता है, लेकिन अब उस file को कोई भी बदल सकता है। अगर उसे root चलाता है, तो कोई भी root बन सकता है।

ज़रूरी commands:

id              # मैं कौन हूँ, किन groups में हूँ
sudo -l         # मैं root बनकर क्या चला सकता हूँ
find / -perm -4000 -type f 2>/dev/null   # SUID files

SUID क्या है?

कुछ programs अपने मालिक की हैसियत से चलते हैं — चलाने वाला कोई भी हो। passwd command root बनकर चलती है क्योंकि उसे /etc/shadow में लिखना होता है। यह सही है।

लेकिन अगर vim, python या find पर SUID root लगा हो — कोई भी user एक ही command में root बन सकता है।

ध्यान देने योग्य बातें:

  • /etc/passwd — सब पढ़ सकते हैं (accounts की सूची)
  • /etc/shadow — सिर्फ़ root (password hashes) ← अगर आप इसे पढ़ पा रहे हैं तो यह critical finding है
  • docker group में होना root के बराबर है — बहुत से लोग यह नहीं जानते

यह क्यों सीख रहे हैं?

किसी system में सामान्य user बनकर घुसने के बाद root बनना हो — तो आप एक permission ग़लती ही ढूँढ रहे होते हैं। इसी को privilege escalation कहते हैं।

Want this summary in Malayalam, Telugu, Kannada or another language? Tell us — the most requested languages get added next.


What's next

You understand a single machine. Now the network between machines — what actually travels, and what a defender sees when they look at it.

→ Lesson 3: TCP/IP without the textbook