π§Linux Privilege Escalation
Privilege Escalation refers to the process of exploiting misconfigurations, known vulnerabilities and unintended bugs in order to gain higher privileges on the target host. The final objective of this process is to gain the highest level of privileges on a target machine, achieving full compromise of that target.
External Resources
Linux Privilege Escalation:
GTFOBins - Unix binaries that can be exploited
Techniques Covered
Enumeration - System reconnaissance to identify potential attack vectors
Programs, Jobs and Services - Exploiting misconfigured services, cron jobs, and SUID binaries
Environment Variables Abuse - PATH variable, LD_PRELOAD and other issues
Persistence - Maintaining access after gaining elevated privileges
Table of Contents
Enumeration Scripts
Before trying specific techniques, it's advisable to run automated enumeration scripts to identify potential privilege escalation vectors:
LinPEAS
LinEnum
LSE (Linux Smart Enumeration)
pspy (Process Spy)
Kernel Exploits
Identifying and exploiting kernel vulnerabilities:
Check kernel version:
Search for known exploits:
Common kernel exploits:
Dirty COW (CVE-2016-5195)
overlayfs (CVE-2021-3493)
PTRACE_TRACEME (CVE-2019-13272)
Example: Exploiting Dirty COW
SUID/SGID Binaries
SUID (Set User ID) and SGID (Set Group ID) binaries run with the privileges of the file owner/group:
Find SUID/SGID binaries:
Investigate each binary using GTFOBins (https://gtfobins.github.io/) to identify potential privilege escalation vectors.
Example exploits:
Using find for privilege escalation:
Using nano for privilege escalation:
Using cp to overwrite sensitive files:
Sudo Rights
Check what commands you can run with sudo:
Common sudo privilege escalation vectors:
Running commands with sudo:
Environment variables preservation with sudo (
env_keep):
Wildcard exploitation:
Cron Jobs
Identifying and exploiting vulnerable cron jobs:
Find cron jobs:
Look for writable scripts executed by cron:
Monitor running processes to identify cron jobs:
Example exploitation:
Path Variable Manipulation
If the system uses a relative path to execute commands and the PATH variable can be manipulated:
Check the current PATH:
Create a malicious binary with the same name:
Modify the PATH to include your directory:
Wait for the vulnerable script to be executed, or execute it if you have permission.
NFS Shares
Exploiting misconfigured NFS shares:
Check for NFS shares:
Look for shares with
no_root_squashorno_all_squashoptions.Mount the share and exploit:
Weak File Permissions
Check for writable sensitive files:
System configuration files:
/etc/passwd writable (rare but worth checking):
Service configuration files:
Service Exploits
Exploit misconfigured services:
Check for running services:
Look for services running as root with writable configuration or binary files:
Check for writable service binaries:
Docker Group
If the user is part of the docker group:
Capabilities
Check for binaries with dangerous capabilities:
Example exploitation of capabilities:
LD_PRELOAD and LD_LIBRARY_PATH
If you can control LD_PRELOAD or LD_LIBRARY_PATH when running a SUID binary:
Create a malicious shared library:
Use LD_PRELOAD to load the malicious library:
Alternatively, use LD_LIBRARY_PATH to point to a directory with malicious libraries:
Resources
Last updated