Unit 5: Permissions · Lesson 3 of 6 · 14 min

Directory permissions

On a directory, r, w and x mean something different.

mission

You are
You are explaining a strange access pattern to a colleague.
Situation
You cannot list /srv/app, yet you could read a file inside it.
Goal
Work out why from the directory bits.

rwx on a directory

  1. rlist the names inside
  2. wcreate, rename and delete entries
  3. xenter it and reach files by name
01

Read the directory modes

learner@root-lab
stat -c '%A %U %G %n' /srv/app /srv/app/config
drwxr-x--x deploy ops /srv/app
drwxr-xr-x deploy ops /srv/app/config
ls /srv/app
ls: cannot open directory '/srv/app': Permission denied
ls /srv/app/config
app.env
db.env

you should see Others have only x on /srv/app: no listing, but a path you already know still works.

02

Least privilege done right

learner@root-lab
stat -c '%A %U %G %n' /etc/passwd /etc/shadow
-rw-r--r-- root root /etc/passwd
-rw-r----- root shadow /etc/shadow
cat /etc/shadow
cat: /etc/shadow: Permission denied

you should see Everyone can read the account list. Only root and the shadow group read the password hashes.

03

A drop box

Write and execute without read lets others put files in but not list what is there.

learner@root-lab
mkdir -p /tmp/dropbox && chmod 733 /tmp/dropbox
stat -c '%a %A %n' /tmp/dropbox
733 drwx-wx-wx /tmp/dropbox

you should see drwx-wx-wx: a one-way drop box.

What a defender takes away

  1. 1r lists, w changes entries, x lets you through.
  2. 2x without r hides names but not known paths.
  3. 3Hiding a directory is not a substitute for protecting its files.

Questions

0 of 1 solved

Answer each one from what you find on your lab machine.

  1. Show hint

    stat -c '%a' /srv/app