Enumerating Linux

You’re In. Now Become root.

You landed on a Linux box. But as a nobody.

A standard user. You can’t:

  • read other people’s files
  • edit system config
  • touch /etc/shadow

Privilege escalation is the climb out of that hole.

From an unprivileged foothold up to root, UID 0, the account that owns the machine completely.


Every technique in this chapter is the same move you met on Windows, just wearing Linux clothes:

Find something that runs with more power than you, but that you are allowed to change.

That “something” takes different shapes:

  • a script root runs on a timer that you can overwrite
  • a program that runs as its owner instead of as you
  • a sudo rule that’s too generous

Same idea, different door.


But here’s the catch: you can’t exploit what you haven’t found.

So this note is pure reconnaissance. Two jobs:

  1. Understand how Linux hands out power
  2. Map the machine to spot where that power leaks

Everything Is a File

One idea makes Linux permissions click:

Almost everything is a file.

Documents, directories, devices, even network sockets, all represented in the filesystem. So one permission system governs nearly the whole machine.

And every file answers the same three questions, for three different audiences.


The three questions (what can you do?):

PermissionSymbolMeans
Readrlook at it
Writewchange it
Executexrun it

The three audiences (who’s asking?):

  • the owner of the file
  • the owner’s group
  • everyone else (others)

Run ls -l and you see all nine at once (three permissions times three audiences), plus a leading type character:

$ ls -l /etc/shadow-rw-r----- 1 root shadow 1751 May 2 09:31 /etc/shadow

That -rw-r----- decodes cleanly once you chunk it:

ChunkAudienceMeaning
-file typejust a regular file (ignore it for permissions)
rw-owner (root)read + write, no execute
r--group (shadow)read only
---othersnothing at all

So /etc/shadow is readable only by root and the shadow group. That matters, because that file holds every user’s password hash.


One subtlety worth pinning down: x means different things for a file and a directory.

rwx
Fileread its contentschange its contentsrun it as a program
Directorylist what’s insidecreate or delete files insidecd into it, reach known entries

Write on a directory lets you delete and replace the files in it, even files you don’t own. That distinction quietly powers several escalation tricks later.


Who Am I?

First move after landing a shell: figure out who you are and what you can touch.

$ id

This prints your UID (user ID), GID (group ID), and every group you belong to:

uid=1000(joe) gid=1000(joe) groups=1000(joe),24(cdrom),29(audio),...

Two numbers matter most:

  • root is always UID 0. That’s the summit you’re climbing to.
  • Regular users start at UID 1000 and count up. So 1000 is the first human account made on the box.

Your groups are not just noise. Membership in a group like sudo, docker, adm, or lxd can be an entire escalation path on its own. Always read the full list.


Next, enumerate every user by reading the world-readable account list:

$ cat /etc/passwd

Each line is one account, colon-separated:

joe:x:1000:1000:joe,,,:/home/joe:/bin/bash
FieldValueTells you
login namejoethe username
passwordxthe real hash lives in /etc/shadow, not here
UID / GID1000 / 1000a normal human account
home/home/joea real home dir = a real person to target
shell/bin/bashan interactive login (vs /usr/sbin/nologin)

Two reading habits pay off immediately:

  • Accounts with a real home and a real shell (/bin/bash) are humans worth targeting. Accounts ending in /usr/sbin/nologin are service accounts that can’t log in, so www-data and sshd just tell you a web server and SSH are installed.
  • That x in the password field means the actual hash sits in /etc/shadow, readable only by root. If you can ever read that file, you can crack hashes offline, which links straight back to the credential attacks chapter.

Situational Awareness

With the model understood, you sweep the machine. You’re not running commands at random, every one is a lens looking for the same thing: something privileged that you might be able to influence.


The core checklist:

WhatCommandWhy you care
OS / kerneluname -a, cat /etc/os-releaseKernel exploits are version-exact. A mismatched one crashes the box, so you need the precise version.
Processesps auxAnything running as root, especially custom or unusual software, is a target.
Networkip a, ss -anp, routelMultiple interfaces means this box could be a pivot. A service bound to 127.0.0.1 is reachable only locally, hidden attack surface.
Firewallread /etc/iptables/rules.v4Rule files are often left world-readable and reveal what’s blocked, and what’s quietly open locally.
Cron jobsls -la /etc/cron*, crontab -lScheduled scripts running as root with weak permissions are a classic way up (a later note).
Installed softwaredpkg -l (Debian), rpm -qa (Red Hat)Version numbers feed a public-exploit search.
Writable placesfind / -writable -type d 2>/dev/nullThe sharpest lens of all: it asks directly what can I change?

That last find is worth internalizing. 2>/dev/null throws away the permission-denied noise so you see only the directories you can actually write to. Privileged and writable is the whole game.


The mindset: you’re running a funnel. A fresh shell sees a machine full of facts, most of them noise. Each command narrows it. What survives, runs with more power than you and can be changed by you, is your escalation shortlist.


Automate It, Then Distrust It

Doing that entire sweep by hand is thorough but slow, and real engagements have deadlines. So there are scripts that run every check for you in one shot:

Run one, read the highlights, save hours.


But there’s a catch you must respect, the same one from the Windows side:

Automated tools find the common stuff. They miss the weird one-off misconfiguration, which is exactly the thing that’s often the real way in. A custom setting some admin made at 2am is precisely what a generic scanner has no rule for.

The discipline: automate to triage fast, then verify by hand. Let LinPEAS narrow a thousand files to fifty, but never let it be your only pass.


Where This Leads

You now understand how Linux hands out power, rwx across owner, group, and others, and you’ve mapped the machine: who’s privileged, what’s installed, what’s listening, and where you’re allowed to write.

Often that map alone hands you the win: a password someone left lying around. Hunting down those forgotten secrets, in history files, configs, and service trails, is Hunting Exposed Secrets.