Linux Deep Dive I
Filesystem, permissions, processes, and the way in
- › Navigate the Linux filesystem and know which directories matter to an attacker
- › Read and reason about permissions in both symbolic and octal form
- › Explain SUID, SGID, and the sticky bit, and why SUID is a privilege-escalation goldmine
- › Inspect users, groups, and running processes to understand who can do what
Why Linux, and why this deep
The overwhelming majority of servers you will ever attack run Linux. When you get a foothold, you land in a shell on a Linux box, usually as a low-privileged user, and everything you do next — find secrets, escalate to root, pivot onward — is Linux fluency. Most people "know Linux" the way a tourist knows a city. You need to know it like a local who understands why the streets are laid out the way they are. This lesson is that local's map.
The organising idea of the whole system is simple and worth saying once, plainly: on Linux, almost everything is a file, and every file has an owner and a set of permissions. Master files and permissions and you understand access control, which is what privilege escalation is all about.
The filesystem is a single tree
There are no drive letters. Everything hangs off one root, /, and each directory has a purpose defined by the Filesystem Hierarchy Standard. You don't need all of it; you need the handful an attacker cares about:
| Path | What lives there | Why you care |
|---|---|---|
| /etc | System configuration (text files) | /etc/passwd (users), /etc/shadow (password hashes), service configs, secrets |
| /home/<user> | A user's personal files | SSH keys, .bash_history, notes, credentials people leave lying around |
| /root | The root user's home | The prize; usually only readable once you're root |
| /var | Variable data: logs, web roots, mail | /var/www (web app source & configs), /var/log (traces of you) |
| /tmp, /dev/shm | World-writable scratch space | Where you drop your tools and payloads — everyone can write here |
| /usr/bin, /bin | Installed programs | The binaries you'll abuse; SUID ones especially |
| /proc | A live view of the kernel & processes | /proc/<pid> reveals a process's command line, environment, open files |
/etc deserve memorising. `/etc/passwd` is world-readable and lists every account (username, UID, home, shell) — reconnaissance in one cat. `/etc/shadow` holds the password *hashes* and is readable only by root. The day you can read /etc/shadow, you can crack passwords offline — which is why gaining read access to it is a milestone worth recognising.Permissions: the ten characters that govern everything
Run ls -l and every file begins with something like -rwxr-xr--. Those ten characters are the entire access-control decision for that file. Read them in four chunks:
- rwx r-x r--
| | | |
| | | +-- OTHERS (everyone else): read only
| | +--------- GROUP (the file's group): read + execute
| +---------------- OWNER (the file's user): read + write + execute
+--------------------- TYPE ( - file · d directory · l symlink )
r = read (4) w = write (2) x = execute (1)So the same permissions have two notations, and you must be fluent in both because tools speak different ones:
- Symbolic:
rwxr-xr--— human-readable, whatls -lshows. - Octal: add the bits per chunk.
rwx= 4+2+1 = 7,r-x= 4+0+1 = 5,r--= 4+0+0 = 4. Sorwxr-xr--= 754, which is whatchmod 754 filesets.
For a directory, the bits mean something slightly different and it trips everyone up: `x` on a directory means "you may enter it" (cd into it, access files inside by name), while `r` means "you may list its contents." You can sometimes access a file inside a directory you cannot list — if you already know the filename and have x on the directory. Attackers exploit exactly that.
1ls -l /etc/shadow2# -rw-r----- 1 root shadow 1234 ... /etc/shadow3# owner root can read/write; group 'shadow' can read; others: nothing4 5id # who am I? uid, gid, and every group I'm in6chmod 640 secret.txt # octal: owner rw, group r, others none7chmod o+x script.sh # symbolic: add execute for 'others'The special bits — where privilege escalation lives
Beyond rwx there are three special permission bits, and one of them is the most important concept in Linux privilege escalation.
The SUID bit (`s` in the owner's execute slot). When set on an executable, it makes the program run with the privileges of the file's owner, not the user who launched it. If a binary is owned by root and has SUID set, *anyone* who runs it runs code as root for the duration. That exists for legitimate reasons — passwd needs to edit /etc/shadow, so it's SUID-root — but a misconfigured or abusable SUID-root binary is a direct path from low-privileged user to root.
1# find every SUID file on the system, quietly2find / -perm -4000 -type f 2>/dev/null3 4# example output line:5# -rwsr-xr-x 1 root root 47.7K ... /usr/bin/find6# ^ that 's' is SUID: this runs as root no matter who calls its where an x should be, on a root-owned binary, is a flashing sign. If that binary can be made to run an arbitrary command (many can — find, vim, nmap, cp, and dozens more have documented tricks), you become root. Running find / -perm -4000 2>/dev/null is one of the first things you do on any freshly-owned box. We'll weaponise this properly in the privilege-escalation phase; for now, learn to *spot* it.| Special bit | Symbol | On a file it means | On a directory it means |
|---|---|---|---|
| SUID | s (owner x) | Run as the file's owner (e.g. root) | (no effect) |
| SGID | s (group x) | Run as the file's group | New files inherit the directory's group |
| Sticky | t (others x) | (rare) | Only a file's owner can delete it — why /tmp is safe-ish |
Users, groups, and processes: who is who
Access is decided by identity, so know how to read identity. Every user has a numeric UID (root is always 0 — that number, not the name, is what confers power) and belongs to one or more groups (each a GID). Membership in the right group (sudo, docker, adm) can be as good as being root.
Processes are just running programs, each owned by a user, each with a PID. Reading the process list tells you what services are running (attack surface), what's running as root (targets), and sometimes secrets passed on a command line (a password in ps output is a real and common find).
1whoami; id # my identity and groups2cat /etc/passwd | cut -d: -f1 # every username on the system3sudo -l # what am I allowed to run as root? (huge for privesc)4ps aux # every process: user, pid, and full command line5ps aux | grep root # what is running as root — your escalation targetsNotice how much of this is *reading*, not exploiting. That's the point of foundations: before you can escalate, you have to see clearly — who you are, what you can touch, what runs above you, and which files and bits are out of place. The exploits later are short. The seeing is the skill.
Read a box like an attacker
On your Kali box (or any Linux you control), do a full 'situational awareness' pass and write it up in linux1.md. Answer, with the command you used for each: (1) What is your UID and every group you're in? (2) List all usernames from /etc/passwd. (3) Find every SUID binary on the system. (4) Pick one file and set it to permissions 640 with chmod, then read back the ls -l line and explain each of the ten characters. (5) Show one process running as root and name what it is.
$ id$ find / -perm -4000 -type f 2>/dev/null$ chmod 640 <somefile> && ls -l <somefile>$ ps aux | grep root- › You can convert rwxr-xr-- to 754 and back without thinking
- › You explained why an SUID-root binary matters, in your own words
- › You know why /etc/shadow being unreadable (to you) is significant
- › You listed at least one SUID binary and one root process on your machine