🐧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:

Techniques Covered

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:

  1. Check kernel version:

  1. Search for known exploits:

  1. 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:

  1. Find SUID/SGID binaries:

  1. 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:

  1. Running commands with sudo:

  1. Environment variables preservation with sudo (env_keep):

  1. Wildcard exploitation:

Cron Jobs

Identifying and exploiting vulnerable cron jobs:

  1. Find cron jobs:

  1. Look for writable scripts executed by cron:

  1. 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:

  1. Check the current PATH:

  1. Create a malicious binary with the same name:

  1. Modify the PATH to include your directory:

  1. Wait for the vulnerable script to be executed, or execute it if you have permission.

NFS Shares

Exploiting misconfigured NFS shares:

  1. Check for NFS shares:

  1. Look for shares with no_root_squash or no_all_squash options.

  2. Mount the share and exploit:

Weak File Permissions

Check for writable sensitive files:

  1. System configuration files:

  1. /etc/passwd writable (rare but worth checking):

  1. Service configuration files:

Service Exploits

Exploit misconfigured services:

  1. Check for running services:

  1. Look for services running as root with writable configuration or binary files:

  1. 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:

  1. Create a malicious shared library:

  1. Use LD_PRELOAD to load the malicious library:

  1. Alternatively, use LD_LIBRARY_PATH to point to a directory with malicious libraries:

Resources

Last updated