Labs / Linux Exploitation / Escalate to root

Lab 1 of 4 · Escalate to root

Enumerate a foothold up to root

Read a foothold for the way up — by hand and with linpeas — find a password in a deploy file, and sudo to root.

Start this lab 6 steps

The idea

Kaveh has a signed engagement against Bowmont Haulage and a foothold on their dispatch box as the service account dispatch. Nothing jumps out: no NOPASSWD rule, no odd setuid binary. That is the normal case, and it is why escalation almost always opens with enumeration — reading the box, patiently, for the one thing left wrong.

Here the one thing is a secret in the open: a deploy-automation .env left world-readable, holding the very password dispatch logs in with — and dispatch may run sudo. You will sweep the box by hand, confirm it with linpeas, read the password out of the file, and hand it to sudo -S to become root.

Steps

  1. The foothold, and the wall it stops at

    You are on Kaveh's Kali box. The foothold is an SSH login on the dispatch box at 10.0.1.20 as the service account dispatch. Click Start to open a shell there, confirm who you are with id, then try the prize straight away — /etc/shadow — and watch it refused. That wall is what enumeration will get you past.

    kali:~# ssh box
  2. The early wins come up empty

    Start where every escalation starts — the two cheapest checks. sudo -n -l asks, without prompting, what you may run as root; find / -perm -4000 lists every setuid binary, the files that run as their owner. On a soft box one of these ends it. On this one neither does: sudo wants a password you do not have, and the only setuid files are the stock system ones. No free win — so you keep reading.

    kali:~# ssh box 'sudo -n -l'
    kali:~# ssh box 'find / -perm -4000 -type f 2>/dev/null'
  3. Read the box for secrets

    Applications and their deploy tooling leave secrets on disk — in config files, .env files, scripts, history. An ordinary account can often read them because nobody tightened the permissions. Sweep the obvious home for an app's files — /opt, where vendored and deploy tooling lands — for anything that looks like a credential.

    kali:~# ssh box 'grep -rin pass /opt 2>/dev/null'
  4. Sweep it faster with linpeas

    By hand you found one secret. linpeas runs hundreds of these checks in one pass — readable config and .env files, credentials, history, /opt contents, sudo, setuid, writable paths — so nothing a hand sweep would miss gets missed. It is on your Kali box at /usr/share/peass/linpeas/linpeas.sh; the target has no internet, so copy it over the foothold with scp, then run only the interesting-files checks so it stays fast. Watch it run its password and /opt sweeps — the ones that cover the file you already found.

    kali:~# scp /usr/share/peass/linpeas/linpeas.sh box:/tmp/linpeas.sh
    kali:~# ssh box 'bash /tmp/linpeas.sh -N -q -o interesting_files'
  5. Own the box

    sudo wanted one thing: dispatch's password. You have it. sudo -S reads that password from standard input instead of a terminal, so you can pipe it straight in over the foothold — no interactive prompt. Run id as root to prove it, then read the /etc/shadow that was closed to you in step one.

    kali:~# ssh box 'echo "D1spatch-0ps!" | sudo -S -k id'
    kali:~# ssh box 'echo "D1spatch-0ps!" | sudo -S -k cat /etc/shadow'
  6. What Bowmont's admin should change

    Kaveh's finding is not "sudo is dangerous" or "linpeas is dangerous". It is that a secret on disk that an ordinary account can read is a root password, the moment that account can sudo. The fixes, in order:

    • Keep secrets out of readable files. The deploy password belongs in a secrets manager or a file scoped to the one account that needs it (0600, owned by that account) — never 0644 under /opt. Rotate it, since it has now leaked.
    • Do not reuse a login password as a sudo/deploy password. One leak unlocked both. Separate credentials, so reading a deploy file does not also hand over the account's sudo.
    • Scope the sudo rule. dispatch ALL=(ALL:ALL) ALL lets the account run anything as root. The nightly deploy needs a short list of commands, not all of them — grant those, so a leaked password buys far less.
    • Watch for it. sudo logs every command to the auth log, so Bowmont's SOC would see dispatch running cat /etc/shadow as root — an ops account reading the hash file is the tell.

    One honest line: running any of this against a system whose owner has not authorised you in writing is unauthorised access, an offence under laws like the UK Computer Misuse Act and the United States' CFAA. Kaveh has a signed engagement; that permission is the only thing separating this from a crime.

    kali:~# ssh box 'ls -l /opt/bowmont/deploy/.env'

Run these steps on real machines

Keep reading

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab