hacking track
week 11 · day 3

Linux Deep Dive I

Filesystem, permissions, processes, and the way in

Easy 120 min 180 xp
After this you can
  • 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:

PathWhat lives thereWhy you care
/etcSystem configuration (text files)/etc/passwd (users), /etc/shadow (password hashes), service configs, secrets
/home/<user>A user's personal filesSSH keys, .bash_history, notes, credentials people leave lying around
/rootThe root user's homeThe prize; usually only readable once you're root
/varVariable data: logs, web roots, mail/var/www (web app source & configs), /var/log (traces of you)
/tmp, /dev/shmWorld-writable scratch spaceWhere you drop your tools and payloads — everyone can write here
/usr/bin, /binInstalled programsThe binaries you'll abuse; SUID ones especially
/procA live view of the kernel & processes/proc/<pid> reveals a process's command line, environment, open files
Note
Two files in /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:

Anatomy of -rwxr-xr--
   -   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, what ls -l shows.
  • Octal: add the bits per chunk. rwx = 4+2+1 = 7, r-x = 4+0+1 = 5, r-- = 4+0+0 = 4. So rwxr-xr-- = 754, which is what chmod 754 file sets.

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.

reading and changing permissionssh
1ls -l /etc/shadow
2# -rw-r----- 1 root shadow 1234 ... /etc/shadow
3# owner root can read/write; group 'shadow' can read; others: nothing
4
5id # who am I? uid, gid, and every group I'm in
6chmod 640 secret.txt # octal: owner rw, group r, others none
7chmod 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.

finding SUID binaries — a first-move on any boxsh
1# find every SUID file on the system, quietly
2find / -perm -4000 -type f 2>/dev/null
3
4# example output line:
5# -rwsr-xr-x 1 root root 47.7K ... /usr/bin/find
6# ^ that 's' is SUID: this runs as root no matter who calls it
Key idea
The s 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 bitSymbolOn a file it meansOn a directory it means
SUIDs (owner x)Run as the file's owner (e.g. root)(no effect)
SGIDs (group x)Run as the file's groupNew files inherit the directory's group
Stickyt (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).

situational awareness on a boxsh
1whoami; id # my identity and groups
2cat /etc/passwd | cut -d: -f1 # every username on the system
3sudo -l # what am I allowed to run as root? (huge for privesc)
4ps aux # every process: user, pid, and full command line
5ps aux | grep root # what is running as root — your escalation targets

Notice 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.

finished reading?
Your task, you write the code

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.

deliverable: linux1.md
build & run
$ id
$ find / -perm -4000 -type f 2>/dev/null
$ chmod 640 <somefile> && ls -l <somefile>
$ ps aux | grep root
self-review before running
  • 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
stretchLook up two SUID binaries from your find output on GTFOBins (gtfobins.github.io) and read how each could be abused to escalate. Don't run anything yet — just understand the mechanism. You're building the pattern-recognition you'll use in Phase 5.

Self-check

01The permissions rwxr-x--- in octal are:
02An SUID bit set on a root-owned executable means:
03On a directory, the execute (x) bit grants the right to:
04Which numeric UID always denotes the all-powerful account?
0/4 correct · 0/4 checked